From cc5ace114a8331eabff4f3569eee0b171301d3cf Mon Sep 17 00:00:00 2001 From: Rogee Date: Tue, 30 Dec 2025 23:30:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=A0=BC=E5=BC=8F=EF=BC=8C=E5=A2=9E=E5=BC=BA=E5=8F=AF?= =?UTF-8?q?=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/content.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/backend/app/services/content.go b/backend/app/services/content.go index 680c939..74c0c0c 100644 --- a/backend/app/services/content.go +++ b/backend/app/services/content.go @@ -85,7 +85,9 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt cid := cast.ToInt64(id) // Increment Views - _, _ = models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(cid)).UpdateSimple(models.ContentQuery.Views.Add(1)) + _, _ = models.ContentQuery.WithContext(ctx). + Where(models.ContentQuery.ID.Eq(cid)). + UpdateSimple(models.ContentQuery.Views.Add(1)) _, q := models.ContentQuery.QueryContext(ctx) @@ -225,7 +227,12 @@ func (s *content) ListComments(ctx context.Context, userID int64, id string, pag }, nil } -func (s *content) CreateComment(ctx context.Context, userID int64, id string, form *content_dto.CommentCreateForm) error { +func (s *content) CreateComment( + ctx context.Context, + userID int64, + id string, + form *content_dto.CommentCreateForm, +) error { if userID == 0 { return errorx.ErrUnauthorized } @@ -485,7 +492,10 @@ func (s *content) addInteract(ctx context.Context, userID int64, contentId, typ cid := cast.ToInt64(contentId) // Fetch content for author - c, err := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(cid)).Select(models.ContentQuery.UserID, models.ContentQuery.Title).First() + c, err := models.ContentQuery.WithContext(ctx). + Where(models.ContentQuery.ID.Eq(cid)). + Select(models.ContentQuery.UserID, models.ContentQuery.Title). + First() if err != nil { return errorx.ErrRecordNotFound } @@ -515,9 +525,10 @@ func (s *content) addInteract(ctx context.Context, userID int64, contentId, typ if Notification != nil { actionName := "互动" - if typ == "like" { + switch typ { + case "like": actionName = "点赞" - } else if typ == "favorite" { + case "favorite": actionName = "收藏" } _ = Notification.Send(ctx, c.UserID, "interaction", "新的"+actionName, "有人"+actionName+"了您的作品: "+c.Title)