mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Fix comment activity api.
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gorm.io/gorm"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActivityType uint
|
type ActivityType uint
|
||||||
@@ -22,10 +23,10 @@ type Activity struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ActivityView struct {
|
type ActivityView struct {
|
||||||
ID uint `json:"id"`
|
ID uint `json:"id"`
|
||||||
Time time.Time `json:"time"`
|
Time time.Time `json:"time"`
|
||||||
Type ActivityType `json:"type"`
|
Type ActivityType `json:"type"`
|
||||||
User UserView `json:"user"`
|
User UserView `json:"user"`
|
||||||
Comment *CommentWithResourceView `json:"comment,omitempty"`
|
Comment *CommentView `json:"comment,omitempty"`
|
||||||
Resource *ResourceView `json:"resource,omitempty"`
|
Resource *ResourceView `json:"resource,omitempty"`
|
||||||
}
|
}
|
||||||
|
@@ -20,19 +20,17 @@ func GetActivityList(page int) ([]model.ActivityView, int, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
var comment *model.CommentWithResourceView
|
var comment *model.CommentView
|
||||||
var resource *model.ResourceView
|
var resource *model.ResourceView
|
||||||
if activity.Type == model.ActivityTypeNewComment {
|
switch activity.Type {
|
||||||
|
case model.ActivityTypeNewComment:
|
||||||
c, err := dao.GetCommentByID(activity.RefID)
|
c, err := dao.GetCommentByID(activity.RefID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
r, err := dao.GetResourceByID(c.RefID)
|
comment = c.ToView()
|
||||||
if err != nil {
|
comment.Content, comment.ContentTruncated = restrictCommentLength(c.Content)
|
||||||
return nil, 0, err
|
case model.ActivityTypeNewResource, model.ActivityTypeUpdateResource:
|
||||||
}
|
|
||||||
comment = c.ToViewWithResource(&r)
|
|
||||||
} else if activity.Type == model.ActivityTypeNewResource || activity.Type == model.ActivityTypeUpdateResource {
|
|
||||||
r, err := dao.GetResourceByID(activity.RefID)
|
r, err := dao.GetResourceByID(activity.RefID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
|
Reference in New Issue
Block a user