Fix comment activity api.

This commit is contained in:
2025-07-04 16:07:52 +08:00
parent 6365827748
commit 549c2d48d6
2 changed files with 14 additions and 15 deletions

View File

@@ -1,8 +1,9 @@
package model
import (
"gorm.io/gorm"
"time"
"gorm.io/gorm"
)
type ActivityType uint
@@ -26,6 +27,6 @@ type ActivityView struct {
Time time.Time `json:"time"`
Type ActivityType `json:"type"`
User UserView `json:"user"`
Comment *CommentWithResourceView `json:"comment,omitempty"`
Comment *CommentView `json:"comment,omitempty"`
Resource *ResourceView `json:"resource,omitempty"`
}

View File

@@ -20,19 +20,17 @@ func GetActivityList(page int) ([]model.ActivityView, int, error) {
if err != nil {
return nil, 0, err
}
var comment *model.CommentWithResourceView
var comment *model.CommentView
var resource *model.ResourceView
if activity.Type == model.ActivityTypeNewComment {
switch activity.Type {
case model.ActivityTypeNewComment:
c, err := dao.GetCommentByID(activity.RefID)
if err != nil {
return nil, 0, err
}
r, err := dao.GetResourceByID(c.RefID)
if err != nil {
return nil, 0, err
}
comment = c.ToViewWithResource(&r)
} else if activity.Type == model.ActivityTypeNewResource || activity.Type == model.ActivityTypeUpdateResource {
comment = c.ToView()
comment.Content, comment.ContentTruncated = restrictCommentLength(c.Content)
case model.ActivityTypeNewResource, model.ActivityTypeUpdateResource:
r, err := dao.GetResourceByID(activity.RefID)
if err != nil {
return nil, 0, err