mirror of https://gitee.com/answerdev/answer.git
Merge branch 'feat/0.5.0/timeline_ai' into test
This commit is contained in:
commit
d40b6194fe
|
@ -182,8 +182,8 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
||||||
siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)
|
siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)
|
||||||
notificationRepo := notification.NewNotificationRepo(dataData)
|
notificationRepo := notification.NewNotificationRepo(dataData)
|
||||||
notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService)
|
notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService)
|
||||||
notificationService := notification2.NewNotificationService(dataData, notificationRepo, notificationCommon)
|
notificationService := notification2.NewNotificationService(dataData, notificationRepo, notificationCommon, revisionService)
|
||||||
notificationController := controller.NewNotificationController(notificationService)
|
notificationController := controller.NewNotificationController(notificationService, rankService)
|
||||||
dashboardController := controller.NewDashboardController(dashboardService)
|
dashboardController := controller.NewDashboardController(dashboardService)
|
||||||
uploadController := controller.NewUploadController(uploaderService)
|
uploadController := controller.NewUploadController(uploaderService)
|
||||||
activityCommon := activity_common2.NewActivityCommon(activityRepo)
|
activityCommon := activity_common2.NewActivityCommon(activityRepo)
|
||||||
|
|
|
@ -110,7 +110,7 @@ func (cc *CommentController) UpdateComment(ctx *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
can, err := cc.rankService.CheckOperationPermission(ctx, req.UserID, rank.CommentEditRank, req.UserID)
|
can, err := cc.rankService.CheckOperationPermission(ctx, req.UserID, rank.CommentEditRank, req.CommentID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handler.HandleResponse(ctx, err, nil)
|
handler.HandleResponse(ctx, err, nil)
|
||||||
return
|
return
|
||||||
|
|
|
@ -5,17 +5,25 @@ import (
|
||||||
"github.com/answerdev/answer/internal/base/middleware"
|
"github.com/answerdev/answer/internal/base/middleware"
|
||||||
"github.com/answerdev/answer/internal/schema"
|
"github.com/answerdev/answer/internal/schema"
|
||||||
"github.com/answerdev/answer/internal/service/notification"
|
"github.com/answerdev/answer/internal/service/notification"
|
||||||
|
"github.com/answerdev/answer/internal/service/rank"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NotificationController notification controller
|
// NotificationController notification controller
|
||||||
type NotificationController struct {
|
type NotificationController struct {
|
||||||
notificationService *notification.NotificationService
|
notificationService *notification.NotificationService
|
||||||
|
rankService *rank.RankService
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNotificationController new controller
|
// NewNotificationController new controller
|
||||||
func NewNotificationController(notificationService *notification.NotificationService) *NotificationController {
|
func NewNotificationController(
|
||||||
return &NotificationController{notificationService: notificationService}
|
notificationService *notification.NotificationService,
|
||||||
|
rankService *rank.RankService,
|
||||||
|
) *NotificationController {
|
||||||
|
return &NotificationController{
|
||||||
|
notificationService: notificationService,
|
||||||
|
rankService: rankService,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRedDot
|
// GetRedDot
|
||||||
|
@ -28,8 +36,26 @@ func NewNotificationController(notificationService *notification.NotificationSer
|
||||||
// @Success 200 {object} handler.RespBody
|
// @Success 200 {object} handler.RespBody
|
||||||
// @Router /answer/api/v1/notification/status [get]
|
// @Router /answer/api/v1/notification/status [get]
|
||||||
func (nc *NotificationController) GetRedDot(ctx *gin.Context) {
|
func (nc *NotificationController) GetRedDot(ctx *gin.Context) {
|
||||||
|
|
||||||
|
req := &schema.GetRedDot{}
|
||||||
|
|
||||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
userID := middleware.GetLoginUserIDFromContext(ctx)
|
||||||
RedDot, err := nc.notificationService.GetRedDot(ctx, userID)
|
req.UserID = userID
|
||||||
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
|
canList, err := nc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||||
|
rank.QuestionAuditRank,
|
||||||
|
rank.AnswerAuditRank,
|
||||||
|
rank.TagAuditRank,
|
||||||
|
}, "")
|
||||||
|
if err != nil {
|
||||||
|
handler.HandleResponse(ctx, err, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.CanReviewQuestion = canList[0]
|
||||||
|
req.CanReviewAnswer = canList[1]
|
||||||
|
req.CanReviewTag = canList[2]
|
||||||
|
|
||||||
|
RedDot, err := nc.notificationService.GetRedDot(ctx, req)
|
||||||
handler.HandleResponse(ctx, err, RedDot)
|
handler.HandleResponse(ctx, err, RedDot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,8 +74,21 @@ func (nc *NotificationController) ClearRedDot(ctx *gin.Context) {
|
||||||
if handler.BindAndCheck(ctx, req) {
|
if handler.BindAndCheck(ctx, req) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
||||||
RedDot, err := nc.notificationService.ClearRedDot(ctx, userID, req.TypeStr)
|
canList, err := nc.rankService.CheckOperationPermissions(ctx, req.UserID, []string{
|
||||||
|
rank.QuestionAuditRank,
|
||||||
|
rank.AnswerAuditRank,
|
||||||
|
rank.TagAuditRank,
|
||||||
|
}, "")
|
||||||
|
if err != nil {
|
||||||
|
handler.HandleResponse(ctx, err, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.CanReviewQuestion = canList[0]
|
||||||
|
req.CanReviewAnswer = canList[1]
|
||||||
|
req.CanReviewTag = canList[2]
|
||||||
|
|
||||||
|
RedDot, err := nc.notificationService.ClearRedDot(ctx, req)
|
||||||
handler.HandleResponse(ctx, err, RedDot)
|
handler.HandleResponse(ctx, err, RedDot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,13 @@ type NotificationContent struct {
|
||||||
UpdateTime int64 `json:"update_time"`
|
UpdateTime int64 `json:"update_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GetRedDot struct {
|
||||||
|
CanReviewQuestion bool `json:"-"`
|
||||||
|
CanReviewAnswer bool `json:"-"`
|
||||||
|
CanReviewTag bool `json:"-"`
|
||||||
|
UserID string `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
// NotificationMsg notification message
|
// NotificationMsg notification message
|
||||||
type NotificationMsg struct {
|
type NotificationMsg struct {
|
||||||
// trigger notification user id
|
// trigger notification user id
|
||||||
|
@ -57,6 +64,8 @@ type ObjectInfo struct {
|
||||||
type RedDot struct {
|
type RedDot struct {
|
||||||
Inbox int64 `json:"inbox"`
|
Inbox int64 `json:"inbox"`
|
||||||
Achievement int64 `json:"achievement"`
|
Achievement int64 `json:"achievement"`
|
||||||
|
Revision int64 `json:"revision"`
|
||||||
|
CanRevision bool `json:"can_revision"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotificationSearch struct {
|
type NotificationSearch struct {
|
||||||
|
@ -68,8 +77,11 @@ type NotificationSearch struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotificationClearRequest struct {
|
type NotificationClearRequest struct {
|
||||||
UserID string `json:"-"`
|
UserID string `json:"-"`
|
||||||
TypeStr string `json:"type" form:"type"` // inbox achievement
|
TypeStr string `json:"type" form:"type"` // inbox achievement
|
||||||
|
CanReviewQuestion bool `json:"-"`
|
||||||
|
CanReviewAnswer bool `json:"-"`
|
||||||
|
CanReviewTag bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NotificationClearIDRequest struct {
|
type NotificationClearIDRequest struct {
|
||||||
|
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"github.com/answerdev/answer/internal/base/translator"
|
"github.com/answerdev/answer/internal/base/translator"
|
||||||
"github.com/answerdev/answer/internal/schema"
|
"github.com/answerdev/answer/internal/schema"
|
||||||
notficationcommon "github.com/answerdev/answer/internal/service/notification_common"
|
notficationcommon "github.com/answerdev/answer/internal/service/notification_common"
|
||||||
|
"github.com/answerdev/answer/internal/service/revision_common"
|
||||||
|
"github.com/jinzhu/copier"
|
||||||
"github.com/segmentfault/pacman/i18n"
|
"github.com/segmentfault/pacman/i18n"
|
||||||
"github.com/segmentfault/pacman/log"
|
"github.com/segmentfault/pacman/log"
|
||||||
)
|
)
|
||||||
|
@ -20,24 +22,28 @@ type NotificationService struct {
|
||||||
data *data.Data
|
data *data.Data
|
||||||
notificationRepo notficationcommon.NotificationRepo
|
notificationRepo notficationcommon.NotificationRepo
|
||||||
notificationCommon *notficationcommon.NotificationCommon
|
notificationCommon *notficationcommon.NotificationCommon
|
||||||
|
revisionService *revision_common.RevisionService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNotificationService(
|
func NewNotificationService(
|
||||||
data *data.Data,
|
data *data.Data,
|
||||||
notificationRepo notficationcommon.NotificationRepo,
|
notificationRepo notficationcommon.NotificationRepo,
|
||||||
notificationCommon *notficationcommon.NotificationCommon,
|
notificationCommon *notficationcommon.NotificationCommon,
|
||||||
|
revisionService *revision_common.RevisionService,
|
||||||
|
|
||||||
) *NotificationService {
|
) *NotificationService {
|
||||||
return &NotificationService{
|
return &NotificationService{
|
||||||
data: data,
|
data: data,
|
||||||
notificationRepo: notificationRepo,
|
notificationRepo: notificationRepo,
|
||||||
notificationCommon: notificationCommon,
|
notificationCommon: notificationCommon,
|
||||||
|
revisionService: revisionService,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NotificationService) GetRedDot(ctx context.Context, userID string) (*schema.RedDot, error) {
|
func (ns *NotificationService) GetRedDot(ctx context.Context, req *schema.GetRedDot) (*schema.RedDot, error) {
|
||||||
redBot := &schema.RedDot{}
|
redBot := &schema.RedDot{}
|
||||||
inboxKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeInbox, userID)
|
inboxKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeInbox, req.UserID)
|
||||||
achievementKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeAchievement, userID)
|
achievementKey := fmt.Sprintf("answer_RedDot_%d_%s", schema.NotificationTypeAchievement, req.UserID)
|
||||||
inboxValue, err := ns.data.Cache.GetInt64(ctx, inboxKey)
|
inboxValue, err := ns.data.Cache.GetInt64(ctx, inboxKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
redBot.Inbox = 0
|
redBot.Inbox = 0
|
||||||
|
@ -50,19 +56,32 @@ func (ns *NotificationService) GetRedDot(ctx context.Context, userID string) (*s
|
||||||
} else {
|
} else {
|
||||||
redBot.Achievement = achievementValue
|
redBot.Achievement = achievementValue
|
||||||
}
|
}
|
||||||
|
revisionCount := &schema.RevisionSearch{}
|
||||||
|
_ = copier.Copy(revisionCount, req)
|
||||||
|
if req.CanReviewAnswer || req.CanReviewQuestion || req.CanReviewTag {
|
||||||
|
redBot.CanRevision = true
|
||||||
|
revisionCountNum, err := ns.revisionService.GetUnreviewedRevisionCount(ctx, revisionCount)
|
||||||
|
if err != nil {
|
||||||
|
return redBot, err
|
||||||
|
}
|
||||||
|
redBot.Revision = revisionCountNum
|
||||||
|
}
|
||||||
|
|
||||||
return redBot, nil
|
return redBot, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NotificationService) ClearRedDot(ctx context.Context, userID string, botTypeStr string) (*schema.RedDot, error) {
|
func (ns *NotificationService) ClearRedDot(ctx context.Context, req *schema.NotificationClearRequest) (*schema.RedDot, error) {
|
||||||
botType, ok := schema.NotificationType[botTypeStr]
|
botType, ok := schema.NotificationType[req.TypeStr]
|
||||||
if ok {
|
if ok {
|
||||||
key := fmt.Sprintf("answer_RedDot_%d_%s", botType, userID)
|
key := fmt.Sprintf("answer_RedDot_%d_%s", botType, req.UserID)
|
||||||
err := ns.data.Cache.Del(ctx, key)
|
err := ns.data.Cache.Del(ctx, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("ClearRedDot del cache error", err.Error())
|
log.Error("ClearRedDot del cache error", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ns.GetRedDot(ctx, userID)
|
getRedDotreq := &schema.GetRedDot{}
|
||||||
|
_ = copier.Copy(getRedDotreq, req)
|
||||||
|
return ns.GetRedDot(ctx, getRedDotreq)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *NotificationService) ClearUnRead(ctx context.Context, userID string, botTypeStr string) error {
|
func (ns *NotificationService) ClearUnRead(ctx context.Context, userID string, botTypeStr string) error {
|
||||||
|
|
|
@ -38,6 +38,7 @@ func GetCommentPermission(ctx context.Context, userID string, creatorUserID stri
|
||||||
// GetTagPermission get tag permission
|
// GetTagPermission get tag permission
|
||||||
func GetTagPermission(ctx context.Context, canEdit, canDelete bool) (
|
func GetTagPermission(ctx context.Context, canEdit, canDelete bool) (
|
||||||
actions []*schema.PermissionMemberAction) {
|
actions []*schema.PermissionMemberAction) {
|
||||||
|
actions = make([]*schema.PermissionMemberAction, 0)
|
||||||
if canEdit {
|
if canEdit {
|
||||||
actions = append(actions, &schema.PermissionMemberAction{
|
actions = append(actions, &schema.PermissionMemberAction{
|
||||||
Action: "edit",
|
Action: "edit",
|
||||||
|
|
|
@ -27,6 +27,14 @@ func NewRevisionService(revisionRepo revision.RevisionRepo, userRepo usercommon.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rs *RevisionService) GetUnreviewedRevisionCount(ctx context.Context, req *schema.RevisionSearch) (count int64, err error) {
|
||||||
|
search := &entity.RevisionSearch{}
|
||||||
|
search.Page = 1
|
||||||
|
_ = copier.Copy(search, req)
|
||||||
|
_, count, err = rs.revisionRepo.SearchUnreviewedList(ctx, search)
|
||||||
|
return count, err
|
||||||
|
}
|
||||||
|
|
||||||
// AddRevision add revision
|
// AddRevision add revision
|
||||||
//
|
//
|
||||||
// autoUpdateRevisionID bool : if autoUpdateRevisionID is true , the object.revision_id will be updated,
|
// autoUpdateRevisionID bool : if autoUpdateRevisionID is true , the object.revision_id will be updated,
|
||||||
|
|
Loading…
Reference in New Issue