feat: users & authentication implementation

This commit is contained in:
Florian Sylvain
2023-08-07 12:31:29 +02:00
parent e258dccc1c
commit f33f53ca76
15 changed files with 550 additions and 18 deletions
+27
View File
@@ -0,0 +1,27 @@
package useCases
import (
. "GohCMS2/adapters/secondary/gateways"
. "GohCMS2/domain/user"
"gorm.io/gorm"
)
type CreateUserUseCase struct {
userRepository UserRepository
}
type CreateUserCommand struct {
Username string
Password string
Email string
}
func NewCreateUserUseCase(db *gorm.DB) *CreateUserUseCase {
return &CreateUserUseCase{
userRepository: *NewUserRepository(db),
}
}
func (g *CreateUserUseCase) CreateUser(user CreateUserCommand) (User, error) {
return g.userRepository.Create(FromApi(user.Username, user.Password, user.Email))
}
+21
View File
@@ -0,0 +1,21 @@
package useCases
import (
. "GohCMS2/adapters/secondary/gateways"
. "GohCMS2/domain/user"
"gorm.io/gorm"
)
type GetUserByUsernameUseCase struct {
userRepository UserRepository
}
func NewGetUserByUsernameUseCase(db *gorm.DB) *GetUserByUsernameUseCase {
return &GetUserByUsernameUseCase{
userRepository: *NewUserRepository(db),
}
}
func (g *GetUserByUsernameUseCase) GetUserByUsername(username string) (User, error) {
return g.userRepository.GetByUsername(username)
}
+21
View File
@@ -0,0 +1,21 @@
package useCases
import (
. "GohCMS2/adapters/secondary/gateways"
. "GohCMS2/domain/user"
"gorm.io/gorm"
)
type GetUserUseCase struct {
userRepository UserRepository
}
func NewGetUserUseCase(db *gorm.DB) *GetUserUseCase {
return &GetUserUseCase{
userRepository: *NewUserRepository(db),
}
}
func (g *GetUserUseCase) GetUser(id uint32) (User, error) {
return g.userRepository.Get(id)
}
+21
View File
@@ -0,0 +1,21 @@
package useCases
import (
. "GohCMS2/adapters/secondary/gateways"
. "GohCMS2/domain/user"
"gorm.io/gorm"
)
type ListUsersUseCase struct {
userRepository UserRepository
}
func NewListUsersUseCase(db *gorm.DB) *ListUsersUseCase {
return &ListUsersUseCase{
userRepository: *NewUserRepository(db),
}
}
func (g *ListUsersUseCase) ListUsers() []User {
return g.userRepository.GetAll()
}