feat: login service and implement database storage
This commit is contained in:
@@ -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,
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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,
|
||||
),
|
||||
)
|
||||
Reference in New Issue
Block a user