✨ More stickers apis
This commit is contained in:
parent
ad1d82a2ff
commit
7af44da03b
@ -14,11 +14,13 @@ func MapAPIs(app *fiber.App, baseURL string) {
|
|||||||
api.Put("/attachments/:id", updateAttachmentMeta)
|
api.Put("/attachments/:id", updateAttachmentMeta)
|
||||||
api.Delete("/attachments/:id", deleteAttachment)
|
api.Delete("/attachments/:id", deleteAttachment)
|
||||||
|
|
||||||
|
api.Get("/stickers/manifest", listStickerManifest)
|
||||||
api.Get("/stickers/packs", listStickerPacks)
|
api.Get("/stickers/packs", listStickerPacks)
|
||||||
api.Post("/stickers/packs", createStickerPack)
|
api.Post("/stickers/packs", createStickerPack)
|
||||||
api.Put("/stickers/packs/:packId", updateStickerPack)
|
api.Put("/stickers/packs/:packId", updateStickerPack)
|
||||||
api.Delete("/stickers/packs/:packId", deleteStickerPack)
|
api.Delete("/stickers/packs/:packId", deleteStickerPack)
|
||||||
|
|
||||||
|
api.Get("/stickers", listStickers)
|
||||||
api.Get("/stickers/:stickerId", getSticker)
|
api.Get("/stickers/:stickerId", getSticker)
|
||||||
api.Post("/stickers", createSticker)
|
api.Post("/stickers", createSticker)
|
||||||
api.Put("/stickers/:stickerId", updateSticker)
|
api.Put("/stickers/:stickerId", updateSticker)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
|
||||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/gap"
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/gap"
|
||||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
|
||||||
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/server/exts"
|
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/server/exts"
|
||||||
@ -8,7 +9,7 @@ import (
|
|||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func listStickerPacks(c *fiber.Ctx) error {
|
func listStickerManifest(c *fiber.Ctx) error {
|
||||||
take := c.QueryInt("take", 0)
|
take := c.QueryInt("take", 0)
|
||||||
offset := c.QueryInt("offset", 0)
|
offset := c.QueryInt("offset", 0)
|
||||||
|
|
||||||
@ -23,6 +24,32 @@ func listStickerPacks(c *fiber.Ctx) error {
|
|||||||
return c.JSON(stickers)
|
return c.JSON(stickers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listStickerPacks(c *fiber.Ctx) error {
|
||||||
|
take := c.QueryInt("take", 0)
|
||||||
|
offset := c.QueryInt("offset", 0)
|
||||||
|
|
||||||
|
if take > 100 {
|
||||||
|
take = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
tx := database.C
|
||||||
|
|
||||||
|
if len(c.Query("author")) > 0 {
|
||||||
|
var author models.Account
|
||||||
|
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
} else {
|
||||||
|
tx = tx.Where("account_id = ?", author.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var packs []models.StickerPack
|
||||||
|
if err := tx.Limit(take).Offset(offset).Find(&packs).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
return c.JSON(packs)
|
||||||
|
}
|
||||||
|
|
||||||
func createStickerPack(c *fiber.Ctx) error {
|
func createStickerPack(c *fiber.Ctx) error {
|
||||||
if err := gap.H.EnsureAuthenticated(c); err != nil {
|
if err := gap.H.EnsureAuthenticated(c); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -12,6 +12,36 @@ import (
|
|||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func listStickers(c *fiber.Ctx) error {
|
||||||
|
take := c.QueryInt("take", 0)
|
||||||
|
offset := c.QueryInt("offset", 0)
|
||||||
|
|
||||||
|
if take > 100 {
|
||||||
|
take = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
tx := database.C
|
||||||
|
|
||||||
|
if len(c.Query("author")) > 0 {
|
||||||
|
var author models.Account
|
||||||
|
if err := database.C.Where("name = ?", c.Query("author")).First(&author).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
||||||
|
} else {
|
||||||
|
tx = tx.Where("account_id = ?", author.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if val := c.QueryInt("pack", 0); val > 0 {
|
||||||
|
tx = tx.Where("pack_id = ?", val)
|
||||||
|
}
|
||||||
|
|
||||||
|
var stickers []models.Sticker
|
||||||
|
if err := tx.Limit(take).Offset(offset).Find(&stickers).Error; err != nil {
|
||||||
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
return c.JSON(stickers)
|
||||||
|
}
|
||||||
|
|
||||||
func getSticker(c *fiber.Ctx) error {
|
func getSticker(c *fiber.Ctx) error {
|
||||||
id, _ := c.ParamsInt("stickerId", 0)
|
id, _ := c.ParamsInt("stickerId", 0)
|
||||||
sticker, err := services.GetSticker(uint(id))
|
sticker, err := services.GetSticker(uint(id))
|
||||||
|
Loading…
Reference in New Issue
Block a user