32 lines
692 B
Go
32 lines
692 B
Go
package repository
|
|
|
|
import (
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/db/model"
|
|
"gitea.neur0tx.site/Neur0toxine/vegapokerbot/internal/db/util"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type User struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewUser(db *gorm.DB) *User {
|
|
return &User{db: db}
|
|
}
|
|
|
|
func (u *User) ByID(id uint64) (*model.User, error) {
|
|
var user *model.User
|
|
if err := u.db.First(&user, id).Error; err != nil {
|
|
return nil, util.HandleRecordNotFound(err)
|
|
}
|
|
return user, nil
|
|
}
|
|
|
|
func (u *User) ByIDWithChats(id uint64) (*model.User, error) {
|
|
var user *model.User
|
|
if err := u.db.Preload("Chats").First(&user, id).Error; err != nil {
|
|
return nil, util.HandleRecordNotFound(err)
|
|
}
|
|
return user, nil
|
|
}
|