feat: login service and implement database storage

This commit is contained in:
ericprd
2025-02-23 22:34:26 +08:00
parent a95a5ca521
commit 5fcb5c2cd5
24 changed files with 576 additions and 8 deletions
+19
View File
@@ -0,0 +1,19 @@
package serviceauth
import staffrepository "github.com/ardeman/project-legalgo-go/internal/accessor/staff"
type LoginStaffSvc struct {
staffAcs staffrepository.StaffInterface
}
type LoginStaffIntf interface {
LoginAsStaff(string) (string, error)
}
func New(
staffAcs staffrepository.StaffInterface,
) LoginStaffIntf {
return &LoginStaffSvc{
staffAcs: staffAcs,
}
}
+21
View File
@@ -0,0 +1,21 @@
package serviceauth
import (
"errors"
"github.com/ardeman/project-legalgo-go/internal/utilities/utils"
)
func (sv *LoginStaffSvc) LoginAsStaff(email string) (string, error) {
staff, err := sv.staffAcs.GetStaff(email)
if err != nil {
return "", errors.New(err.Error())
}
token, err := utils.GenerateToken2(staff.Email)
if err != nil {
return "", errors.New(err.Error())
}
return token, nil
}
+12
View File
@@ -0,0 +1,12 @@
package services
import (
serviceauth "github.com/ardeman/project-legalgo-go/internal/services/auth"
"go.uber.org/fx"
)
var Module = fx.Module("services",
fx.Provide(
serviceauth.New,
),
)