add comment and reply framework

This commit is contained in:
landaiqing
2024-09-19 18:44:53 +08:00
parent ef5d7daa10
commit 8d5d918a7d
11 changed files with 80 additions and 20 deletions

View File

@@ -3,6 +3,7 @@ package api
import (
"schisandra-cloud-album/api/captcha_api"
"schisandra-cloud-album/api/client_api"
"schisandra-cloud-album/api/comment_api"
"schisandra-cloud-album/api/oauth_api"
"schisandra-cloud-album/api/permission_api"
"schisandra-cloud-album/api/role_api"
@@ -21,6 +22,7 @@ type Apis struct {
RoleApi role_api.RoleAPI
PermissionApi permission_api.PermissionAPI
ClientApi client_api.ClientAPI
CommonApi comment_api.CommentAPI
}
// Api new函数实例化实例化完成后会返回结构体地指针类型

View File

@@ -1,3 +1,7 @@
package comment_api
import "schisandra-cloud-album/service"
type CommentAPI struct{}
var commentReplyService = service.Service.CommentReplyService

View File

@@ -1 +1,28 @@
package comment_api
import (
ginI18n "github.com/gin-contrib/i18n"
"github.com/gin-gonic/gin"
"schisandra-cloud-album/api/comment_api/dto"
"schisandra-cloud-album/common/result"
)
// CommentSubmit 提交评论
func (CommentAPI) CommentSubmit(c *gin.Context) {
commentRequest := dto.CommentRequest{}
err := c.ShouldBindJSON(&commentRequest)
if err != nil {
result.FailWithMessage(ginI18n.MustGetMessage(c, "ParamsError"), c)
return
}
content := commentRequest.Content
images := commentRequest.Images
if content == "" {
result.FailWithMessage(ginI18n.MustGetMessage(c, "RequestParamsNotEmpty"), c)
return
}
if len(images) > 5 {
result.FailWithMessage(ginI18n.MustGetMessage(c, "TooManyImages"), c)
return
}
}

View File

@@ -0,0 +1,6 @@
package dto
type CommentRequest struct {
Content string `json:"content"`
Images []string `json:"images"`
}