feat: login service and implement database storage
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
staffrepository "github.com/ardeman/project-legalgo-go/internal/accessor/staff"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
var Module = fx.Module("repository", fx.Provide(
|
||||
staffrepository.New,
|
||||
))
|
||||
@@ -0,0 +1,25 @@
|
||||
package staffrepository
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
staffmodel "github.com/ardeman/project-legalgo-go/database/staff"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func (sr *StaffRepository) GetStaff(email string) (*staffmodel.Staff, error) {
|
||||
var staff staffmodel.Staff
|
||||
|
||||
if email == "" {
|
||||
return nil, errors.New("email is empty")
|
||||
}
|
||||
|
||||
if err := sr.DB.Where("email = ?", email).First(&staff).Error; err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errors.New("staff not found")
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &staff, nil
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package staffrepository
|
||||
|
||||
import (
|
||||
"github.com/ardeman/project-legalgo-go/database"
|
||||
staffmodel "github.com/ardeman/project-legalgo-go/database/staff"
|
||||
)
|
||||
|
||||
type StaffRepository struct {
|
||||
DB *database.DB
|
||||
}
|
||||
|
||||
type StaffInterface interface {
|
||||
GetStaff(string) (*staffmodel.Staff, error)
|
||||
}
|
||||
|
||||
func New(db *database.DB) StaffInterface {
|
||||
return &StaffRepository{db}
|
||||
}
|
||||
Reference in New Issue
Block a user