Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rm user-specific methods from pkg/infra/adapter/repo #8

Closed
Tracked by #3
Sddilora opened this issue May 6, 2024 · 0 comments
Closed
Tracked by #3

Rm user-specific methods from pkg/infra/adapter/repo #8

Sddilora opened this issue May 6, 2024 · 0 comments
Assignees
Labels
Be Be Team compliance Ensuring adherence to standards and regulations high-priority Urgent issues needing immediate attention sub-issue Sub-task within a larger task

Comments

@Sddilora
Copy link
Member

Sddilora commented May 6, 2024

User-specific methods:

// SaveUser insert a new user or update the existing one in the database.
func (a DbAdapter) SaveUser(ctx context.Context, user me.User) (me.User, error) {
userDbMapper := map_repo.NewUserFromEntity(user)
qry := a.DbClient
if user.Id.String() != "" && user.Id != (uuid.UUID{}) {
qry = qry.Omit("created_at")
}
userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
if userDbMapper.ID != (uuid.UUID{}) {
userDbMapper.UpdatedBy, _ = uuid.Parse(userId)
} else {
userDbMapper.CreatedBy, _ = uuid.Parse(userId)
}
result := qry.Save(&userDbMapper)
if result.Error != nil {
userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "SaveUser", userId, result.Error.Error()))
return me.User{}, result.Error
}
return *userDbMapper.ToEntity(), nil
}
// DeleteUser soft-deletes the given user in the database.
func (a DbAdapter) DeleteUser(ctx context.Context, user me.User) (me.User, error) {
userDbMapper := map_repo.NewUserFromEntity(user)
userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
userDbMapper.DeletedBy, _ = uuid.Parse(userId)
result := a.DbClient.Delete(&userDbMapper)
if result.Error != nil {
userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "DeleteUser", userId, result.Error.Error()))
return me.User{}, result.Error
}
return *userDbMapper.ToEntity(), nil
}

// ChangePassword changes the given user password in the database.
func (a DbAdapter) ChangePassword(ctx context.Context, userPassword me.UserPassword) (me.UserPassword, error) {
userPasswordDbMapper := map_repo.NewUserPasswordFromEntity(userPassword)
qry := a.DbClient
if userPassword.Id.String() != "" && userPassword.Id != (uuid.UUID{}) {
qry = qry.Omit("created_at")
}
userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
if userPasswordDbMapper.ID != (uuid.UUID{}) {
userPasswordDbMapper.UpdatedBy, _ = uuid.Parse(userId)
} else {
userPasswordDbMapper.CreatedBy, _ = uuid.Parse(userId)
}
result := qry.Save(&userPasswordDbMapper)
if result.Error != nil {
userId, _ := ctx.Value(smodel.QueryKeyUid).(string)
go a.Log(context.Background(), me.NewLogData().GenerateLogData(pb_logging.LogType_LogTypeERROR, "ChangePassword", userId, result.Error.Error()))
return me.UserPassword{}, result.Error
}
return *userPasswordDbMapper.ToEntity(), nil
}

Remove user-specific methods from the adapter.

"GetUsersByFilter" will not be removed because it is used by the "GetUserPasswordByUserId," "Login," and "Refresh" methods.

"GetUserPasswordByUserId" will not be removed because it is used by the "Login" method.

The changes will be merged into the "/first/hsm/1/create-first" branch first. Therefore, set the base branch of the pull request as /first/hsm/1/create-first.

@husamettinarabaci husamettinarabaci added the Be Be Team label May 6, 2024
@Sddilora Sddilora changed the title Rm user-specific methods from adapter Rm user-specific methods from infrastructure May 6, 2024
@Sddilora Sddilora changed the title Rm user-specific methods from infrastructure Rm user-specific methods from pkg/infra/adapter/repo May 6, 2024
@Sddilora Sddilora added compliance Ensuring adherence to standards and regulations sub-issue Sub-task within a larger task high-priority Urgent issues needing immediate attention labels May 6, 2024
@Feyzanrs Feyzanrs self-assigned this May 7, 2024
@Feyzanrs Feyzanrs closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Be Be Team compliance Ensuring adherence to standards and regulations high-priority Urgent issues needing immediate attention sub-issue Sub-task within a larger task
Projects
None yet
Development

No branches or pull requests

3 participants