Skip to content

Commit

Permalink
refactor: Optimize code structure
Browse files Browse the repository at this point in the history
  • Loading branch information
intyouss committed Sep 8, 2023
1 parent e44f25d commit 21f1307
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/comment/service/internal/biz/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ 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:
if commentText == "" {
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
Expand All @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion app/comment/service/internal/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 21f1307

Please sign in to comment.