Skip to content

Commit

Permalink
Fix issue (apache#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yang Wong committed Dec 17, 2023
1 parent a00f660 commit 66f2ef8
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 1,361 deletions.
50 changes: 15 additions & 35 deletions cmd/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions internal/controller/comment_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ func (cc *CommentController) GetCommentPersonalWithPage(ctx *gin.Context) {
return
}

req.UserID = middleware.GetLoginUserIDFromContext(ctx)

req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
resp, err := cc.commentService.GetCommentPersonalWithPage(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/controller/question_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -788,8 +788,9 @@ func (qc *QuestionController) GetSimilarQuestions(ctx *gin.Context) {
// @Router /answer/api/v1/personal/qa/top [get]
func (qc *QuestionController) UserTop(ctx *gin.Context) {
userName := ctx.Query("username")
loginUserRole := ctx.Query("login_user_role")
userID := middleware.GetLoginUserIDFromContext(ctx)
questionList, answerList, err := qc.questionService.SearchUserTopList(ctx, userName, userID)
questionList, answerList, err := qc.questionService.SearchUserTopList(ctx, userName, userID, loginUserRole)
handler.HandleResponse(ctx, err, gin.H{
"question": questionList,
"answer": answerList,
Expand All @@ -814,7 +815,6 @@ func (qc *QuestionController) PersonalQuestionPage(ctx *gin.Context) {
if handler.BindAndCheck(ctx, req) {
return
}

req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)
resp, err := qc.questionService.PersonalQuestionPage(ctx, req)
handler.HandleResponse(ctx, err, resp)
Expand Down Expand Up @@ -862,7 +862,6 @@ func (qc *QuestionController) PersonalCollectionPage(ctx *gin.Context) {
}

req.UserID = middleware.GetLoginUserIDFromContext(ctx)

resp, err := qc.questionService.PersonalCollectionPage(ctx, req)
handler.HandleResponse(ctx, err, resp)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/rank_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (cc *RankController) GetRankPersonalWithPage(ctx *gin.Context) {
return
}

req.UserID = middleware.GetLoginUserIDFromContext(ctx)
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)

resp, err := cc.rankService.GetRankPersonalPage(ctx, req)
handler.HandleResponse(ctx, err, resp)
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/vote_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (vc *VoteController) UserVotes(ctx *gin.Context) {
return
}

req.UserID = middleware.GetLoginUserIDFromContext(ctx)
req.LoginUserID = middleware.GetLoginUserIDFromContext(ctx)

resp, err := vc.VoteService.ListUserVotes(ctx, req)
handler.HandleResponse(ctx, err, resp)
Expand Down
4 changes: 4 additions & 0 deletions internal/schema/comment_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,10 @@ type GetCommentPersonalWithPageReq struct {
PageSize int `validate:"omitempty,min=1" form:"page_size"`
// username
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`
// login user role
LoginUserRole string `form:"login_user_role"`
// login user id
LoginUserID string `json:"-"`
// user id
UserID string `json:"-"`
}
Expand Down
29 changes: 16 additions & 13 deletions internal/schema/question_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,23 +464,26 @@ type AdminUpdateQuestionStatusReq struct {
}

type PersonalQuestionPageReq struct {
Page int `validate:"omitempty,min=1" form:"page"`
PageSize int `validate:"omitempty,min=1" form:"page_size"`
OrderCond string `validate:"omitempty,oneof=newest active frequent score unanswered" form:"order"`
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`
LoginUserID string `json:"-"`
Page int `validate:"omitempty,min=1" form:"page"`
PageSize int `validate:"omitempty,min=1" form:"page_size"`
OrderCond string `validate:"omitempty,oneof=newest active frequent score unanswered" form:"order"`
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`
LoginUserID string `json:"-"`
LoginUserRole string `form:"login_user_role"`
}

type PersonalAnswerPageReq struct {
Page int `validate:"omitempty,min=1" form:"page"`
PageSize int `validate:"omitempty,min=1" form:"page_size"`
OrderCond string `validate:"omitempty,oneof=newest active frequent score unanswered" form:"order"`
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`
LoginUserID string `json:"-"`
Page int `validate:"omitempty,min=1" form:"page"`
PageSize int `validate:"omitempty,min=1" form:"page_size"`
OrderCond string `validate:"omitempty,oneof=newest active frequent score unanswered" form:"order"`
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`
LoginUserID string `json:"-"`
LoginUserRole string `form:"login_user_role"`
}

type PersonalCollectionPageReq struct {
Page int `validate:"omitempty,min=1" form:"page"`
PageSize int `validate:"omitempty,min=1" form:"page_size"`
UserID string `json:"-"`
Page int `validate:"omitempty,min=1" form:"page"`
PageSize int `validate:"omitempty,min=1" form:"page_size"`
UserID string `json:"-"`
LoginUserRole string `form:"login_user_role"`
}
4 changes: 4 additions & 0 deletions internal/schema/rank_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ type GetRankPersonalWithPageReq struct {
PageSize int `validate:"omitempty,min=1" form:"page_size"`
// username
Username string `validate:"omitempty,gt=0,lte=100" form:"username"`

LoginUserRole string `form:"login_user_role"`

LoginUserID string `json:"-"`
// user id
UserID string `json:"-"`
}
Expand Down
4 changes: 4 additions & 0 deletions internal/schema/vote_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ type GetVoteWithPageReq struct {
Page int `validate:"omitempty,min=1" form:"page"`
// page size
PageSize int `validate:"omitempty,min=1" form:"page_size"`

LoginUserRole string `form:"login_user_role"`

LoginUserID string `json:"-"`
// user id
UserID string `json:"-"`
}
Expand Down
30 changes: 26 additions & 4 deletions internal/service/comment/comment_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ import (
"github.com/apache/incubator-answer/internal/base/reason"
"github.com/apache/incubator-answer/internal/entity"
"github.com/apache/incubator-answer/internal/schema"
// "github.com/apache/incubator-answer/internal/service"
answercommon "github.com/apache/incubator-answer/internal/service/answer_common"
"github.com/apache/incubator-answer/internal/service/activity_common"
"github.com/apache/incubator-answer/internal/service/activity_queue"
"github.com/apache/incubator-answer/internal/service/comment_common"
questioncommon "github.com/apache/incubator-answer/internal/service/question_common"
"github.com/apache/incubator-answer/internal/service/export"
"github.com/apache/incubator-answer/internal/service/notice_queue"
"github.com/apache/incubator-answer/internal/service/object_info"
Expand Down Expand Up @@ -77,7 +80,9 @@ func (c *CommentQuery) GetOrderBy() string {
// CommentService user service
type CommentService struct {
commentRepo CommentRepo
commentCommonRepo comment_common.CommentCommonRepo
commentCommonRepo comment_common.CommentCommonRepo
questionCommon *questioncommon.QuestionCommon
answerRepo answercommon.AnswerRepo
userCommon *usercommon.UserCommon
voteCommon activity_common.VoteRepo
objectInfoService *object_info.ObjService
Expand All @@ -92,6 +97,8 @@ type CommentService struct {
func NewCommentService(
commentRepo CommentRepo,
commentCommonRepo comment_common.CommentCommonRepo,
questionCommon *questioncommon.QuestionCommon,
answerRepo answercommon.AnswerRepo,
userCommon *usercommon.UserCommon,
objectInfoService *object_info.ObjService,
voteCommon activity_common.VoteRepo,
Expand All @@ -104,6 +111,8 @@ func NewCommentService(
return &CommentService{
commentRepo: commentRepo,
commentCommonRepo: commentCommonRepo,
questionCommon: questionCommon,
answerRepo: answerRepo,
userCommon: userCommon,
voteCommon: voteCommon,
objectInfoService: objectInfoService,
Expand Down Expand Up @@ -447,17 +456,17 @@ func (cs *CommentService) GetCommentPersonalWithPage(ctx context.Context, req *s
if len(req.UserID) == 0 {
return nil, errors.BadRequest(reason.UserNotFound)
}

dto := &CommentQuery{
PageCond: pager.PageCond{Page: req.Page, PageSize: req.PageSize},
UserID: req.UserID,
QueryCond: "created_at",
}
commentList, total, err := cs.commentRepo.GetCommentPage(ctx, dto)
commentList, _, err := cs.commentRepo.GetCommentPage(ctx, dto)
if err != nil {
return nil, err
}
resp := make([]*schema.GetCommentPersonalWithPageResp, 0)
dbSearch := entity.AnswerSearch{}
for _, comment := range commentList {
commentResp := &schema.GetCommentPersonalWithPageResp{
CommentID: comment.ID,
Expand All @@ -470,6 +479,19 @@ func (cs *CommentService) GetCommentPersonalWithPage(ctx context.Context, req *s
if err != nil {
log.Error(err)
} else {
questionInfo, _, _ := cs.questionCommon.GetQuestionRepo().GetQuestion(ctx, objInfo.QuestionID)
isParticipant := questionInfo.UserID == req.LoginUserID
dbSearch.QuestionID = questionInfo.ID
answerOriginalList, _, _ := cs.answerRepo.SearchList(ctx, &dbSearch)
for _, answer := range answerOriginalList {
if answer.UserID == req.LoginUserID {
isParticipant = true
break
}
}
if req.LoginUserRole == "1" && questionInfo.Show == 2 && !isParticipant{
continue
}
commentResp.ObjectType = objInfo.ObjectType
commentResp.Title = objInfo.Title
commentResp.UrlTitle = htmltext.UrlTitle(objInfo.Title)
Expand All @@ -482,7 +504,7 @@ func (cs *CommentService) GetCommentPersonalWithPage(ctx context.Context, req *s
}
resp = append(resp, commentResp)
}
return pager.NewPageModel(total, resp), nil
return pager.NewPageModel(int64(len(resp)), resp), nil
}

func (cs *CommentService) notificationQuestionComment(ctx context.Context, questionUserID,
Expand Down
19 changes: 0 additions & 19 deletions internal/service/mock/siteinfo_repo_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions internal/service/question_common/question.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (qs *QuestionCommon) UpdatePostSetTime(ctx context.Context, questionID stri
func (qs *QuestionCommon) FindInfoByID(ctx context.Context, questionIDs []string, loginUserID string) (map[string]*schema.QuestionInfo, error) {
list := make(map[string]*schema.QuestionInfo)
questionList, err := qs.questionRepo.FindByID(ctx, questionIDs)

if err != nil {
return list, err
}
Expand Down Expand Up @@ -651,3 +652,7 @@ func (qs *QuestionCommon) ShowFormatWithTag(ctx context.Context, data *entity.Qu
info.Tags = Tags
return info
}

func (qc *QuestionCommon) GetQuestionRepo() QuestionRepo {
return qc.questionRepo
}
Loading

0 comments on commit 66f2ef8

Please sign in to comment.