Able to get sticker pack by id

This commit is contained in:
LittleSheep 2024-09-25 22:55:15 +08:00
parent fa997a19a1
commit fdadebbeab
3 changed files with 19 additions and 0 deletions

View File

@ -26,6 +26,7 @@ func MapAPIs(app *fiber.App, baseURL string) {
api.Get("/stickers/lookup", lookupStickerBatch)
api.Get("/stickers/lookup/:alias", lookupSticker)
api.Get("/stickers/packs", listStickerPacks)
api.Get("/stickers/packs/:packId", getStickerPack)
api.Post("/stickers/packs", createStickerPack)
api.Put("/stickers/packs/:packId", updateStickerPack)
api.Delete("/stickers/packs/:packId", deleteStickerPack)

View File

@ -44,6 +44,16 @@ func listStickerPacks(c *fiber.Ctx) error {
})
}
func getStickerPack(c *fiber.Ctx) error {
id, _ := c.ParamsInt("packId", 0)
pack, err := services.GetStickerPack(uint(id))
if err != nil {
return fiber.NewError(fiber.StatusNotFound, err.Error())
}
return c.JSON(pack)
}
func createStickerPack(c *fiber.Ctx) error {
if err := gap.H.EnsureAuthenticated(c); err != nil {
return err

View File

@ -6,6 +6,14 @@ import (
"gorm.io/gorm"
)
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
}
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 {