features/working-on-scopes #13

Merged
jtom38 merged 28 commits from features/working-on-scopes into main 2024-04-04 15:31:54 -07:00
3 changed files with 6 additions and 5 deletions
Showing only changes of commit c071212df5 - Show all commits

View File

@ -18,7 +18,7 @@ const (
type IUserTable interface { type IUserTable interface {
GetByName(name string) (domain.UserEntity, error) GetByName(name string) (domain.UserEntity, error)
Create(name, password string) (int64, error) Create(name, password, scope string) (int64, error)
Update(id int, entity domain.UserEntity) error Update(id int, entity domain.UserEntity) error
UpdatePassword(name, password string) error UpdatePassword(name, password string) error
CheckUserHash(name, password string) error CheckUserHash(name, password string) error
@ -56,7 +56,7 @@ func (ur UserRepository) GetByName(name string) (domain.UserEntity, error) {
return data[0], nil return data[0], nil
} }
func (ur UserRepository) Create(name, password string) (int64, error) { func (ur UserRepository) Create(name, password, scope string) (int64, error) {
passwordBytes := []byte(password) passwordBytes := []byte(password)
hash, err := bcrypt.GenerateFromPassword(passwordBytes, bcrypt.DefaultCost) hash, err := bcrypt.GenerateFromPassword(passwordBytes, bcrypt.DefaultCost)
if err != nil { if err != nil {

View File

@ -2,6 +2,7 @@ package repositories_test
import ( import (
"database/sql" "database/sql"
"go-cook/api/domain"
"go-cook/api/repositories" "go-cook/api/repositories"
"log" "log"
"testing" "testing"
@ -20,7 +21,7 @@ func TestCanCreateNewUser(t *testing.T) {
defer db.Close() defer db.Close()
repo := repositories.NewUserRepository(db) repo := repositories.NewUserRepository(db)
updated, err := repo.Create("testing", "NotSecure") updated, err := repo.Create("testing", "NotSecure", domain.ScopeRecipeRead)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
t.FailNow() t.FailNow()

View File

@ -53,13 +53,13 @@ func (us UserService) GetUser(username string) (domain.UserEntity, error) {
return us.repo.GetByName(username) return us.repo.GetByName(username)
} }
func (us UserService) CreateNewUser(name, password string) (domain.UserEntity, error) { func (us UserService) CreateNewUser(name, password, scope string) (domain.UserEntity, error) {
err := us.CheckPasswordForRequirements(password) err := us.CheckPasswordForRequirements(password)
if err != nil { if err != nil {
return domain.UserEntity{}, err return domain.UserEntity{}, err
} }
us.repo.Create(name, password) us.repo.Create(name, password, domain.ScopeRecipeRead)
return domain.UserEntity{}, nil return domain.UserEntity{}, nil
} }