Paperclip/pkg/internal/services/sticker_packs.go

61 lines
1.6 KiB
Go
Raw Normal View History

2024-08-03 07:43:15 +00:00
package services
import (
2024-10-27 05:13:40 +00:00
"git.solsynth.dev/hypernet/nexus/pkg/nex/sec"
2024-11-02 02:41:31 +00:00
"git.solsynth.dev/hypernet/paperclip/pkg/internal/database"
"git.solsynth.dev/hypernet/paperclip/pkg/internal/models"
"gorm.io/gorm"
2024-08-03 07:43:15 +00:00
)
func GetStickerPack(id uint) (models.StickerPack, error) {
var pack models.StickerPack
if err := database.C.Where("id = ?", id).First(&pack).Error; err != nil {
return pack, err
}
return pack, nil
}
2024-08-03 07:43:15 +00:00
func GetStickerPackWithUser(id, userId uint) (models.StickerPack, error) {
var pack models.StickerPack
if err := database.C.Where("id = ? AND account_id = ?", id, userId).First(&pack).Error; err != nil {
return pack, err
}
return pack, nil
}
func ListStickerPackWithStickers(tx *gorm.DB, take, offset int) ([]models.StickerPack, error) {
2024-08-03 07:43:15 +00:00
var packs []models.StickerPack
if err := tx.Limit(take).Offset(offset).Preload("Stickers").Preload("Stickers.Attachment").Find(&packs).Error; err != nil {
2024-08-03 07:43:15 +00:00
return packs, err
}
return packs, nil
}
2024-11-02 18:14:56 +00:00
func NewStickerPack(user *sec.UserInfo, prefix, name, desc string) (models.StickerPack, error) {
2024-08-03 07:43:15 +00:00
pack := models.StickerPack{
Prefix: prefix,
Name: name,
Description: desc,
AccountID: user.ID,
}
if err := database.C.Save(&pack).Error; err != nil {
return pack, err
}
return pack, nil
}
func UpdateStickerPack(pack models.StickerPack) (models.StickerPack, error) {
if err := database.C.Save(&pack).Error; err != nil {
return pack, err
}
return pack, nil
}
func DeleteStickerPack(pack models.StickerPack) (models.StickerPack, error) {
if err := database.C.Delete(&pack).Error; err != nil {
return pack, err
}
return pack, nil
}