quite a lot of things
This commit is contained in:
69
internal/auth/store.go
Normal file
69
internal/auth/store.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"billit/internal/database"
|
||||
)
|
||||
|
||||
// DBUserStore adapts database.Service to auth.UserStore interface
|
||||
type DBUserStore struct {
|
||||
db database.Service
|
||||
}
|
||||
|
||||
// NewDBUserStore creates a new user store backed by the database
|
||||
func NewDBUserStore(db database.Service) *DBUserStore {
|
||||
return &DBUserStore{db: db}
|
||||
}
|
||||
|
||||
// CreateUser creates a new user
|
||||
func (s *DBUserStore) CreateUser(email, passwordHash string) (*User, error) {
|
||||
dbUser, err := s.db.CreateUser(email, passwordHash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &User{
|
||||
ID: dbUser.ID,
|
||||
Email: dbUser.Email,
|
||||
Password: dbUser.Password,
|
||||
CompanyDetails: dbUser.CompanyDetails,
|
||||
BankDetails: dbUser.BankDetails,
|
||||
CreatedAt: dbUser.CreatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetUserByEmail retrieves a user by email
|
||||
func (s *DBUserStore) GetUserByEmail(email string) (*User, error) {
|
||||
dbUser, err := s.db.GetUserByEmail(email)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dbUser == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return &User{
|
||||
ID: dbUser.ID,
|
||||
Email: dbUser.Email,
|
||||
Password: dbUser.Password,
|
||||
CompanyDetails: dbUser.CompanyDetails,
|
||||
BankDetails: dbUser.BankDetails,
|
||||
CreatedAt: dbUser.CreatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// GetUserByID retrieves a user by ID
|
||||
func (s *DBUserStore) GetUserByID(id string) (*User, error) {
|
||||
dbUser, err := s.db.GetUserByID(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dbUser == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return &User{
|
||||
ID: dbUser.ID,
|
||||
Email: dbUser.Email,
|
||||
Password: dbUser.Password,
|
||||
CompanyDetails: dbUser.CompanyDetails,
|
||||
BankDetails: dbUser.BankDetails,
|
||||
CreatedAt: dbUser.CreatedAt,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user