fix: Worker 队列补充 DLX args + GetAllComments 加排序和分页限制
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
|||||||
"feedsystem_video_go/internal/social"
|
"feedsystem_video_go/internal/social"
|
||||||
"feedsystem_video_go/internal/video"
|
"feedsystem_video_go/internal/video"
|
||||||
"feedsystem_video_go/internal/worker"
|
"feedsystem_video_go/internal/worker"
|
||||||
|
mqrabbit "feedsystem_video_go/internal/middleware/rabbitmq"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -194,7 +195,7 @@ func declareSocialTopology(ch *amqp.Channel) error {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
nil,
|
amqp.Table{"x-dead-letter-exchange": mqrabbit.DLXExchange},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -231,7 +232,7 @@ func declarePopularityTopology(ch *amqp.Channel) error {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
nil,
|
amqp.Table{"x-dead-letter-exchange": mqrabbit.DLXExchange},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -265,7 +266,7 @@ func declareLikeTopology(ch *amqp.Channel) error {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
nil,
|
amqp.Table{"x-dead-letter-exchange": mqrabbit.DLXExchange},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -299,7 +300,7 @@ func declareCommentTopology(ch *amqp.Channel) error {
|
|||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
nil,
|
amqp.Table{"x-dead-letter-exchange": mqrabbit.DLXExchange},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1,51 +1,55 @@
|
|||||||
package video
|
package video
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CommentRepository struct {
|
type CommentRepository struct {
|
||||||
db *gorm.DB
|
db *gorm.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewCommentRepository(db *gorm.DB) *CommentRepository {
|
func NewCommentRepository(db *gorm.DB) *CommentRepository {
|
||||||
return &CommentRepository{db: db}
|
return &CommentRepository{db: db}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CommentRepository) CreateComment(ctx context.Context, comment *Comment) error {
|
func (r *CommentRepository) CreateComment(ctx context.Context, comment *Comment) error {
|
||||||
return r.db.WithContext(ctx).Create(comment).Error
|
return r.db.WithContext(ctx).Create(comment).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CommentRepository) DeleteComment(ctx context.Context, comment *Comment) error {
|
func (r *CommentRepository) DeleteComment(ctx context.Context, comment *Comment) error {
|
||||||
return r.db.WithContext(ctx).Delete(comment).Error
|
return r.db.WithContext(ctx).Delete(comment).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CommentRepository) GetAllComments(ctx context.Context, videoID uint) ([]Comment, error) {
|
func (r *CommentRepository) GetAllComments(ctx context.Context, videoID uint) ([]Comment, error) {
|
||||||
var comments []Comment
|
var comments []Comment
|
||||||
err := r.db.WithContext(ctx).Where("video_id = ?", videoID).Find(&comments).Error
|
err := r.db.WithContext(ctx).
|
||||||
return comments, err
|
Where("video_id = ?", videoID).
|
||||||
}
|
Order("created_at asc").
|
||||||
|
Limit(200).
|
||||||
func (r *CommentRepository) IsExist(ctx context.Context, id uint) (bool, error) {
|
Find(&comments).Error
|
||||||
var comment Comment
|
return comments, err
|
||||||
if err := r.db.WithContext(ctx).First(&comment, id).Error; err != nil {
|
}
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return false, nil
|
func (r *CommentRepository) IsExist(ctx context.Context, id uint) (bool, error) {
|
||||||
}
|
var comment Comment
|
||||||
return false, err
|
if err := r.db.WithContext(ctx).First(&comment, id).Error; err != nil {
|
||||||
}
|
if err == gorm.ErrRecordNotFound {
|
||||||
return true, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
return false, err
|
||||||
func (r *CommentRepository) GetByID(ctx context.Context, id uint) (*Comment, error) {
|
}
|
||||||
var comment Comment
|
return true, nil
|
||||||
if err := r.db.WithContext(ctx).First(&comment, id).Error; err != nil {
|
}
|
||||||
if err == gorm.ErrRecordNotFound {
|
|
||||||
return nil, nil
|
func (r *CommentRepository) GetByID(ctx context.Context, id uint) (*Comment, error) {
|
||||||
}
|
var comment Comment
|
||||||
return nil, err
|
if err := r.db.WithContext(ctx).First(&comment, id).Error; err != nil {
|
||||||
}
|
if err == gorm.ErrRecordNotFound {
|
||||||
return &comment, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &comment, nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user