Skip to content

Commit

Permalink
refactor: don't pass userID though dto
Browse files Browse the repository at this point in the history
  • Loading branch information
olexsmir committed Sep 26, 2024
1 parent a41cb54 commit 7e85b32
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 0 additions & 2 deletions internal/dtos/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type UserDTO struct {
}

type ResetUserPasswordDTO struct {
// NOTE: probably userID shouldn't be here
UserID uuid.UUID
CurrentPassword string
NewPassword string
}
Expand Down
10 changes: 7 additions & 3 deletions internal/service/usersrv/usersrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type UserServicer interface {
RefreshTokens(ctx context.Context, refreshToken string) (dtos.TokensDTO, error)
Logout(ctx context.Context, userID uuid.UUID) error

ChangePassword(ctx context.Context, inp dtos.ResetUserPasswordDTO) error
ChangePassword(ctx context.Context, userID uuid.UUID, inp dtos.ResetUserPasswordDTO) error

Verify(ctx context.Context, verificationKey string) error
ResendVerificationEmail(ctx context.Context, credentials dtos.SignInDTO) error
Expand Down Expand Up @@ -165,7 +165,11 @@ func (u *UserSrv) RefreshTokens(ctx context.Context, rtoken string) (dtos.Tokens
}, nil
}

func (u *UserSrv) ChangePassword(ctx context.Context, inp dtos.ResetUserPasswordDTO) error {
func (u *UserSrv) ChangePassword(
ctx context.Context,
userID uuid.UUID,
inp dtos.ResetUserPasswordDTO,
) error {
oldPass, err := u.hasher.Hash(inp.CurrentPassword)
if err != nil {
return err
Expand All @@ -176,7 +180,7 @@ func (u *UserSrv) ChangePassword(ctx context.Context, inp dtos.ResetUserPassword
return err
}

if err := u.userstore.ChangePassword(ctx, inp.UserID, oldPass, newPass); err != nil {
if err := u.userstore.ChangePassword(ctx, userID, oldPass, newPass); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion internal/transport/http/apiv1/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func (a *APIV1) changePasswordHandler(c *gin.Context) {

if err := a.usersrv.ChangePassword(
c.Request.Context(),
a.getUserID(c),
dtos.ResetUserPasswordDTO{
UserID: a.getUserID(c),
CurrentPassword: req.CurrentPassword,
NewPassword: req.NewPassword,
}); err != nil {
Expand Down

0 comments on commit 7e85b32

Please sign in to comment.