33 lines
742 B
Go
33 lines
742 B
Go
package http
|
|
|
|
import (
|
|
"quyun/app/models"
|
|
"quyun/app/requests"
|
|
"quyun/database/schemas/public/model"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
type ListQuery struct {
|
|
keyword *string `query:"keyword"`
|
|
}
|
|
|
|
// @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.keyword)
|
|
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)
|
|
}
|