diff --git a/entity/token.go b/entity/token.go index 8271b50..88d84ad 100644 --- a/entity/token.go +++ b/entity/token.go @@ -7,9 +7,11 @@ import ( const ( TokenStatusAllowed = "ALLOWED" TokenStatusRevoked = "REVOKED" + TokenStatusExpired = "EXPIRED" ) type Token struct { + Id int Token string UserId int64 Status string diff --git a/entity/user.go b/entity/user.go index 76e57f6..fed1508 100644 --- a/entity/user.go +++ b/entity/user.go @@ -10,6 +10,7 @@ type User struct { LastName string Email string Password string + Blocked bool UpdatedAt time.Time CreatedAt time.Time } @@ -22,14 +23,6 @@ type SudirUser struct { Email string } -type CreateUser struct { - RoleId int - FirstName string - LastName string - Email string - Password string -} - type UpdateUser struct { RoleId int FirstName string diff --git a/migrations/20230322202054_update_tables.sql b/migrations/20230322202054_update_tables.sql new file mode 100644 index 0000000..4e72927 --- /dev/null +++ b/migrations/20230322202054_update_tables.sql @@ -0,0 +1,31 @@ +-- +goose Up +alter table roles + add unique (name); + +alter table tokens + add column id serial8 not null; + +alter table tokens + add constraint fk_user_id__user_id + foreign key (user_id) references users (id) + on update cascade on delete cascade; + +create index ix_tokens__user_id on tokens (user_id); + +create table audit +( + id serial8 primary key, + user_id int8 not null, + message text not null, + created_at timestamp not null +); + +create index ix_audit__created_at on audit (created_at DESC); + +alter table users + add column blocked boolean not null default false; + +alter table users + add unique (sudir_user_id); + +-- +goose Down diff --git a/repository/user.go b/repository/user.go index ffcb894..be12da1 100644 --- a/repository/user.go +++ b/repository/user.go @@ -22,8 +22,7 @@ func NewUser(db db.DB) User { func (u User) GetUserByEmail(ctx context.Context, email string) (*entity.User, error) { q, args, err := query.New(). - Select("id", "role_id", "first_name", "last_name", "password", - "email", "sudir_user_id", "created_at", "updated_at"). + Select("*"). From("users"). Where(squirrel.Eq{"email": email}). ToSql() @@ -46,8 +45,7 @@ func (u User) GetUserByEmail(ctx context.Context, email string) (*entity.User, e func (u User) GetUserById(ctx context.Context, identity int64) (*entity.User, error) { q, args, err := query.New(). - Select("id", "role_id", "first_name", "last_name", "password", - "email", "sudir_user_id", "created_at", "updated_at"). + Select("*"). From("users"). Where(squirrel.Eq{"id": identity}). ToSql() @@ -95,8 +93,7 @@ func (u User) GetUserBySudirUserId(ctx context.Context, id string) (*entity.User func (u User) GetUsers(ctx context.Context, ids []int64, offset, limit int, email string) ([]entity.User, error) { // take every except password q := query.New(). - Select("id", "role_id", "first_name", "last_name", - "email", "sudir_user_id", "created_at", "updated_at"). + Select("*"). From("users") if len(ids) > 0 {