From 21f130710290db621a37d2a089e67ddb87f04545 Mon Sep 17 00:00:00 2001 From: intyouss <123916296+intyouss@users.noreply.github.com> Date: Fri, 8 Sep 2023 15:36:20 +0800 Subject: [PATCH] refactor: Optimize code structure --- app/comment/service/internal/biz/comment.go | 10 +++++----- app/comment/service/internal/data/data.go | 3 ++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/comment/service/internal/biz/comment.go b/app/comment/service/internal/biz/comment.go index 260ee4a..0a2b66e 100644 --- a/app/comment/service/internal/biz/comment.go +++ b/app/comment/service/internal/biz/comment.go @@ -97,7 +97,7 @@ func (uc *CommentUseCase) GetCommentList( func (uc *CommentUseCase) CommentAction( ctx context.Context, videoId, commentId uint32, actionType uint32, commentText string, -) (c *Comment, err error) { +) (*Comment, error) { userId := ctx.Value(middleware.UserIdKey("user_id")).(uint32) switch actionType { case CreateType: @@ -105,7 +105,7 @@ func (uc *CommentUseCase) CommentAction( return nil, ErrCommentTextEmpty } createTime := time.Now().Format("01-02") - c, err = uc.repo.CreateComment(ctx, videoId, commentText, createTime) + c, err := uc.repo.CreateComment(ctx, videoId, commentText, createTime) if err != nil { uc.log.Errorf("CreateComment err: %v", err) return nil, err @@ -116,17 +116,17 @@ func (uc *CommentUseCase) CommentAction( return nil, err } c.User = users[0] - return + return c, nil case DeleteType: if commentId == 0 { return nil, ErrInvalidId } - err = uc.repo.DeleteComment(ctx, videoId, commentId) + err := uc.repo.DeleteComment(ctx, videoId, commentId) if err != nil { uc.log.Errorf("DeleteComment err: %v", err) return nil, err } - return + return nil, nil default: return nil, errorX.ErrInValidActionType } diff --git a/app/comment/service/internal/data/data.go b/app/comment/service/internal/data/data.go index f4d9837..cb30aa2 100644 --- a/app/comment/service/internal/data/data.go +++ b/app/comment/service/internal/data/data.go @@ -4,12 +4,13 @@ import ( "context" "sync" + "github.com/go-redis/redis/v8" + "github.com/segmentio/kafka-go" "github.com/toomanysource/atreus/app/comment/service/internal/conf" "github.com/go-kratos/kratos/v2/log" - "github.com/go-redis/redis/v8" "github.com/google/wire" "gorm.io/driver/mysql" "gorm.io/gorm"