diff --git a/dal/comment.gen.go b/dal/comment.gen.go
index 84e5ef7..9a837e5 100644
--- a/dal/comment.gen.go
+++ b/dal/comment.gen.go
@@ -42,6 +42,7 @@ func newComment(db *gorm.DB, opts ...gen.DOOption) comment {
_comment.Status = field.NewField(tableName, "status")
_comment.TopPriority = field.NewInt32(tableName, "top_priority")
_comment.UserAgent = field.NewString(tableName, "user_agent")
+ _comment.Likes = field.NewInt32(tableName, "likes")
_comment.fillFieldMap()
@@ -69,6 +70,7 @@ type comment struct {
Status field.Field
TopPriority field.Int32
UserAgent field.String
+ Likes field.Int32
fieldMap map[string]field.Expr
}
@@ -102,6 +104,7 @@ func (c *comment) updateTableName(table string) *comment {
c.Status = field.NewField(table, "status")
c.TopPriority = field.NewInt32(table, "top_priority")
c.UserAgent = field.NewString(table, "user_agent")
+ c.Likes = field.NewInt32(table, "likes")
c.fillFieldMap()
@@ -144,6 +147,7 @@ func (c *comment) fillFieldMap() {
c.fieldMap["status"] = c.Status
c.fieldMap["top_priority"] = c.TopPriority
c.fieldMap["user_agent"] = c.UserAgent
+ c.fieldMap["likes"] = c.Likes
}
func (c comment) clone(db *gorm.DB) comment {
diff --git a/handler/content/api/comment.go b/handler/content/api/comment.go
new file mode 100644
index 0000000..f3fa16f
--- /dev/null
+++ b/handler/content/api/comment.go
@@ -0,0 +1,26 @@
+package api
+
+import (
+ "github.com/gin-gonic/gin"
+
+ "github.com/go-sonic/sonic/service"
+ "github.com/go-sonic/sonic/util"
+)
+
+type CommentHandler struct {
+ BaseCommentService service.BaseCommentService
+}
+
+func NewCommentHandler(baseCommentService service.BaseCommentService) *CommentHandler {
+ return &CommentHandler{
+ BaseCommentService: baseCommentService,
+ }
+}
+
+func (c *CommentHandler) Like(ctx *gin.Context) (interface{}, error) {
+ commentID, err := util.ParamInt32(ctx, "commentID")
+ if err != nil {
+ return nil, err
+ }
+ return nil, c.BaseCommentService.IncreaseLike(ctx, commentID)
+}
diff --git a/handler/content/api/init.go b/handler/content/api/init.go
index 1890ecc..40af7b7 100644
--- a/handler/content/api/init.go
+++ b/handler/content/api/init.go
@@ -12,5 +12,6 @@ func init() {
NewSheetHandler,
NewOptionHandler,
NewPhotoHandler,
+ NewCommentHandler,
)
}
diff --git a/handler/router.go b/handler/router.go
index 4b00aa4..5e92c14 100644
--- a/handler/router.go
+++ b/handler/router.go
@@ -346,6 +346,8 @@ func (s *Server) RegisterRouters() {
contentAPIRouter.GET("/links/team_view", s.wrapHandler(s.ContentAPILinkHandler.LinkTeamVO))
contentAPIRouter.GET("/options/comment", s.wrapHandler(s.ContentAPIOptionHandler.Comment))
+
+ contentAPIRouter.POST("/comments/:commentID/likes", s.wrapHandler(s.ContentAPICommentHandler.Like))
}
}
}
diff --git a/handler/server.go b/handler/server.go
index 24e2dfc..afd2744 100644
--- a/handler/server.go
+++ b/handler/server.go
@@ -77,6 +77,7 @@ type Server struct {
ContentAPISheetHandler *api.SheetHandler
ContentAPIOptionHandler *api.OptionHandler
ContentAPIPhotoHandler *api.PhotoHandler
+ ContentAPICommentHandler *api.CommentHandler
}
type ServerParams struct {
@@ -132,6 +133,7 @@ type ServerParams struct {
ContentAPISheetHandler *api.SheetHandler
ContentAPIOptionHandler *api.OptionHandler
ContentAPIPhotoHandler *api.PhotoHandler
+ ContentAPICommentHandler *api.CommentHandler
}
func NewServer(param ServerParams, lifecycle fx.Lifecycle) *Server {
@@ -197,6 +199,7 @@ func NewServer(param ServerParams, lifecycle fx.Lifecycle) *Server {
ContentAPIOptionHandler: param.ContentAPIOptionHandler,
ContentSearchHandler: param.ContentSearchHandler,
ContentAPIPhotoHandler: param.ContentAPIPhotoHandler,
+ ContentAPICommentHandler: param.ContentAPICommentHandler,
}
lifecycle.Append(fx.Hook{
OnStop: httpServer.Shutdown,
diff --git a/model/dto/comment.go b/model/dto/comment.go
index b46daa2..bb7aba0 100644
--- a/model/dto/comment.go
+++ b/model/dto/comment.go
@@ -17,4 +17,5 @@ type Comment struct {
AllowNotification bool `json:"allowNotification"`
CreateTime int64 `json:"createTime"`
Avatar string `json:"avatar"`
+ Likes int32 `json:"likes"`
}
diff --git a/model/entity/comment.gen.go b/model/entity/comment.gen.go
index 5bed316..b6a40bf 100644
--- a/model/entity/comment.gen.go
+++ b/model/entity/comment.gen.go
@@ -31,6 +31,7 @@ type Comment struct {
Status consts.CommentStatus `gorm:"column:status;type:bigint;not null;index:comment_type_status,priority:2" json:"status"`
TopPriority int32 `gorm:"column:top_priority;type:int;not null" json:"top_priority"`
UserAgent string `gorm:"column:user_agent;type:varchar(511);not null" json:"user_agent"`
+ Likes int32 `gorm:"column:likes;type:int;not null;default: 0" json:"likes"`
}
// TableName Comment's table name
diff --git a/model/property/comment.go b/model/property/comment.go
index 010569b..725a832 100644
--- a/model/property/comment.go
+++ b/model/property/comment.go
@@ -5,7 +5,7 @@ import "reflect"
var (
CommentGravatarDefault = Property{
KeyValue: "comment_gravatar_default",
- DefaultValue: "mm",
+ DefaultValue: "identicon",
Kind: reflect.String,
}
CommentNewNeedCheck = Property{
@@ -40,12 +40,12 @@ var (
}
CommentInternalPluginJs = Property{
KeyValue: "comment_internal_plugin_js",
- DefaultValue: "//cdn.jsdelivr.net/npm/halo-comment@latest/dist/halo-comment.min.js",
+ DefaultValue: "https://cdn.jsdelivr.net/npm/halo-comment@latest/dist/halo-comment.min.js",
Kind: reflect.String,
}
CommentGravatarSource = Property{
KeyValue: "gravatar_source",
- DefaultValue: "//gravatar.com/avatar/",
+ DefaultValue: "https://gravatar.com/avatar/",
Kind: reflect.String,
}
CommentBanTime = Property{
diff --git a/model/vo/comment.go b/model/vo/comment.go
index d007bf5..f4be555 100644
--- a/model/vo/comment.go
+++ b/model/vo/comment.go
@@ -28,5 +28,6 @@ type JournalCommentWithJournal struct {
type CommentWithHasChildren struct {
*dto.Comment
- HasChildren bool `json:"hasChildren"`
+ HasChildren bool `json:"hasChildren"`
+ ChildrenCount int64 `json:"childrenCount"`
}
diff --git a/resources/template/common/macro/global_macro.tmpl b/resources/template/common/macro/global_macro.tmpl
index 9f151f6..a805dce 100644
--- a/resources/template/common/macro/global_macro.tmpl
+++ b/resources/template/common/macro/global_macro.tmpl
@@ -12,4 +12,19 @@