feat: phone validation
Some checks failed
build quyun / Build (push) Failing after 1m25s

This commit is contained in:
2025-12-20 11:47:45 +08:00
parent fdbf26d751
commit 0e4af79b53
31 changed files with 1130 additions and 984 deletions

View File

@@ -21,15 +21,15 @@ type posts struct{}
// List posts
//
// @Summary 作品列表
// @Tags Admin Posts
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query ListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=PostItem} "成功"
// @Router /admin/posts [get]
// @Bind pagination query
// @Bind query query
// @Summary 作品列表
// @Tags Admin Posts
// @Produce json
// @Param pagination query requests.Pagination false "分页参数"
// @Param query query ListQuery false "筛选条件"
// @Success 200 {object} requests.Pager{items=PostItem} "成功"
// @Router /admin/posts [get]
// @Bind pagination query
// @Bind query query
func (ctl *posts) List(ctx fiber.Ctx, pagination *requests.Pagination, query *ListQuery) (*requests.Pager, error) {
conds := []gen.Condition{
models.PostQuery.Title.Like(*query.Keyword),
@@ -75,14 +75,14 @@ type PostForm struct {
// Create
//
// @Summary 创建作品
// @Tags Admin Posts
// @Accept json
// @Produce json
// @Param form body PostForm true "请求体"
// @Success 200 {object} any "成功"
// @Router /admin/posts [post]
// @Bind form body
// @Summary 创建作品
// @Tags Admin Posts
// @Accept json
// @Produce json
// @Param form body PostForm true "请求体"
// @Success 200 {object} any "成功"
// @Router /admin/posts [post]
// @Bind form body
func (ctl *posts) Create(ctx fiber.Ctx, form *PostForm) error {
post := models.Post{
Title: form.Title,
@@ -101,7 +101,7 @@ func (ctl *posts) Create(ctx fiber.Ctx, form *PostForm) error {
if err != nil {
return err
}
assets := lo.Map(medias, func(media *models.Media, _ int) fields.MediaAsset {
assets := lo.Map(medias, func(media *models.Medium, _ int) fields.MediaAsset {
return fields.MediaAsset{
Type: media.MimeType,
Media: media.ID,
@@ -119,16 +119,16 @@ func (ctl *posts) Create(ctx fiber.Ctx, form *PostForm) error {
// Update posts
//
// @Summary 更新作品
// @Tags Admin Posts
// @Accept json
// @Produce json
// @Param id path int64 true "作品 ID"
// @Param form body PostForm true "请求体"
// @Success 200 {object} any "成功"
// @Router /admin/posts/:id [put]
// @Bind post path key(id) model(id)
// @Bind form body
// @Summary 更新作品
// @Tags Admin Posts
// @Accept json
// @Produce json
// @Param id path int64 true "作品 ID"
// @Param form body PostForm true "请求体"
// @Success 200 {object} any "成功"
// @Router /admin/posts/:id [put]
// @Bind post path key(id) model(id)
// @Bind form body
func (ctl *posts) Update(ctx fiber.Ctx, post *models.Post, form *PostForm) error {
post.Title = form.Title
post.HeadImages = types.NewJSONType(form.HeadImages)
@@ -144,7 +144,7 @@ func (ctl *posts) Update(ctx fiber.Ctx, post *models.Post, form *PostForm) error
if err != nil {
return err
}
assets := lo.Map(medias, func(media *models.Media, _ int) fields.MediaAsset {
assets := lo.Map(medias, func(media *models.Medium, _ int) fields.MediaAsset {
return fields.MediaAsset{
Type: media.MimeType,
Media: media.ID,
@@ -162,13 +162,13 @@ func (ctl *posts) Update(ctx fiber.Ctx, post *models.Post, form *PostForm) error
// Delete posts
//
// @Summary 删除作品
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 204 {object} any "成功"
// @Router /admin/posts/:id [delete]
// @Bind post path key(id) model(id)
// @Summary 删除作品
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 204 {object} any "成功"
// @Router /admin/posts/:id [delete]
// @Bind post path key(id) model(id)
func (ctl *posts) Delete(ctx fiber.Ctx, post *models.Post) error {
if _, err := post.ForceDelete(ctx); err != nil {
return err
@@ -178,19 +178,19 @@ func (ctl *posts) Delete(ctx fiber.Ctx, post *models.Post) error {
type PostItem struct {
*models.Post
Medias []*models.Media `json:"medias"`
BoughtCount int64 `json:"bought_count"`
Medias []*models.Medium `json:"medias"`
BoughtCount int64 `json:"bought_count"`
}
// Show posts by id
//
// @Summary 作品详情
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 200 {object} PostItem "成功"
// @Router /admin/posts/:id [get]
// @Bind post path key(id) model(id)
// @Summary 作品详情
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Success 200 {object} PostItem "成功"
// @Router /admin/posts/:id [get]
// @Bind post path key(id) model(id)
func (ctl *posts) Show(ctx fiber.Ctx, post *models.Post) (*PostItem, error) {
medias, err := services.Media.GetByIds(ctx, lo.Map(post.Assets.Data(), func(asset fields.MediaAsset, _ int) int64 {
return asset.Media
@@ -206,15 +206,15 @@ func (ctl *posts) Show(ctx fiber.Ctx, post *models.Post) (*PostItem, error) {
// SendTo
//
// @Summary 赠送作品给用户
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Param userId path int64 true "用户 ID"
// @Success 200 {object} any "成功"
// @Router /admin/posts/:id/send-to/:userId [post]
// @Bind post path key(id) model(id)
// @Bind user path key(userId) model(id)
// @Summary 赠送作品给用户
// @Tags Admin Posts
// @Produce json
// @Param id path int64 true "作品 ID"
// @Param userId path int64 true "用户 ID"
// @Success 200 {object} any "成功"
// @Router /admin/posts/:id/send-to/:userId [post]
// @Bind post path key(id) model(id)
// @Bind user path key(userId) model(id)
func (ctl *posts) SendTo(ctx fiber.Ctx, post *models.Post, user *models.User) error {
if err := services.Posts.SendTo(ctx, post.ID, user.ID); err != nil {
return err