chore: remove db dependency from handler

This commit is contained in:
2024-09-27 11:17:09 +02:00
committed by Tim Wundenberg
parent e10e7c9357
commit 7e8730206c
2 changed files with 18 additions and 5 deletions

View File

@@ -1,7 +1,6 @@
package handler package handler
import ( import (
"me-fit/db"
"me-fit/service" "me-fit/service"
"me-fit/utils" "me-fit/utils"
"time" "time"
@@ -51,7 +50,7 @@ var (
func (handler HandlerAuthImpl) handleSignIn() http.HandlerFunc { func (handler HandlerAuthImpl) handleSignIn() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
user, err := utils.WaitMinimumTime(securityWaitDuration, func() (*db.User, error) { user, err := utils.WaitMinimumTime(securityWaitDuration, func() (*service.User, error) {
var email = r.FormValue("email") var email = r.FormValue("email")
var password = r.FormValue("password") var password = r.FormValue("password")

View File

@@ -28,8 +28,22 @@ var (
InvaidEmailOrPassword = errors.New("Invalid email or password") InvaidEmailOrPassword = errors.New("Invalid email or password")
) )
type User struct {
Id uuid.UUID
Email string
EmailVerified bool
}
func NewUser(user *db.User) *User {
return &User{
Id: user.Id,
Email: user.Email,
EmailVerified: user.EmailVerified,
}
}
type ServiceAuth interface { type ServiceAuth interface {
SignIn(email string, password string) (*db.User, error) SignIn(email string, password string) (*User, error)
} }
type ServiceAuthImpl struct { type ServiceAuthImpl struct {
@@ -42,7 +56,7 @@ func NewServiceAuthImpl(d *sql.DB) *ServiceAuthImpl {
} }
} }
func (service ServiceAuthImpl) SignIn(email string, password string) (*db.User, error) { func (service ServiceAuthImpl) SignIn(email string, password string) (*User, error) {
user, err := service.dbAuth.GetUser(email) user, err := service.dbAuth.GetUser(email)
if err != nil { if err != nil {
@@ -59,7 +73,7 @@ func (service ServiceAuthImpl) SignIn(email string, password string) (*db.User,
return nil, InvaidEmailOrPassword return nil, InvaidEmailOrPassword
} }
return user, nil return NewUser(user), nil
} }
func HandleSignInPage(db *sql.DB) http.HandlerFunc { func HandleSignInPage(db *sql.DB) http.HandlerFunc {