features/move-domain-for-portal #8

Merged
jtom38 merged 6 commits from features/move-domain-for-portal into main 2024-05-09 19:10:04 -07:00
2 changed files with 11 additions and 10 deletions
Showing only changes of commit d7f2eca4c3 - Show all commits

View File

@ -5,7 +5,7 @@ import (
"database/sql" "database/sql"
"errors" "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" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
"github.com/google/uuid" "github.com/google/uuid"
) )
@ -16,7 +16,7 @@ const (
type RefreshToken interface { type RefreshToken interface {
Create(ctx context.Context, username string) (string, error) 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) Delete(ctx context.Context, id int64) (int64, error)
IsRequestValid(ctx context.Context, username, refreshToken string) 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 // 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) return rt.table.GetByUsername(ctx, name)
} }

View File

@ -6,7 +6,8 @@ import (
"errors" "errors"
"strings" "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" "git.jamestombleson.com/jtom38/newsbot-api/internal/repository"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
@ -21,10 +22,10 @@ const (
type UserServices interface { type UserServices interface {
DoesUserExist(ctx context.Context, username string) error DoesUserExist(ctx context.Context, username string) error
DoesPasswordMatchHash(ctx context.Context, username, password 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 AddScopes(ctx context.Context, username string, scopes []string) error
RemoveScopes(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 CheckPasswordForRequirements(password string) error
} }
@ -63,7 +64,7 @@ func (us UserService) DoesPasswordMatchHash(ctx context.Context, username, passw
return nil 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) return us.repo.GetByName(ctx, username)
} }
@ -124,14 +125,14 @@ func (us UserService) doesScopeExist(scopes []string, target string) bool {
return false 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) err := us.CheckPasswordForRequirements(password)
if err != nil { if err != nil {
return domain.UserEntity{}, err return entity.UserEntity{}, err
} }
us.repo.Create(ctx, name, password, domain.ScopeArticleRead) us.repo.Create(ctx, name, password, domain.ScopeArticleRead)
return domain.UserEntity{}, nil return entity.UserEntity{}, nil
} }
func (us UserService) CheckPasswordForRequirements(password string) error { func (us UserService) CheckPasswordForRequirements(password string) error {