refactor: 优化代码格式,增强可读性
This commit is contained in:
@@ -85,7 +85,9 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
|
|||||||
cid := cast.ToInt64(id)
|
cid := cast.ToInt64(id)
|
||||||
|
|
||||||
// Increment Views
|
// 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)
|
_, q := models.ContentQuery.QueryContext(ctx)
|
||||||
|
|
||||||
@@ -225,7 +227,12 @@ func (s *content) ListComments(ctx context.Context, userID int64, id string, pag
|
|||||||
}, nil
|
}, 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 {
|
if userID == 0 {
|
||||||
return errorx.ErrUnauthorized
|
return errorx.ErrUnauthorized
|
||||||
}
|
}
|
||||||
@@ -485,7 +492,10 @@ func (s *content) addInteract(ctx context.Context, userID int64, contentId, typ
|
|||||||
cid := cast.ToInt64(contentId)
|
cid := cast.ToInt64(contentId)
|
||||||
|
|
||||||
// Fetch content for author
|
// 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 {
|
if err != nil {
|
||||||
return errorx.ErrRecordNotFound
|
return errorx.ErrRecordNotFound
|
||||||
}
|
}
|
||||||
@@ -515,9 +525,10 @@ func (s *content) addInteract(ctx context.Context, userID int64, contentId, typ
|
|||||||
|
|
||||||
if Notification != nil {
|
if Notification != nil {
|
||||||
actionName := "互动"
|
actionName := "互动"
|
||||||
if typ == "like" {
|
switch typ {
|
||||||
|
case "like":
|
||||||
actionName = "点赞"
|
actionName = "点赞"
|
||||||
} else if typ == "favorite" {
|
case "favorite":
|
||||||
actionName = "收藏"
|
actionName = "收藏"
|
||||||
}
|
}
|
||||||
_ = Notification.Send(ctx, c.UserID, "interaction", "新的"+actionName, "有人"+actionName+"了您的作品: "+c.Title)
|
_ = Notification.Send(ctx, c.UserID, "interaction", "新的"+actionName, "有人"+actionName+"了您的作品: "+c.Title)
|
||||||
|
|||||||
Reference in New Issue
Block a user