feat: 更新内容相关接口,使用统一的分页响应结构
This commit is contained in:
@@ -2,6 +2,7 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"quyun/v2/app/http/v1/dto"
|
"quyun/v2/app/http/v1/dto"
|
||||||
|
"quyun/v2/app/requests"
|
||||||
"quyun/v2/app/services"
|
"quyun/v2/app/services"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
@@ -23,7 +24,7 @@ type Content struct{}
|
|||||||
// @Param tenantId query string false "Filter by creator"
|
// @Param tenantId query string false "Filter by creator"
|
||||||
// @Param sort query string false "Sort order" Enums(latest, hot, price_asc)
|
// @Param sort query string false "Sort order" Enums(latest, hot, price_asc)
|
||||||
// @Param page query int false "Page number"
|
// @Param page query int false "Page number"
|
||||||
// @Success 200 {object} dto.ContentListResponse
|
// @Success 200 {object} requests.Pager{items=[]dto.ContentItem}
|
||||||
// @Bind keyword query
|
// @Bind keyword query
|
||||||
// @Bind genre query
|
// @Bind genre query
|
||||||
// @Bind tenantId query
|
// @Bind tenantId query
|
||||||
@@ -33,7 +34,7 @@ func (c *Content) List(
|
|||||||
ctx fiber.Ctx,
|
ctx fiber.Ctx,
|
||||||
keyword, genre, tenantId, sort string,
|
keyword, genre, tenantId, sort string,
|
||||||
page int,
|
page int,
|
||||||
) (*dto.ContentListResponse, error) {
|
) (*requests.Pager, error) {
|
||||||
return services.Content.List(ctx.Context(), keyword, genre, tenantId, sort, page)
|
return services.Content.List(ctx.Context(), keyword, genre, tenantId, sort, page)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,10 +63,10 @@ func (c *Content) Get(ctx fiber.Ctx, id string) (*dto.ContentDetail, error) {
|
|||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param id path string true "Content ID"
|
// @Param id path string true "Content ID"
|
||||||
// @Param page query int false "Page number"
|
// @Param page query int false "Page number"
|
||||||
// @Success 200 {object} dto.CommentListResponse
|
// @Success 200 {object} requests.Pager{items=[]dto.Comment}
|
||||||
// @Bind id path
|
// @Bind id path
|
||||||
// @Bind page query
|
// @Bind page query
|
||||||
func (c *Content) ListComments(ctx fiber.Ctx, id string, page int) (*dto.CommentListResponse, error) {
|
func (c *Content) ListComments(ctx fiber.Ctx, id string, page int) (*requests.Pager, error) {
|
||||||
return services.Content.ListComments(ctx.Context(), id, page)
|
return services.Content.ListComments(ctx.Context(), id, page)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,4 +113,4 @@ func (c *Content) LikeComment(ctx fiber.Ctx, id string) error {
|
|||||||
// @Success 200 {array} dto.Topic
|
// @Success 200 {array} dto.Topic
|
||||||
func (c *Content) ListTopics(ctx fiber.Ctx) ([]dto.Topic, error) {
|
func (c *Content) ListTopics(ctx fiber.Ctx) ([]dto.Topic, error) {
|
||||||
return services.Content.ListTopics(ctx.Context())
|
return services.Content.ListTopics(ctx.Context())
|
||||||
}
|
}
|
||||||
@@ -51,21 +51,11 @@ type Comment struct {
|
|||||||
ReplyTo string `json:"replyTo"`
|
ReplyTo string `json:"replyTo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CommentListResponse struct {
|
|
||||||
Data []Comment `json:"data"`
|
|
||||||
Pagination requests.Pagination `json:"pagination"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CommentCreateForm struct {
|
type CommentCreateForm struct {
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
ReplyTo string `json:"replyTo"`
|
ReplyTo string `json:"replyTo"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContentListResponse struct {
|
|
||||||
Data []ContentItem `json:"data"`
|
|
||||||
Pagination requests.Pagination `json:"pagination"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Topic struct {
|
type Topic struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
@@ -81,4 +71,4 @@ type ContentPrice struct {
|
|||||||
DiscountValue float64 `json:"discountValue"`
|
DiscountValue float64 `json:"discountValue"`
|
||||||
DiscountStartAt string `json:"discountStartAt"`
|
DiscountStartAt string `json:"discountStartAt"`
|
||||||
DiscountEndAt string `json:"discountEndAt"`
|
DiscountEndAt string `json:"discountEndAt"`
|
||||||
}
|
}
|
||||||
@@ -5,21 +5,22 @@ import (
|
|||||||
|
|
||||||
content_dto "quyun/v2/app/http/v1/dto"
|
content_dto "quyun/v2/app/http/v1/dto"
|
||||||
user_dto "quyun/v2/app/http/v1/dto"
|
user_dto "quyun/v2/app/http/v1/dto"
|
||||||
|
"quyun/v2/app/requests"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @provider
|
// @provider
|
||||||
type content struct{}
|
type content struct{}
|
||||||
|
|
||||||
func (s *content) List(ctx context.Context, keyword, genre, tenantId, sort string, page int) (*content_dto.ContentListResponse, error) {
|
func (s *content) List(ctx context.Context, keyword, genre, tenantId, sort string, page int) (*requests.Pager, error) {
|
||||||
return &content_dto.ContentListResponse{}, nil
|
return &requests.Pager{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *content) Get(ctx context.Context, id string) (*content_dto.ContentDetail, error) {
|
func (s *content) Get(ctx context.Context, id string) (*content_dto.ContentDetail, error) {
|
||||||
return &content_dto.ContentDetail{}, nil
|
return &content_dto.ContentDetail{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *content) ListComments(ctx context.Context, id string, page int) (*content_dto.CommentListResponse, error) {
|
func (s *content) ListComments(ctx context.Context, id string, page int) (*requests.Pager, error) {
|
||||||
return &content_dto.CommentListResponse{}, nil
|
return &requests.Pager{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *content) CreateComment(ctx context.Context, id string, form *content_dto.CommentCreateForm) error {
|
func (s *content) CreateComment(ctx context.Context, id string, form *content_dto.CommentCreateForm) error {
|
||||||
@@ -60,4 +61,4 @@ func (s *content) RemoveLike(ctx context.Context, contentId string) error {
|
|||||||
|
|
||||||
func (s *content) ListTopics(ctx context.Context) ([]content_dto.Topic, error) {
|
func (s *content) ListTopics(ctx context.Context) ([]content_dto.Topic, error) {
|
||||||
return []content_dto.Topic{}, nil
|
return []content_dto.Topic{}, nil
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user