116 lines
3.2 KiB
Go
116 lines
3.2 KiB
Go
package v1
|
|
|
|
import (
|
|
"quyun/v2/app/http/v1/dto"
|
|
"quyun/v2/app/requests"
|
|
"quyun/v2/app/services"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
// @provider
|
|
type Content struct{}
|
|
|
|
// List contents (Explore / Search)
|
|
//
|
|
// @Router /v1/contents [get]
|
|
// @Summary List contents
|
|
// @Description List contents with filtering and pagination
|
|
// @Tags Content
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param keyword query string false "Search keyword"
|
|
// @Param genre query string false "Genre"
|
|
// @Param tenantId query string false "Filter by creator"
|
|
// @Param sort query string false "Sort order" Enums(latest, hot, price_asc)
|
|
// @Param page query int false "Page number"
|
|
// @Success 200 {object} requests.Pager{items=[]dto.ContentItem}
|
|
// @Bind keyword query
|
|
// @Bind genre query
|
|
// @Bind tenantId query
|
|
// @Bind sort query
|
|
// @Bind page query
|
|
func (c *Content) List(
|
|
ctx fiber.Ctx,
|
|
keyword, genre, tenantId, sort string,
|
|
page int,
|
|
) (*requests.Pager, error) {
|
|
return services.Content.List(ctx.Context(), keyword, genre, tenantId, sort, page)
|
|
}
|
|
|
|
// Get content detail
|
|
//
|
|
// @Router /v1/contents/:id [get]
|
|
// @Summary Get content detail
|
|
// @Description Get content detail by ID
|
|
// @Tags Content
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Content ID"
|
|
// @Success 200 {object} dto.ContentDetail
|
|
// @Bind id path
|
|
func (c *Content) Get(ctx fiber.Ctx, id string) (*dto.ContentDetail, error) {
|
|
return services.Content.Get(ctx.Context(), id)
|
|
}
|
|
|
|
// Get comments for a content
|
|
//
|
|
// @Router /v1/contents/:id/comments [get]
|
|
// @Summary Get comments
|
|
// @Description Get comments for a content
|
|
// @Tags Content
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Content ID"
|
|
// @Param page query int false "Page number"
|
|
// @Success 200 {object} requests.Pager{items=[]dto.Comment}
|
|
// @Bind id path
|
|
// @Bind page query
|
|
func (c *Content) ListComments(ctx fiber.Ctx, id string, page int) (*requests.Pager, error) {
|
|
return services.Content.ListComments(ctx.Context(), id, page)
|
|
}
|
|
|
|
// Post a comment
|
|
//
|
|
// @Router /v1/contents/:id/comments [post]
|
|
// @Summary Post comment
|
|
// @Description Post a comment to a content
|
|
// @Tags Content
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Content ID"
|
|
// @Param form body dto.CommentCreateForm true "Comment form"
|
|
// @Success 200 {string} string "Comment created"
|
|
// @Bind id path
|
|
// @Bind form body
|
|
func (c *Content) CreateComment(ctx fiber.Ctx, id string, form *dto.CommentCreateForm) error {
|
|
return services.Content.CreateComment(ctx.Context(), id, form)
|
|
}
|
|
|
|
// Like a comment
|
|
//
|
|
// @Router /v1/comments/:id/like [post]
|
|
// @Summary Like comment
|
|
// @Description Like a comment
|
|
// @Tags Content
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Comment ID"
|
|
// @Success 200 {string} string "Liked"
|
|
// @Bind id path
|
|
func (c *Content) LikeComment(ctx fiber.Ctx, id string) error {
|
|
return services.Content.LikeComment(ctx.Context(), id)
|
|
}
|
|
|
|
// List curated topics
|
|
//
|
|
// @Router /v1/topics [get]
|
|
// @Summary List topics
|
|
// @Description List curated topics
|
|
// @Tags Content
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} dto.Topic
|
|
func (c *Content) ListTopics(ctx fiber.Ctx) ([]dto.Topic, error) {
|
|
return services.Content.ListTopics(ctx.Context())
|
|
} |