43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package http
|
|
|
|
import (
|
|
"quyun/app/models"
|
|
"quyun/app/requests"
|
|
"quyun/database/schemas/public/model"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
"github.com/gofiber/fiber/v3/log"
|
|
)
|
|
|
|
type ListQuery struct {
|
|
Keyword *string `query:"keyword"`
|
|
}
|
|
|
|
// @provider
|
|
type posts struct{}
|
|
|
|
// List posts
|
|
// @Router /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 /show/:id [get]
|
|
// @Bind id path
|
|
func (ctl *posts) Show(ctx fiber.Ctx, id int64) (*model.Posts, error) {
|
|
return models.Posts.GetByID(ctx.Context(), id)
|
|
}
|
|
|
|
// Mine posts
|
|
// @Router /mine [get]
|
|
// @Bind pagination query
|
|
// @Bind query query
|
|
func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
|
|
log.Infof("Fetching posts for user with pagination: %+v and keyword: %v", pagination, query.Keyword)
|
|
return models.Users.PostList(ctx.Context(), 1, pagination, query.Keyword)
|
|
}
|