feat:add conds
This commit is contained in:
@@ -3,6 +3,7 @@ package admin
|
||||
import (
|
||||
"quyun/app/models"
|
||||
"quyun/app/requests"
|
||||
"quyun/database/conds"
|
||||
"quyun/database/fields"
|
||||
"quyun/database/schemas/public/model"
|
||||
|
||||
@@ -23,8 +24,12 @@ type posts struct{}
|
||||
// @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)
|
||||
pager, err := models.Posts.List(ctx.Context(), pagination, cond)
|
||||
conds := []conds.Cond{
|
||||
// conds.Post_NotDeleted(),
|
||||
// conds.Post_Status(fields.PostStatusPublished),
|
||||
conds.Post_Like(query.Keyword),
|
||||
}
|
||||
pager, err := models.Posts.List(ctx.Context(), pagination, conds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"quyun/app/models"
|
||||
"quyun/app/requests"
|
||||
"quyun/database/conds"
|
||||
"quyun/database/fields"
|
||||
"quyun/database/schemas/public/model"
|
||||
"quyun/providers/ali"
|
||||
@@ -35,14 +36,13 @@ type posts struct {
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
|
||||
log.Infof("ok", pagination, query.Keyword, user.ID)
|
||||
conds := []conds.Cond{
|
||||
conds.Post_NotDeleted(),
|
||||
conds.Post_Status(fields.PostStatusPublished),
|
||||
conds.Post_Like(query.Keyword),
|
||||
}
|
||||
|
||||
cond := models.Posts.BuildConditionWithKey(query.Keyword)
|
||||
pager, err := models.Posts.List(ctx.Context(), pagination, cond, func(item model.Posts) model.Posts {
|
||||
item.Assets = fields.ToJson([]fields.MediaAsset{})
|
||||
item.Content = ""
|
||||
return item
|
||||
})
|
||||
pager, err := models.Posts.List(ctx.Context(), pagination, conds...)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("post list err: %v", err)
|
||||
return nil, err
|
||||
@@ -106,7 +106,8 @@ type PostItem struct {
|
||||
// @Bind user local
|
||||
func (ctl *posts) Show(ctx fiber.Ctx, id int64, user *model.Users) (*PostItem, error) {
|
||||
log.Infof("Fetching post with ID: %d", id)
|
||||
post, err := models.Posts.GetByID(ctx.Context(), id)
|
||||
|
||||
post, err := models.Posts.GetByID(ctx.Context(), id, conds.Post_NotDeleted(), conds.Post_Status(fields.PostStatusPublished))
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("GetByID err: %v", err)
|
||||
return nil, err
|
||||
@@ -192,12 +193,12 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
|
||||
func (ctl *posts) Mine(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery, user *model.Users) (*requests.Pager, error) {
|
||||
log.Infof("Fetching posts for user with pagination: %+v and keyword: %v", pagination, query.Keyword)
|
||||
|
||||
cond := models.Posts.BuildConditionWithKey(query.Keyword)
|
||||
pager, err := models.Users.PostList(ctx.Context(), user.ID, pagination, cond, func(item model.Posts) model.Posts {
|
||||
item.Assets = fields.ToJson([]fields.MediaAsset{})
|
||||
item.Content = ""
|
||||
return item
|
||||
})
|
||||
conds := []conds.Cond{
|
||||
conds.Post_NotDeleted(),
|
||||
conds.Post_Status(fields.PostStatusPublished),
|
||||
conds.Post_Like(query.Keyword),
|
||||
}
|
||||
pager, err := models.Users.PostList(ctx.Context(), user.ID, pagination, conds...)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("post list err: %v", err)
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user