From d7f2eca4c388b6532a534f03ac68670f4d6786d8 Mon Sep 17 00:00:00 2001 From: James Tombleson Date: Thu, 9 May 2024 19:09:11 -0700 Subject: [PATCH] repo services not use entity --- internal/repositoryServices/refreshTokens.go | 6 +++--- internal/repositoryServices/userService.go | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/repositoryServices/refreshTokens.go b/internal/repositoryServices/refreshTokens.go index ca5b800..f56ef48 100644 --- a/internal/repositoryServices/refreshTokens.go +++ b/internal/repositoryServices/refreshTokens.go @@ -5,7 +5,7 @@ import ( "database/sql" "errors" - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" + "git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "github.com/google/uuid" ) @@ -16,7 +16,7 @@ const ( type RefreshToken interface { Create(ctx context.Context, username string) (string, error) - GetByName(ctx context.Context, name string) (domain.RefreshTokenEntity, error) + GetByName(ctx context.Context, name string) (entity.RefreshTokenEntity, error) Delete(ctx context.Context, id int64) (int64, error) IsRequestValid(ctx context.Context, username, refreshToken string) error } @@ -64,7 +64,7 @@ func (rt RefreshTokenService) Create(ctx context.Context, username string) (stri } // Find the saved refresh token for a user and return it if it exists -func (rt RefreshTokenService) GetByName(ctx context.Context, name string) (domain.RefreshTokenEntity, error) { +func (rt RefreshTokenService) GetByName(ctx context.Context, name string) (entity.RefreshTokenEntity, error) { return rt.table.GetByUsername(ctx, name) } diff --git a/internal/repositoryServices/userService.go b/internal/repositoryServices/userService.go index 7a4bed2..2bd52d8 100644 --- a/internal/repositoryServices/userService.go +++ b/internal/repositoryServices/userService.go @@ -6,7 +6,8 @@ import ( "errors" "strings" - "git.jamestombleson.com/jtom38/newsbot-api/internal/domain" + "git.jamestombleson.com/jtom38/newsbot-api/domain" + "git.jamestombleson.com/jtom38/newsbot-api/internal/entity" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository" "golang.org/x/crypto/bcrypt" @@ -21,10 +22,10 @@ const ( type UserServices interface { DoesUserExist(ctx context.Context, username string) error DoesPasswordMatchHash(ctx context.Context, username, password string) error - GetUser(ctx context.Context, username string) (domain.UserEntity, error) + GetUser(ctx context.Context, username string) (entity.UserEntity, error) AddScopes(ctx context.Context, username string, scopes []string) error RemoveScopes(ctx context.Context, username string, scopes []string) error - Create(ctx context.Context, name, password, scope string) (domain.UserEntity, error) + Create(ctx context.Context, name, password, scope string) (entity.UserEntity, error) CheckPasswordForRequirements(password string) error } @@ -63,7 +64,7 @@ func (us UserService) DoesPasswordMatchHash(ctx context.Context, username, passw return nil } -func (us UserService) GetUser(ctx context.Context, username string) (domain.UserEntity, error) { +func (us UserService) GetUser(ctx context.Context, username string) (entity.UserEntity, error) { return us.repo.GetByName(ctx, username) } @@ -124,14 +125,14 @@ func (us UserService) doesScopeExist(scopes []string, target string) bool { return false } -func (us UserService) Create(ctx context.Context, name, password, scope string) (domain.UserEntity, error) { +func (us UserService) Create(ctx context.Context, name, password, scope string) (entity.UserEntity, error) { err := us.CheckPasswordForRequirements(password) if err != nil { - return domain.UserEntity{}, err + return entity.UserEntity{}, err } us.repo.Create(ctx, name, password, domain.ScopeArticleRead) - return domain.UserEntity{}, nil + return entity.UserEntity{}, nil } func (us UserService) CheckPasswordForRequirements(password string) error {