refactor: Provide context to user repository
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.ostiwe.com/ostiwe-com/status/model"
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/db"
|
||||
)
|
||||
|
||||
type User interface {
|
||||
FindByLogin(login string) (*model.User, error)
|
||||
FindByID(ID uint64) (*model.User, error)
|
||||
FindByLogin(ctx context.Context, login string) (*model.User, error)
|
||||
FindByID(ctx context.Context, ID uint64) (*model.User, error)
|
||||
}
|
||||
|
||||
type userRepository struct {
|
||||
@@ -18,14 +20,14 @@ func NewUserRepository() User {
|
||||
return &userRepository{repository{db: db.Global}}
|
||||
}
|
||||
|
||||
func (u userRepository) FindByLogin(login string) (*model.User, error) {
|
||||
func (u userRepository) FindByLogin(ctx context.Context, login string) (*model.User, error) {
|
||||
var user *model.User
|
||||
|
||||
return user, u.db.Find(&user, "login = ?", login).Error
|
||||
return user, u.db.WithContext(ctx).Find(&user, "login = ?", login).Error
|
||||
}
|
||||
|
||||
func (u userRepository) FindByID(ID uint64) (*model.User, error) {
|
||||
func (u userRepository) FindByID(ctx context.Context, ID uint64) (*model.User, error) {
|
||||
var user *model.User
|
||||
|
||||
return user, u.db.Find(&user, "id = ?", ID).Error
|
||||
return user, u.db.WithContext(ctx).Find(&user, "id = ?", ID).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user