Skip to content

Commit

Permalink
Revision
Browse files Browse the repository at this point in the history
  • Loading branch information
hemite123 committed Jun 13, 2024
1 parent 8ba2f71 commit ac54b6d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions cmd/user_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "testing"

func TestRegister(t *testing.T) {

}
2 changes: 1 addition & 1 deletion internal/app/ports/user_ports.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type IUserRepository interface {
GetUserByUsernameAndPassword(ctx context.Context, username string, hashPassword string) (*entity.UserORM, error)
RegisterUser(ctx context.Context, userData entity.UserORM) (int64, error)
GetUserByEmail(ctx context.Context, email string) error
GetUserByEmail(ctx context.Context, email string) (entity.UserORM, error)
}

type IUserService interface {
Expand Down
6 changes: 3 additions & 3 deletions internal/app/repository/user_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (r *UserRepository) RegisterUser(ctx context.Context, userData entity.UserO
return lastId, nil
}

func (r *UserRepository) GetUserByEmail(ctx context.Context, email string) error {
func (r *UserRepository) GetUserByEmail(ctx context.Context, email string) (entity.UserORM, error) {
span, ctx := opentracing.StartSpanFromContext(ctx, "repo.UserRepository.GetUserByEmail")
defer span.Finish()

Expand All @@ -65,8 +65,8 @@ func (r *UserRepository) GetUserByEmail(ctx context.Context, email string) error
err := r.MasterDB.GetContext(ctx, &user, queryGetEmailSame, email)
if err != nil {
if err == sql.ErrNoRows {
return nil
return user, nil
}
}
return errors.New("Email Already Exists")
return user, errors.New("Email Already Exists")
}
7 changes: 5 additions & 2 deletions internal/app/service/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ func (s *UserService) Register(ctx context.Context, userData entity.User) (int64
span, ctx := opentracing.StartSpanFromContext(ctx, "service.UserService.Register")
defer span.Finish()

err := s.userRepository.GetUserByEmail(ctx, userData.Email)
returnUsers, err := s.userRepository.GetUserByEmail(ctx, userData.Email)
if err != nil {
return 0, errors.New("Email Already Exists")
return 0, err
}
if returnUsers.Username != "" {
return 0, errors.New("Email Already Exist")
}
passwordHashed, err := utils.HashPassword(userData.Password)
if err != nil {
Expand Down

0 comments on commit ac54b6d

Please sign in to comment.