Files
quyun/backend/app/http/posts.go

33 lines
730 B
Go

package http
import (
"quyun/app/models"
"quyun/app/requests"
"quyun/database/schemas/public/model"
"github.com/gofiber/fiber/v3"
)
type ListQuery struct {
Key *string `query:"key"`
}
// @provider
type posts struct{}
// List posts
// @Router /v1/posts [get]
// @Bind pagination query
// @Bind query query
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
cond := models.Posts.BuildConditionWithKey(query.Key)
return models.Posts.List(ctx.Context(), pagination, cond)
}
// Show
// @Router /v1/posts/:id [get]
// @Bind id path
func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*model.Posts, error) {
return models.Posts.GetByID(ctx.Context(), id)
}