small fixes
This commit is contained in:
@@ -41,6 +41,14 @@ type RPUser struct {
|
||||
CompressLimit int `db:"compress_limit"`
|
||||
}
|
||||
|
||||
type RPWaifuPrompts struct {
|
||||
WaifuID int `db:"waifu_id"`
|
||||
Waifu *Waifu
|
||||
|
||||
AppearancePrompt string `db:"appearance_prompt"`
|
||||
PersonalityPrompt string `db:"personality_prompt"`
|
||||
}
|
||||
|
||||
type RPRepository struct {
|
||||
db *sqlx.DB
|
||||
}
|
||||
@@ -164,6 +172,12 @@ func (rep RPRepository) GetSetting(id int) (RPSetting, error) {
|
||||
return setting, err
|
||||
}
|
||||
|
||||
func (rep RPRepository) GetWaifuPrompts(waifuId int) (RPWaifuPrompts, error) {
|
||||
prompts := RPWaifuPrompts{}
|
||||
err := rep.db.Get(&prompts, "SELECT * FROM rp_waifu_prompts WHERE waifu_id=$1;", waifuId)
|
||||
return prompts, err
|
||||
}
|
||||
|
||||
func (rep RPRepository) UpdateUserCompressSettings(user RPUser) (RPUser, error) {
|
||||
query, args, err := sqlx.In(
|
||||
"UPDATE rp_users SET compress_method=?, compress_limit=? WHERE user_id=?;",
|
||||
|
||||
@@ -30,9 +30,12 @@ func NewWaifuRepository(db *laniakea.DatabaseContext) *WaifuRepository {
|
||||
return &WaifuRepository{db: db.PostgresSQL}
|
||||
}
|
||||
|
||||
func (rep *WaifuRepository) GetAll() ([]Waifu, error) {
|
||||
waifus, err := sqlx.List[Waifu](rep.db, "SELECT * FROM waifus;")
|
||||
//userRep := newUserRepository(rep.db)
|
||||
func (rep *WaifuRepository) GetAll() ([]*Waifu, error) {
|
||||
waifus := make([]*Waifu, 0)
|
||||
err := rep.db.Select(&waifus, "SELECT * FROM waifus;")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, waifu := range waifus {
|
||||
if !waifu.OwnerID.Valid {
|
||||
@@ -40,12 +43,15 @@ func (rep *WaifuRepository) GetAll() ([]Waifu, error) {
|
||||
}
|
||||
waifu.Owner = new(User)
|
||||
err = rep.db.Get(waifu.Owner, "SELECT * FROM users WHERE id=$1;", waifu.OwnerID.Int64)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return waifus, err
|
||||
}
|
||||
|
||||
func (rep *WaifuRepository) GetByUserId(userId int) ([]Waifu, error) {
|
||||
waifus, err := sqlx.List[Waifu](rep.db, "SELECT waifus.* FROM waifus WHERE owner_id=$1;", userId)
|
||||
func (rep *WaifuRepository) GetByUserId(userId int) ([]*Waifu, error) {
|
||||
waifus, err := sqlx.List[*Waifu](rep.db, "SELECT waifus.* FROM waifus WHERE owner_id=$1;", userId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -84,9 +90,9 @@ func (rep *WaifuRepository) GetFreeByRarity(rarity int) ([]Waifu, error) {
|
||||
return waifus, err
|
||||
}
|
||||
|
||||
func (rep *WaifuRepository) GetById(id int) (Waifu, error) {
|
||||
waifu := Waifu{}
|
||||
err := rep.db.Get(&waifu, "SELECT * FROM waifus WHERE id=$1;", id)
|
||||
func (rep *WaifuRepository) GetById(id int) (*Waifu, error) {
|
||||
waifu := new(Waifu)
|
||||
err := rep.db.Get(waifu, "SELECT * FROM waifus WHERE id=$1;", id)
|
||||
if err != nil {
|
||||
return waifu, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user