34 lines
795 B
Go
34 lines
795 B
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.ostiwe.com/ostiwe-com/status/model"
|
|
"git.ostiwe.com/ostiwe-com/status/modules/db"
|
|
)
|
|
|
|
type User interface {
|
|
FindByLogin(ctx context.Context, login string) (*model.User, error)
|
|
FindByID(ctx context.Context, ID uint64) (*model.User, error)
|
|
}
|
|
|
|
type userRepository struct {
|
|
repository
|
|
}
|
|
|
|
func NewUserRepository() User {
|
|
return &userRepository{repository{db: db.Global}}
|
|
}
|
|
|
|
func (u userRepository) FindByLogin(ctx context.Context, login string) (*model.User, error) {
|
|
var user *model.User
|
|
|
|
return user, u.db.WithContext(ctx).Find(&user, "login = ?", login).Error
|
|
}
|
|
|
|
func (u userRepository) FindByID(ctx context.Context, ID uint64) (*model.User, error) {
|
|
var user *model.User
|
|
|
|
return user, u.db.WithContext(ctx).Find(&user, "id = ?", ID).Error
|
|
}
|