mirror of https://gitee.com/answerdev/answer.git
update name modification
This commit is contained in:
parent
f7931433d2
commit
bcfeef1490
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/base/translator"
|
||||
"github.com/answerdev/answer/internal/controller"
|
||||
"github.com/answerdev/answer/internal/controller/template_render"
|
||||
"github.com/answerdev/answer/internal/controller_backyard"
|
||||
"github.com/answerdev/answer/internal/controller_admin"
|
||||
"github.com/answerdev/answer/internal/repo"
|
||||
"github.com/answerdev/answer/internal/router"
|
||||
"github.com/answerdev/answer/internal/service"
|
||||
|
@ -38,7 +38,7 @@ func initApplication(
|
|||
server.ProviderSetServer,
|
||||
router.ProviderSetRouter,
|
||||
controller.ProviderSetController,
|
||||
controller_backyard.ProviderSetController,
|
||||
controller_admin.ProviderSetController,
|
||||
templaterender.ProviderSetTemplateRenderController,
|
||||
service.ProviderSetService,
|
||||
cron.ProviderSetService,
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/base/translator"
|
||||
"github.com/answerdev/answer/internal/controller"
|
||||
"github.com/answerdev/answer/internal/controller/template_render"
|
||||
"github.com/answerdev/answer/internal/controller_backyard"
|
||||
"github.com/answerdev/answer/internal/controller_admin"
|
||||
"github.com/answerdev/answer/internal/repo/activity"
|
||||
"github.com/answerdev/answer/internal/repo/activity_common"
|
||||
"github.com/answerdev/answer/internal/repo/answer"
|
||||
|
@ -61,8 +61,8 @@ import (
|
|||
rank2 "github.com/answerdev/answer/internal/service/rank"
|
||||
reason2 "github.com/answerdev/answer/internal/service/reason"
|
||||
report2 "github.com/answerdev/answer/internal/service/report"
|
||||
"github.com/answerdev/answer/internal/service/report_backyard"
|
||||
"github.com/answerdev/answer/internal/service/report_handle_backyard"
|
||||
"github.com/answerdev/answer/internal/service/report_admin"
|
||||
"github.com/answerdev/answer/internal/service/report_handle_admin"
|
||||
"github.com/answerdev/answer/internal/service/revision_common"
|
||||
role2 "github.com/answerdev/answer/internal/service/role"
|
||||
"github.com/answerdev/answer/internal/service/search_parser"
|
||||
|
@ -72,7 +72,7 @@ import (
|
|||
tag2 "github.com/answerdev/answer/internal/service/tag"
|
||||
tag_common2 "github.com/answerdev/answer/internal/service/tag_common"
|
||||
"github.com/answerdev/answer/internal/service/uploader"
|
||||
"github.com/answerdev/answer/internal/service/user_backyard"
|
||||
"github.com/answerdev/answer/internal/service/user_admin"
|
||||
"github.com/answerdev/answer/internal/service/user_common"
|
||||
"github.com/segmentfault/pacman"
|
||||
"github.com/segmentfault/pacman/log"
|
||||
|
@ -177,18 +177,18 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
|||
revisionController := controller.NewRevisionController(serviceRevisionService, rankService)
|
||||
rankController := controller.NewRankController(rankService)
|
||||
commonRepo := common.NewCommonRepo(dataData, uniqueIDRepo)
|
||||
reportHandle := report_handle_backyard.NewReportHandle(questionCommon, commentRepo, configRepo)
|
||||
reportBackyardService := report_backyard.NewReportBackyardService(reportRepo, userCommon, commonRepo, answerRepo, questionRepo, commentCommonRepo, reportHandle, configRepo)
|
||||
controller_backyardReportController := controller_backyard.NewReportController(reportBackyardService)
|
||||
userBackyardRepo := user.NewUserBackyardRepo(dataData, authRepo)
|
||||
userBackyardService := user_backyard.NewUserBackyardService(userBackyardRepo, userRoleRelService, authService, userCommon)
|
||||
userBackyardController := controller_backyard.NewUserBackyardController(userBackyardService)
|
||||
reportHandle := report_handle_admin.NewReportHandle(questionCommon, commentRepo, configRepo)
|
||||
reportAdminService := report_admin.NewReportAdminService(reportRepo, userCommon, commonRepo, answerRepo, questionRepo, commentCommonRepo, reportHandle, configRepo)
|
||||
controller_adminReportController := controller_admin.NewReportController(reportAdminService)
|
||||
userAdminRepo := user.NewUserAdminRepo(dataData, authRepo)
|
||||
userAdminService := user_admin.NewUserAdminService(userAdminRepo, userRoleRelService, authService, userCommon)
|
||||
userAdminController := controller_admin.NewUserAdminController(userAdminService)
|
||||
reasonRepo := reason.NewReasonRepo(configRepo)
|
||||
reasonService := reason2.NewReasonService(reasonRepo)
|
||||
reasonController := controller.NewReasonController(reasonService)
|
||||
themeController := controller_backyard.NewThemeController()
|
||||
themeController := controller_admin.NewThemeController()
|
||||
siteInfoService := siteinfo.NewSiteInfoService(siteInfoRepo, siteInfoCommonService, emailService, tagCommonService)
|
||||
siteInfoController := controller_backyard.NewSiteInfoController(siteInfoService)
|
||||
siteInfoController := controller_admin.NewSiteInfoController(siteInfoService)
|
||||
siteinfoController := controller.NewSiteinfoController(siteInfoCommonService)
|
||||
notificationRepo := notification.NewNotificationRepo(dataData)
|
||||
notificationCommon := notificationcommon.NewNotificationCommon(dataData, notificationRepo, userCommon, activityRepo, followRepo, objService)
|
||||
|
@ -201,8 +201,8 @@ func initApplication(debug bool, serverConf *conf.Server, dbConf *data.Database,
|
|||
commentCommonService := comment_common.NewCommentCommonService(commentCommonRepo)
|
||||
activityService := activity2.NewActivityService(activityActivityRepo, userCommon, activityCommon, tagCommonService, objService, commentCommonService, revisionService, metaService)
|
||||
activityController := controller.NewActivityController(activityCommon, activityService)
|
||||
roleController := controller_backyard.NewRoleController(roleService)
|
||||
answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_backyardReportController, userBackyardController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController, uploadController, activityController, roleController)
|
||||
roleController := controller_admin.NewRoleController(roleService)
|
||||
answerAPIRouter := router.NewAnswerAPIRouter(langController, userController, commentController, reportController, voteController, tagController, followController, collectionController, questionController, answerController, searchController, revisionController, rankController, controller_adminReportController, userAdminController, reasonController, themeController, siteInfoController, siteinfoController, notificationController, dashboardController, uploadController, activityController, roleController)
|
||||
swaggerRouter := router.NewSwaggerRouter(swaggerConf)
|
||||
uiRouter := router.NewUIRouter(siteinfoController, siteInfoCommonService)
|
||||
authUserMiddleware := middleware.NewAuthUserMiddleware(authService, siteInfoCommonService)
|
||||
|
|
|
@ -33,7 +33,7 @@ const docTemplate = `{
|
|||
"tags": [
|
||||
"admin"
|
||||
],
|
||||
"summary": "CmsSearchList",
|
||||
"summary": "AdminSearchAnswerList",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
|
@ -184,7 +184,7 @@ const docTemplate = `{
|
|||
"tags": [
|
||||
"admin"
|
||||
],
|
||||
"summary": "CmsSearchList",
|
||||
"summary": "AdminSearchList",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
"tags": [
|
||||
"admin"
|
||||
],
|
||||
"summary": "CmsSearchList",
|
||||
"summary": "AdminSearchAnswerList",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
|
@ -172,7 +172,7 @@
|
|||
"tags": [
|
||||
"admin"
|
||||
],
|
||||
"summary": "CmsSearchList",
|
||||
"summary": "AdminSearchList",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
|
|
|
@ -1924,7 +1924,7 @@ paths:
|
|||
$ref: '#/definitions/handler.RespBody'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: CmsSearchList
|
||||
summary: AdminSearchAnswerList
|
||||
tags:
|
||||
- admin
|
||||
/answer/admin/api/answer/status:
|
||||
|
@ -2016,7 +2016,7 @@ paths:
|
|||
$ref: '#/definitions/handler.RespBody'
|
||||
security:
|
||||
- ApiKeyAuth: []
|
||||
summary: CmsSearchList
|
||||
summary: AdminSearchList
|
||||
tags:
|
||||
- admin
|
||||
/answer/admin/api/question/status:
|
||||
|
|
|
@ -113,7 +113,7 @@ func (am *AuthUserMiddleware) MustAuth() gin.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func (am *AuthUserMiddleware) CmsAuth() gin.HandlerFunc {
|
||||
func (am *AuthUserMiddleware) AdminAuth() gin.HandlerFunc {
|
||||
return func(ctx *gin.Context) {
|
||||
token := ExtractToken(ctx)
|
||||
if len(token) == 0 {
|
||||
|
@ -121,7 +121,7 @@ func (am *AuthUserMiddleware) CmsAuth() gin.HandlerFunc {
|
|||
ctx.Abort()
|
||||
return
|
||||
}
|
||||
userInfo, err := am.authService.GetCmsUserCacheInfo(ctx, token)
|
||||
userInfo, err := am.authService.GetAdminUserCacheInfo(ctx, token)
|
||||
if err != nil {
|
||||
handler.HandleResponse(ctx, errors.Unauthorized(reason.UnauthorizedError), nil)
|
||||
ctx.Abort()
|
||||
|
|
|
@ -57,9 +57,9 @@ func NewHTTPServer(debug bool,
|
|||
authV1.Use(authUserMiddleware.MustAuth())
|
||||
answerRouter.RegisterAnswerAPIRouter(authV1)
|
||||
|
||||
cmsauthV1 := r.Group("/answer/admin/api")
|
||||
cmsauthV1.Use(authUserMiddleware.CmsAuth())
|
||||
answerRouter.RegisterAnswerCmsAPIRouter(cmsauthV1)
|
||||
adminauthV1 := r.Group("/answer/admin/api")
|
||||
adminauthV1.Use(authUserMiddleware.AdminAuth())
|
||||
answerRouter.RegisterAnswerAdminAPIRouter(adminauthV1)
|
||||
|
||||
templateRouter.RegisterTemplateRouter(rootGroup)
|
||||
return r
|
||||
|
|
|
@ -480,8 +480,8 @@ func (qc *QuestionController) UserCollectionList(ctx *gin.Context) {
|
|||
})
|
||||
}
|
||||
|
||||
// CmsSearchList godoc
|
||||
// @Summary CmsSearchList
|
||||
// AdminSearchList godoc
|
||||
// @Summary AdminSearchList
|
||||
// @Description Status:[available,closed,deleted]
|
||||
// @Tags admin
|
||||
// @Accept json
|
||||
|
@ -493,21 +493,21 @@ func (qc *QuestionController) UserCollectionList(ctx *gin.Context) {
|
|||
// @Param query query string false "question id or title"
|
||||
// @Success 200 {object} handler.RespBody
|
||||
// @Router /answer/admin/api/question/page [get]
|
||||
func (qc *QuestionController) CmsSearchList(ctx *gin.Context) {
|
||||
req := &schema.CmsQuestionSearch{}
|
||||
func (qc *QuestionController) AdminSearchList(ctx *gin.Context) {
|
||||
req := &schema.AdminQuestionSearch{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
}
|
||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
||||
questionList, count, err := qc.questionService.CmsSearchList(ctx, req, userID)
|
||||
questionList, count, err := qc.questionService.AdminSearchList(ctx, req, userID)
|
||||
handler.HandleResponse(ctx, err, gin.H{
|
||||
"list": questionList,
|
||||
"count": count,
|
||||
})
|
||||
}
|
||||
|
||||
// CmsSearchAnswerList godoc
|
||||
// @Summary CmsSearchList
|
||||
// AdminSearchAnswerList godoc
|
||||
// @Summary AdminSearchAnswerList
|
||||
// @Description Status:[available,deleted]
|
||||
// @Tags admin
|
||||
// @Accept json
|
||||
|
@ -520,13 +520,13 @@ func (qc *QuestionController) CmsSearchList(ctx *gin.Context) {
|
|||
// @Param question_id query string false "question id"
|
||||
// @Success 200 {object} handler.RespBody
|
||||
// @Router /answer/admin/api/answer/page [get]
|
||||
func (qc *QuestionController) CmsSearchAnswerList(ctx *gin.Context) {
|
||||
req := &entity.CmsAnswerSearch{}
|
||||
func (qc *QuestionController) AdminSearchAnswerList(ctx *gin.Context) {
|
||||
req := &entity.AdminAnswerSearch{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
}
|
||||
userID := middleware.GetLoginUserIDFromContext(ctx)
|
||||
questionList, count, err := qc.questionService.CmsSearchAnswerList(ctx, req, userID)
|
||||
questionList, count, err := qc.questionService.AdminSearchAnswerList(ctx, req, userID)
|
||||
handler.HandleResponse(ctx, err, gin.H{
|
||||
"list": questionList,
|
||||
"count": count,
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
package controller_backyard
|
||||
package controller_admin
|
||||
|
||||
import "github.com/google/wire"
|
||||
|
||||
// ProviderSetController is controller providers.
|
||||
var ProviderSetController = wire.NewSet(
|
||||
NewReportController,
|
||||
NewUserBackyardController,
|
||||
NewUserAdminController,
|
||||
NewThemeController,
|
||||
NewSiteInfoController,
|
||||
NewRoleController,
|
|
@ -1,20 +1,20 @@
|
|||
package controller_backyard
|
||||
package controller_admin
|
||||
|
||||
import (
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
||||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/internal/service/report_backyard"
|
||||
"github.com/answerdev/answer/internal/service/report_admin"
|
||||
"github.com/answerdev/answer/pkg/converter"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// ReportController report controller
|
||||
type ReportController struct {
|
||||
reportService *report_backyard.ReportBackyardService
|
||||
reportService *report_admin.ReportAdminService
|
||||
}
|
||||
|
||||
// NewReportController new controller
|
||||
func NewReportController(reportService *report_backyard.ReportBackyardService) *ReportController {
|
||||
func NewReportController(reportService *report_admin.ReportAdminService) *ReportController {
|
||||
return &ReportController{reportService: reportService}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package controller_backyard
|
||||
package controller_admin
|
||||
|
||||
import (
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
|
@ -1,4 +1,4 @@
|
|||
package controller_backyard
|
||||
package controller_admin
|
||||
|
||||
import (
|
||||
"net/http"
|
|
@ -1,4 +1,4 @@
|
|||
package controller_backyard
|
||||
package controller_admin
|
||||
|
||||
import (
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
|
@ -1,21 +1,21 @@
|
|||
package controller_backyard
|
||||
package controller_admin
|
||||
|
||||
import (
|
||||
"github.com/answerdev/answer/internal/base/handler"
|
||||
"github.com/answerdev/answer/internal/base/middleware"
|
||||
"github.com/answerdev/answer/internal/schema"
|
||||
"github.com/answerdev/answer/internal/service/user_backyard"
|
||||
"github.com/answerdev/answer/internal/service/user_admin"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// UserBackyardController user controller
|
||||
type UserBackyardController struct {
|
||||
userService *user_backyard.UserBackyardService
|
||||
// UserAdminController user controller
|
||||
type UserAdminController struct {
|
||||
userService *user_admin.UserAdminService
|
||||
}
|
||||
|
||||
// NewUserBackyardController new controller
|
||||
func NewUserBackyardController(userService *user_backyard.UserBackyardService) *UserBackyardController {
|
||||
return &UserBackyardController{userService: userService}
|
||||
// NewUserAdminController new controller
|
||||
func NewUserAdminController(userService *user_admin.UserAdminService) *UserAdminController {
|
||||
return &UserAdminController{userService: userService}
|
||||
}
|
||||
|
||||
// UpdateUserStatus update user
|
||||
|
@ -28,7 +28,7 @@ func NewUserBackyardController(userService *user_backyard.UserBackyardService) *
|
|||
// @Param data body schema.UpdateUserStatusReq true "user"
|
||||
// @Success 200 {object} handler.RespBody
|
||||
// @Router /answer/admin/api/user/status [put]
|
||||
func (uc *UserBackyardController) UpdateUserStatus(ctx *gin.Context) {
|
||||
func (uc *UserAdminController) UpdateUserStatus(ctx *gin.Context) {
|
||||
req := &schema.UpdateUserStatusReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
|
@ -48,7 +48,7 @@ func (uc *UserBackyardController) UpdateUserStatus(ctx *gin.Context) {
|
|||
// @Param data body schema.UpdateUserRoleReq true "user"
|
||||
// @Success 200 {object} handler.RespBody
|
||||
// @Router /answer/admin/api/user/role [put]
|
||||
func (uc *UserBackyardController) UpdateUserRole(ctx *gin.Context) {
|
||||
func (uc *UserAdminController) UpdateUserRole(ctx *gin.Context) {
|
||||
req := &schema.UpdateUserRoleReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
|
@ -70,7 +70,7 @@ func (uc *UserBackyardController) UpdateUserRole(ctx *gin.Context) {
|
|||
// @Param data body schema.AddUserReq true "user"
|
||||
// @Success 200 {object} handler.RespBody
|
||||
// @Router /answer/admin/api/user [post]
|
||||
func (uc *UserBackyardController) AddUser(ctx *gin.Context) {
|
||||
func (uc *UserAdminController) AddUser(ctx *gin.Context) {
|
||||
req := &schema.AddUserReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
|
@ -92,7 +92,7 @@ func (uc *UserBackyardController) AddUser(ctx *gin.Context) {
|
|||
// @Param data body schema.UpdateUserPasswordReq true "user"
|
||||
// @Success 200 {object} handler.RespBody
|
||||
// @Router /answer/admin/api/user/password [put]
|
||||
func (uc *UserBackyardController) UpdateUserPassword(ctx *gin.Context) {
|
||||
func (uc *UserAdminController) UpdateUserPassword(ctx *gin.Context) {
|
||||
req := &schema.UpdateUserPasswordReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
||||
|
@ -117,7 +117,7 @@ func (uc *UserBackyardController) UpdateUserPassword(ctx *gin.Context) {
|
|||
// @Param status query string false "user status" Enums(suspended, deleted, inactive)
|
||||
// @Success 200 {object} handler.RespBody{data=pager.PageModel{records=[]schema.GetUserPageResp}}
|
||||
// @Router /answer/admin/api/users/page [get]
|
||||
func (uc *UserBackyardController) GetUserPage(ctx *gin.Context) {
|
||||
func (uc *UserAdminController) GetUserPage(ctx *gin.Context) {
|
||||
req := &schema.GetUserPageReq{}
|
||||
if handler.BindAndCheck(ctx, req) {
|
||||
return
|
|
@ -11,7 +11,7 @@ const (
|
|||
AnswerStatusDeleted = 10
|
||||
)
|
||||
|
||||
var CmsAnswerSearchStatus = map[string]int{
|
||||
var AdminAnswerSearchStatus = map[string]int{
|
||||
"available": AnswerStatusAvailable,
|
||||
"deleted": AnswerStatusDeleted,
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ type AnswerSearch struct {
|
|||
PageSize int `json:"page_size" form:"page_size"` // Search page size
|
||||
}
|
||||
|
||||
type CmsAnswerSearch struct {
|
||||
type AdminAnswerSearch struct {
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
PageSize int `json:"page_size" form:"page_size"` // Search page size
|
||||
Status int `json:"-" form:"-"`
|
||||
|
|
|
@ -10,13 +10,13 @@ const (
|
|||
QuestionStatusDeleted = 10
|
||||
)
|
||||
|
||||
var CmsQuestionSearchStatus = map[string]int{
|
||||
var AdminQuestionSearchStatus = map[string]int{
|
||||
"available": QuestionStatusAvailable,
|
||||
"closed": QuestionStatusClosed,
|
||||
"deleted": QuestionStatusDeleted,
|
||||
}
|
||||
|
||||
var CmsQuestionSearchStatusIntToString = map[int]string{
|
||||
var AdminQuestionSearchStatusIntToString = map[int]string{
|
||||
QuestionStatusAvailable: "available",
|
||||
QuestionStatusClosed: "closed",
|
||||
QuestionStatusDeleted: "deleted",
|
||||
|
|
|
@ -216,7 +216,7 @@ func (ar *answerRepo) SearchList(ctx context.Context, search *entity.AnswerSearc
|
|||
return rows, count, nil
|
||||
}
|
||||
|
||||
func (ar *answerRepo) CmsSearchList(ctx context.Context, search *entity.CmsAnswerSearch) ([]*entity.Answer, int64, error) {
|
||||
func (ar *answerRepo) AdminSearchList(ctx context.Context, search *entity.AdminAnswerSearch) ([]*entity.Answer, int64, error) {
|
||||
var (
|
||||
count int64
|
||||
err error
|
||||
|
|
|
@ -95,8 +95,8 @@ func (ar *authRepo) RemoveUserStatus(ctx context.Context, userID string) (err er
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetBackyardUserCacheInfo get backyard user cache info
|
||||
func (ar *authRepo) GetBackyardUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error) {
|
||||
// GetAdminUserCacheInfo get admin user cache info
|
||||
func (ar *authRepo) GetAdminUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error) {
|
||||
userInfoCache, err := ar.data.Cache.GetString(ctx, constant.AdminTokenCacheKey+accessToken)
|
||||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
|
@ -110,8 +110,8 @@ func (ar *authRepo) GetBackyardUserCacheInfo(ctx context.Context, accessToken st
|
|||
return userInfo, nil
|
||||
}
|
||||
|
||||
// SetBackyardUserCacheInfo set backyard user cache info
|
||||
func (ar *authRepo) SetBackyardUserCacheInfo(ctx context.Context, accessToken string, userInfo *entity.UserCacheInfo) (err error) {
|
||||
// SetAdminUserCacheInfo set admin user cache info
|
||||
func (ar *authRepo) SetAdminUserCacheInfo(ctx context.Context, accessToken string, userInfo *entity.UserCacheInfo) (err error) {
|
||||
userInfoCache, err := json.Marshal(userInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -125,8 +125,8 @@ func (ar *authRepo) SetBackyardUserCacheInfo(ctx context.Context, accessToken st
|
|||
return nil
|
||||
}
|
||||
|
||||
// RemoveBackyardUserCacheInfo remove backyard user cache info
|
||||
func (ar *authRepo) RemoveBackyardUserCacheInfo(ctx context.Context, accessToken string) (err error) {
|
||||
// RemoveAdminUserCacheInfo remove admin user cache info
|
||||
func (ar *authRepo) RemoveAdminUserCacheInfo(ctx context.Context, accessToken string) (err error) {
|
||||
err = ar.data.Cache.Del(ctx, constant.AdminTokenCacheKey+accessToken)
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
|
|
|
@ -44,7 +44,7 @@ var ProviderSetRepo = wire.NewSet(
|
|||
activity_common.NewVoteRepo,
|
||||
config.NewConfigRepo,
|
||||
user.NewUserRepo,
|
||||
user.NewUserBackyardRepo,
|
||||
user.NewUserAdminRepo,
|
||||
rank.NewUserRankRepo,
|
||||
question.NewQuestionRepo,
|
||||
answer.NewAnswerRepo,
|
||||
|
|
|
@ -271,7 +271,7 @@ func (qr *questionRepo) SearchList(ctx context.Context, search *schema.QuestionS
|
|||
return rows, count, nil
|
||||
}
|
||||
|
||||
func (qr *questionRepo) CmsSearchList(ctx context.Context, search *schema.CmsQuestionSearch) ([]*entity.Question, int64, error) {
|
||||
func (qr *questionRepo) AdminSearchList(ctx context.Context, search *schema.AdminQuestionSearch) ([]*entity.Question, int64, error) {
|
||||
var (
|
||||
count int64
|
||||
err error
|
||||
|
|
|
@ -61,26 +61,26 @@ func Test_authRepo_RemoveUserStatus(t *testing.T) {
|
|||
assert.Error(t, err)
|
||||
}
|
||||
|
||||
func Test_authRepo_SetBackyardUserCacheInfo(t *testing.T) {
|
||||
func Test_authRepo_SetAdminUserCacheInfo(t *testing.T) {
|
||||
authRepo := auth.NewAuthRepo(testDataSource)
|
||||
|
||||
err := authRepo.SetBackyardUserCacheInfo(context.TODO(), token, &entity.UserCacheInfo{UserID: userID})
|
||||
err := authRepo.SetAdminUserCacheInfo(context.TODO(), token, &entity.UserCacheInfo{UserID: userID})
|
||||
assert.NoError(t, err)
|
||||
|
||||
cacheInfo, err := authRepo.GetBackyardUserCacheInfo(context.TODO(), token)
|
||||
cacheInfo, err := authRepo.GetAdminUserCacheInfo(context.TODO(), token)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, userID, cacheInfo.UserID)
|
||||
}
|
||||
|
||||
func Test_authRepo_RemoveBackyardUserCacheInfo(t *testing.T) {
|
||||
func Test_authRepo_RemoveAdminUserCacheInfo(t *testing.T) {
|
||||
authRepo := auth.NewAuthRepo(testDataSource)
|
||||
|
||||
err := authRepo.SetBackyardUserCacheInfo(context.TODO(), token, &entity.UserCacheInfo{UserID: userID})
|
||||
err := authRepo.SetAdminUserCacheInfo(context.TODO(), token, &entity.UserCacheInfo{UserID: userID})
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = authRepo.RemoveBackyardUserCacheInfo(context.TODO(), token)
|
||||
err = authRepo.RemoveAdminUserCacheInfo(context.TODO(), token)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = authRepo.GetBackyardUserCacheInfo(context.TODO(), token)
|
||||
_, err = authRepo.GetAdminUserCacheInfo(context.TODO(), token)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
|
|
@ -10,43 +10,43 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_userBackyardRepo_GetUserInfo(t *testing.T) {
|
||||
userBackyardRepo := user.NewUserBackyardRepo(testDataSource, auth.NewAuthRepo(testDataSource))
|
||||
got, exist, err := userBackyardRepo.GetUserInfo(context.TODO(), "1")
|
||||
func Test_userAdminRepo_GetUserInfo(t *testing.T) {
|
||||
userAdminRepo := user.NewUserAdminRepo(testDataSource, auth.NewAuthRepo(testDataSource))
|
||||
got, exist, err := userAdminRepo.GetUserInfo(context.TODO(), "1")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, exist)
|
||||
assert.Equal(t, "1", got.ID)
|
||||
}
|
||||
|
||||
func Test_userBackyardRepo_GetUserPage(t *testing.T) {
|
||||
userBackyardRepo := user.NewUserBackyardRepo(testDataSource, auth.NewAuthRepo(testDataSource))
|
||||
got, total, err := userBackyardRepo.GetUserPage(context.TODO(), 1, 1, &entity.User{Username: "admin"}, "", false)
|
||||
func Test_userAdminRepo_GetUserPage(t *testing.T) {
|
||||
userAdminRepo := user.NewUserAdminRepo(testDataSource, auth.NewAuthRepo(testDataSource))
|
||||
got, total, err := userAdminRepo.GetUserPage(context.TODO(), 1, 1, &entity.User{Username: "admin"}, "", false)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, int64(1), total)
|
||||
assert.Equal(t, "1", got[0].ID)
|
||||
}
|
||||
|
||||
func Test_userBackyardRepo_UpdateUserStatus(t *testing.T) {
|
||||
userBackyardRepo := user.NewUserBackyardRepo(testDataSource, auth.NewAuthRepo(testDataSource))
|
||||
got, exist, err := userBackyardRepo.GetUserInfo(context.TODO(), "1")
|
||||
func Test_userAdminRepo_UpdateUserStatus(t *testing.T) {
|
||||
userAdminRepo := user.NewUserAdminRepo(testDataSource, auth.NewAuthRepo(testDataSource))
|
||||
got, exist, err := userAdminRepo.GetUserInfo(context.TODO(), "1")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, exist)
|
||||
assert.Equal(t, entity.UserStatusAvailable, got.Status)
|
||||
|
||||
err = userBackyardRepo.UpdateUserStatus(context.TODO(), "1", entity.UserStatusSuspended, entity.EmailStatusAvailable,
|
||||
err = userAdminRepo.UpdateUserStatus(context.TODO(), "1", entity.UserStatusSuspended, entity.EmailStatusAvailable,
|
||||
"admin@admin.com")
|
||||
assert.NoError(t, err)
|
||||
|
||||
got, exist, err = userBackyardRepo.GetUserInfo(context.TODO(), "1")
|
||||
got, exist, err = userAdminRepo.GetUserInfo(context.TODO(), "1")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, exist)
|
||||
assert.Equal(t, entity.UserStatusSuspended, got.Status)
|
||||
|
||||
err = userBackyardRepo.UpdateUserStatus(context.TODO(), "1", entity.UserStatusAvailable, entity.EmailStatusAvailable,
|
||||
err = userAdminRepo.UpdateUserStatus(context.TODO(), "1", entity.UserStatusAvailable, entity.EmailStatusAvailable,
|
||||
"admin@admin.com")
|
||||
assert.NoError(t, err)
|
||||
|
||||
got, exist, err = userBackyardRepo.GetUserInfo(context.TODO(), "1")
|
||||
got, exist, err = userAdminRepo.GetUserInfo(context.TODO(), "1")
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, exist)
|
||||
assert.Equal(t, entity.UserStatusAvailable, got.Status)
|
||||
|
|
|
@ -448,14 +448,14 @@ func (sr *searchRepo) parseResult(ctx context.Context, res []map[string][]byte)
|
|||
_ = copier.Copy(&tags, tagsEntity)
|
||||
switch objectKey {
|
||||
case "question":
|
||||
for k, v := range entity.CmsQuestionSearchStatus {
|
||||
for k, v := range entity.AdminQuestionSearchStatus {
|
||||
if v == converter.StringToInt(string(r["status"])) {
|
||||
status = k
|
||||
break
|
||||
}
|
||||
}
|
||||
case "answer":
|
||||
for k, v := range entity.CmsAnswerSearchStatus {
|
||||
for k, v := range entity.AdminAnswerSearchStatus {
|
||||
if v == converter.StringToInt(string(r["status"])) {
|
||||
status = k
|
||||
break
|
||||
|
|
|
@ -12,27 +12,27 @@ import (
|
|||
"github.com/answerdev/answer/internal/base/reason"
|
||||
"github.com/answerdev/answer/internal/entity"
|
||||
"github.com/answerdev/answer/internal/service/auth"
|
||||
"github.com/answerdev/answer/internal/service/user_backyard"
|
||||
"github.com/answerdev/answer/internal/service/user_admin"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
"github.com/segmentfault/pacman/log"
|
||||
)
|
||||
|
||||
// userBackyardRepo user repository
|
||||
type userBackyardRepo struct {
|
||||
// userAdminRepo user repository
|
||||
type userAdminRepo struct {
|
||||
data *data.Data
|
||||
authRepo auth.AuthRepo
|
||||
}
|
||||
|
||||
// NewUserBackyardRepo new repository
|
||||
func NewUserBackyardRepo(data *data.Data, authRepo auth.AuthRepo) user_backyard.UserBackyardRepo {
|
||||
return &userBackyardRepo{
|
||||
// NewUserAdminRepo new repository
|
||||
func NewUserAdminRepo(data *data.Data, authRepo auth.AuthRepo) user_admin.UserAdminRepo {
|
||||
return &userAdminRepo{
|
||||
data: data,
|
||||
authRepo: authRepo,
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateUserStatus update user status
|
||||
func (ur *userBackyardRepo) UpdateUserStatus(ctx context.Context, userID string, userStatus, mailStatus int,
|
||||
func (ur *userAdminRepo) UpdateUserStatus(ctx context.Context, userID string, userStatus, mailStatus int,
|
||||
email string,
|
||||
) (err error) {
|
||||
cond := &entity.User{Status: userStatus, MailStatus: mailStatus, EMail: email}
|
||||
|
@ -62,7 +62,7 @@ func (ur *userBackyardRepo) UpdateUserStatus(ctx context.Context, userID string,
|
|||
}
|
||||
|
||||
// AddUser add user
|
||||
func (ur *userBackyardRepo) AddUser(ctx context.Context, user *entity.User) (err error) {
|
||||
func (ur *userAdminRepo) AddUser(ctx context.Context, user *entity.User) (err error) {
|
||||
_, err = ur.data.DB.Insert(user)
|
||||
if err != nil {
|
||||
err = errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
|
@ -71,7 +71,7 @@ func (ur *userBackyardRepo) AddUser(ctx context.Context, user *entity.User) (err
|
|||
}
|
||||
|
||||
// UpdateUserPassword update user password
|
||||
func (ur *userBackyardRepo) UpdateUserPassword(ctx context.Context, userID string, password string) (err error) {
|
||||
func (ur *userAdminRepo) UpdateUserPassword(ctx context.Context, userID string, password string) (err error) {
|
||||
_, err = ur.data.DB.ID(userID).Update(&entity.User{Pass: password})
|
||||
if err != nil {
|
||||
return errors.InternalServer(reason.DatabaseError).WithError(err).WithStack()
|
||||
|
@ -80,7 +80,7 @@ func (ur *userBackyardRepo) UpdateUserPassword(ctx context.Context, userID strin
|
|||
}
|
||||
|
||||
// GetUserInfo get user info
|
||||
func (ur *userBackyardRepo) GetUserInfo(ctx context.Context, userID string) (user *entity.User, exist bool, err error) {
|
||||
func (ur *userAdminRepo) GetUserInfo(ctx context.Context, userID string) (user *entity.User, exist bool, err error) {
|
||||
user = &entity.User{}
|
||||
exist, err = ur.data.DB.ID(userID).Get(user)
|
||||
if err != nil {
|
||||
|
@ -90,7 +90,7 @@ func (ur *userBackyardRepo) GetUserInfo(ctx context.Context, userID string) (use
|
|||
}
|
||||
|
||||
// GetUserInfoByEmail get user info
|
||||
func (ur *userBackyardRepo) GetUserInfoByEmail(ctx context.Context, email string) (user *entity.User, exist bool, err error) {
|
||||
func (ur *userAdminRepo) GetUserInfoByEmail(ctx context.Context, email string) (user *entity.User, exist bool, err error) {
|
||||
userInfo := &entity.User{}
|
||||
exist, err = ur.data.DB.Where("e_mail = ?", email).
|
||||
Where("status != ?", entity.UserStatusDeleted).Get(userInfo)
|
||||
|
@ -101,7 +101,7 @@ func (ur *userBackyardRepo) GetUserInfoByEmail(ctx context.Context, email string
|
|||
}
|
||||
|
||||
// GetUserPage get user page
|
||||
func (ur *userBackyardRepo) GetUserPage(ctx context.Context, page, pageSize int, user *entity.User,
|
||||
func (ur *userAdminRepo) GetUserPage(ctx context.Context, page, pageSize int, user *entity.User,
|
||||
usernameOrDisplayName string, isStaff bool) (users []*entity.User, total int64, err error) {
|
||||
users = make([]*entity.User, 0)
|
||||
session := ur.data.DB.NewSession()
|
||||
|
|
|
@ -2,35 +2,35 @@ package router
|
|||
|
||||
import (
|
||||
"github.com/answerdev/answer/internal/controller"
|
||||
"github.com/answerdev/answer/internal/controller_backyard"
|
||||
"github.com/answerdev/answer/internal/controller_admin"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type AnswerAPIRouter struct {
|
||||
langController *controller.LangController
|
||||
userController *controller.UserController
|
||||
commentController *controller.CommentController
|
||||
reportController *controller.ReportController
|
||||
voteController *controller.VoteController
|
||||
tagController *controller.TagController
|
||||
followController *controller.FollowController
|
||||
collectionController *controller.CollectionController
|
||||
questionController *controller.QuestionController
|
||||
answerController *controller.AnswerController
|
||||
searchController *controller.SearchController
|
||||
revisionController *controller.RevisionController
|
||||
rankController *controller.RankController
|
||||
backyardReportController *controller_backyard.ReportController
|
||||
backyardUserController *controller_backyard.UserBackyardController
|
||||
reasonController *controller.ReasonController
|
||||
themeController *controller_backyard.ThemeController
|
||||
siteInfoController *controller_backyard.SiteInfoController
|
||||
siteinfoController *controller.SiteinfoController
|
||||
notificationController *controller.NotificationController
|
||||
dashboardController *controller.DashboardController
|
||||
uploadController *controller.UploadController
|
||||
activityController *controller.ActivityController
|
||||
roleController *controller_backyard.RoleController
|
||||
langController *controller.LangController
|
||||
userController *controller.UserController
|
||||
commentController *controller.CommentController
|
||||
reportController *controller.ReportController
|
||||
voteController *controller.VoteController
|
||||
tagController *controller.TagController
|
||||
followController *controller.FollowController
|
||||
collectionController *controller.CollectionController
|
||||
questionController *controller.QuestionController
|
||||
answerController *controller.AnswerController
|
||||
searchController *controller.SearchController
|
||||
revisionController *controller.RevisionController
|
||||
rankController *controller.RankController
|
||||
adminReportController *controller_admin.ReportController
|
||||
adminUserController *controller_admin.UserAdminController
|
||||
reasonController *controller.ReasonController
|
||||
themeController *controller_admin.ThemeController
|
||||
siteInfoController *controller_admin.SiteInfoController
|
||||
siteinfoController *controller.SiteinfoController
|
||||
notificationController *controller.NotificationController
|
||||
dashboardController *controller.DashboardController
|
||||
uploadController *controller.UploadController
|
||||
activityController *controller.ActivityController
|
||||
roleController *controller_admin.RoleController
|
||||
}
|
||||
|
||||
func NewAnswerAPIRouter(
|
||||
|
@ -47,43 +47,43 @@ func NewAnswerAPIRouter(
|
|||
searchController *controller.SearchController,
|
||||
revisionController *controller.RevisionController,
|
||||
rankController *controller.RankController,
|
||||
backyardReportController *controller_backyard.ReportController,
|
||||
backyardUserController *controller_backyard.UserBackyardController,
|
||||
adminReportController *controller_admin.ReportController,
|
||||
adminUserController *controller_admin.UserAdminController,
|
||||
reasonController *controller.ReasonController,
|
||||
themeController *controller_backyard.ThemeController,
|
||||
siteInfoController *controller_backyard.SiteInfoController,
|
||||
themeController *controller_admin.ThemeController,
|
||||
siteInfoController *controller_admin.SiteInfoController,
|
||||
siteinfoController *controller.SiteinfoController,
|
||||
notificationController *controller.NotificationController,
|
||||
dashboardController *controller.DashboardController,
|
||||
uploadController *controller.UploadController,
|
||||
activityController *controller.ActivityController,
|
||||
roleController *controller_backyard.RoleController,
|
||||
roleController *controller_admin.RoleController,
|
||||
) *AnswerAPIRouter {
|
||||
return &AnswerAPIRouter{
|
||||
langController: langController,
|
||||
userController: userController,
|
||||
commentController: commentController,
|
||||
reportController: reportController,
|
||||
voteController: voteController,
|
||||
tagController: tagController,
|
||||
followController: followController,
|
||||
collectionController: collectionController,
|
||||
questionController: questionController,
|
||||
answerController: answerController,
|
||||
searchController: searchController,
|
||||
revisionController: revisionController,
|
||||
rankController: rankController,
|
||||
backyardReportController: backyardReportController,
|
||||
backyardUserController: backyardUserController,
|
||||
reasonController: reasonController,
|
||||
themeController: themeController,
|
||||
siteInfoController: siteInfoController,
|
||||
notificationController: notificationController,
|
||||
siteinfoController: siteinfoController,
|
||||
dashboardController: dashboardController,
|
||||
uploadController: uploadController,
|
||||
activityController: activityController,
|
||||
roleController: roleController,
|
||||
langController: langController,
|
||||
userController: userController,
|
||||
commentController: commentController,
|
||||
reportController: reportController,
|
||||
voteController: voteController,
|
||||
tagController: tagController,
|
||||
followController: followController,
|
||||
collectionController: collectionController,
|
||||
questionController: questionController,
|
||||
answerController: answerController,
|
||||
searchController: searchController,
|
||||
revisionController: revisionController,
|
||||
rankController: rankController,
|
||||
adminReportController: adminReportController,
|
||||
adminUserController: adminUserController,
|
||||
reasonController: reasonController,
|
||||
themeController: themeController,
|
||||
siteInfoController: siteInfoController,
|
||||
notificationController: notificationController,
|
||||
siteinfoController: siteinfoController,
|
||||
dashboardController: dashboardController,
|
||||
uploadController: uploadController,
|
||||
activityController: activityController,
|
||||
roleController: roleController,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -225,22 +225,22 @@ func (a *AnswerAPIRouter) RegisterAnswerAPIRouter(r *gin.RouterGroup) {
|
|||
|
||||
}
|
||||
|
||||
func (a *AnswerAPIRouter) RegisterAnswerCmsAPIRouter(r *gin.RouterGroup) {
|
||||
r.GET("/question/page", a.questionController.CmsSearchList)
|
||||
func (a *AnswerAPIRouter) RegisterAnswerAdminAPIRouter(r *gin.RouterGroup) {
|
||||
r.GET("/question/page", a.questionController.AdminSearchList)
|
||||
r.PUT("/question/status", a.questionController.AdminSetQuestionStatus)
|
||||
r.GET("/answer/page", a.questionController.CmsSearchAnswerList)
|
||||
r.GET("/answer/page", a.questionController.AdminSearchAnswerList)
|
||||
r.PUT("/answer/status", a.answerController.AdminSetAnswerStatus)
|
||||
|
||||
// report
|
||||
r.GET("/reports/page", a.backyardReportController.ListReportPage)
|
||||
r.PUT("/report", a.backyardReportController.Handle)
|
||||
r.GET("/reports/page", a.adminReportController.ListReportPage)
|
||||
r.PUT("/report", a.adminReportController.Handle)
|
||||
|
||||
// user
|
||||
r.GET("/users/page", a.backyardUserController.GetUserPage)
|
||||
r.PUT("/user/status", a.backyardUserController.UpdateUserStatus)
|
||||
r.PUT("/user/role", a.backyardUserController.UpdateUserRole)
|
||||
r.POST("/user", a.backyardUserController.AddUser)
|
||||
r.PUT("/user/password", a.backyardUserController.UpdateUserPassword)
|
||||
r.GET("/users/page", a.adminUserController.GetUserPage)
|
||||
r.PUT("/user/status", a.adminUserController.UpdateUserStatus)
|
||||
r.PUT("/user/role", a.adminUserController.UpdateUserRole)
|
||||
r.POST("/user", a.adminUserController.AddUser)
|
||||
r.PUT("/user/password", a.adminUserController.UpdateUserPassword)
|
||||
|
||||
// reason
|
||||
r.GET("/reasons", a.reasonController.Reasons)
|
||||
|
|
|
@ -3,20 +3,20 @@ package router
|
|||
import (
|
||||
"github.com/answerdev/answer/internal/controller"
|
||||
templaterender "github.com/answerdev/answer/internal/controller/template_render"
|
||||
"github.com/answerdev/answer/internal/controller_backyard"
|
||||
"github.com/answerdev/answer/internal/controller_admin"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type TemplateRouter struct {
|
||||
templateController *controller.TemplateController
|
||||
templateRenderController *templaterender.TemplateRenderController
|
||||
siteInfoController *controller_backyard.SiteInfoController
|
||||
siteInfoController *controller_admin.SiteInfoController
|
||||
}
|
||||
|
||||
func NewTemplateRouter(
|
||||
templateController *controller.TemplateController,
|
||||
templateRenderController *templaterender.TemplateRenderController,
|
||||
siteInfoController *controller_backyard.SiteInfoController,
|
||||
siteInfoController *controller_admin.SiteInfoController,
|
||||
|
||||
) *TemplateRouter {
|
||||
return &TemplateRouter{
|
||||
|
|
|
@ -233,7 +233,7 @@ type QuestionSearch struct {
|
|||
UserID string `json:"-" form:"-"`
|
||||
}
|
||||
|
||||
type CmsQuestionSearch struct {
|
||||
type AdminQuestionSearch struct {
|
||||
Page int `json:"page" form:"page"` // Query number of pages
|
||||
PageSize int `json:"page_size" form:"page_size"` // Search page size
|
||||
Status int `json:"-" form:"-"`
|
||||
|
|
|
@ -19,7 +19,7 @@ type AnswerRepo interface {
|
|||
GetByID(ctx context.Context, id string) (*entity.Answer, bool, error)
|
||||
GetByUserIDQuestionID(ctx context.Context, userID string, questionID string) (*entity.Answer, bool, error)
|
||||
SearchList(ctx context.Context, search *entity.AnswerSearch) ([]*entity.Answer, int64, error)
|
||||
CmsSearchList(ctx context.Context, search *entity.CmsAnswerSearch) ([]*entity.Answer, int64, error)
|
||||
AdminSearchList(ctx context.Context, search *entity.AdminAnswerSearch) ([]*entity.Answer, int64, error)
|
||||
UpdateAnswerStatus(ctx context.Context, answer *entity.Answer) (err error)
|
||||
GetAnswerCount(ctx context.Context) (count int64, err error)
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ func (as *AnswerCommon) SearchAnswered(ctx context.Context, userID, questionID s
|
|||
return has, nil
|
||||
}
|
||||
|
||||
func (as *AnswerCommon) CmsSearchList(ctx context.Context, search *entity.CmsAnswerSearch) ([]*entity.Answer, int64, error) {
|
||||
func (as *AnswerCommon) AdminSearchList(ctx context.Context, search *entity.AdminAnswerSearch) ([]*entity.Answer, int64, error) {
|
||||
if search.Status == 0 {
|
||||
search.Status = 1
|
||||
}
|
||||
return as.answerRepo.CmsSearchList(ctx, search)
|
||||
return as.answerRepo.AdminSearchList(ctx, search)
|
||||
}
|
||||
|
||||
func (as *AnswerCommon) Search(ctx context.Context, search *entity.AnswerSearch) ([]*entity.Answer, int64, error) {
|
||||
|
|
|
@ -413,7 +413,7 @@ func (as *AnswerService) Get(ctx context.Context, answerID, loginUserID string)
|
|||
}
|
||||
|
||||
func (as *AnswerService) AdminSetAnswerStatus(ctx context.Context, req *schema.AdminSetAnswerStatusRequest) error {
|
||||
setStatus, ok := entity.CmsAnswerSearchStatus[req.StatusStr]
|
||||
setStatus, ok := entity.AdminAnswerSearchStatus[req.StatusStr]
|
||||
if !ok {
|
||||
return fmt.Errorf("question status does not exist")
|
||||
}
|
||||
|
|
|
@ -16,9 +16,9 @@ type AuthRepo interface {
|
|||
SetUserStatus(ctx context.Context, userID string, userInfo *entity.UserCacheInfo) (err error)
|
||||
GetUserStatus(ctx context.Context, userID string) (userInfo *entity.UserCacheInfo, err error)
|
||||
RemoveUserStatus(ctx context.Context, userID string) (err error)
|
||||
GetBackyardUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error)
|
||||
SetBackyardUserCacheInfo(ctx context.Context, accessToken string, userInfo *entity.UserCacheInfo) error
|
||||
RemoveBackyardUserCacheInfo(ctx context.Context, accessToken string) (err error)
|
||||
GetAdminUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error)
|
||||
SetAdminUserCacheInfo(ctx context.Context, accessToken string, userInfo *entity.UserCacheInfo) error
|
||||
RemoveAdminUserCacheInfo(ctx context.Context, accessToken string) (err error)
|
||||
AddUserTokenMapping(ctx context.Context, userID, accessToken string) (err error)
|
||||
RemoveAllUserTokens(ctx context.Context, userID string)
|
||||
}
|
||||
|
@ -90,17 +90,17 @@ func (as *AuthService) RemoveAllUserTokens(ctx context.Context, userID string) {
|
|||
as.authRepo.RemoveAllUserTokens(ctx, userID)
|
||||
}
|
||||
|
||||
//cms
|
||||
//Admin
|
||||
|
||||
func (as *AuthService) GetCmsUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error) {
|
||||
return as.authRepo.GetBackyardUserCacheInfo(ctx, accessToken)
|
||||
func (as *AuthService) GetAdminUserCacheInfo(ctx context.Context, accessToken string) (userInfo *entity.UserCacheInfo, err error) {
|
||||
return as.authRepo.GetAdminUserCacheInfo(ctx, accessToken)
|
||||
}
|
||||
|
||||
func (as *AuthService) SetCmsUserCacheInfo(ctx context.Context, accessToken string, userInfo *entity.UserCacheInfo) (err error) {
|
||||
err = as.authRepo.SetBackyardUserCacheInfo(ctx, accessToken, userInfo)
|
||||
func (as *AuthService) SetAdminUserCacheInfo(ctx context.Context, accessToken string, userInfo *entity.UserCacheInfo) (err error) {
|
||||
err = as.authRepo.SetAdminUserCacheInfo(ctx, accessToken, userInfo)
|
||||
return err
|
||||
}
|
||||
|
||||
func (as *AuthService) RemoveCmsUserCacheInfo(ctx context.Context, accessToken string) (err error) {
|
||||
return as.authRepo.RemoveBackyardUserCacheInfo(ctx, accessToken)
|
||||
func (as *AuthService) RemoveAdminUserCacheInfo(ctx context.Context, accessToken string) (err error) {
|
||||
return as.authRepo.RemoveAdminUserCacheInfo(ctx, accessToken)
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ import (
|
|||
"github.com/answerdev/answer/internal/service/rank"
|
||||
"github.com/answerdev/answer/internal/service/reason"
|
||||
"github.com/answerdev/answer/internal/service/report"
|
||||
"github.com/answerdev/answer/internal/service/report_backyard"
|
||||
"github.com/answerdev/answer/internal/service/report_handle_backyard"
|
||||
"github.com/answerdev/answer/internal/service/report_admin"
|
||||
"github.com/answerdev/answer/internal/service/report_handle_admin"
|
||||
"github.com/answerdev/answer/internal/service/revision_common"
|
||||
"github.com/answerdev/answer/internal/service/role"
|
||||
"github.com/answerdev/answer/internal/service/search_parser"
|
||||
|
@ -30,7 +30,7 @@ import (
|
|||
"github.com/answerdev/answer/internal/service/tag"
|
||||
tagcommon "github.com/answerdev/answer/internal/service/tag_common"
|
||||
"github.com/answerdev/answer/internal/service/uploader"
|
||||
"github.com/answerdev/answer/internal/service/user_backyard"
|
||||
"github.com/answerdev/answer/internal/service/user_admin"
|
||||
usercommon "github.com/answerdev/answer/internal/service/user_common"
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
@ -64,9 +64,9 @@ var ProviderSetService = wire.NewSet(
|
|||
NewSearchService,
|
||||
meta.NewMetaService,
|
||||
object_info.NewObjService,
|
||||
report_handle_backyard.NewReportHandle,
|
||||
report_backyard.NewReportBackyardService,
|
||||
user_backyard.NewUserBackyardService,
|
||||
report_handle_admin.NewReportHandle,
|
||||
report_admin.NewReportAdminService,
|
||||
user_admin.NewUserAdminService,
|
||||
reason.NewReasonService,
|
||||
siteinfo_common.NewSiteInfoCommonService,
|
||||
siteinfo.NewSiteInfoService,
|
||||
|
|
|
@ -40,7 +40,7 @@ type QuestionRepo interface {
|
|||
UpdateAccepted(ctx context.Context, question *entity.Question) (err error)
|
||||
UpdateLastAnswer(ctx context.Context, question *entity.Question) (err error)
|
||||
FindByID(ctx context.Context, id []string) (questionList []*entity.Question, err error)
|
||||
CmsSearchList(ctx context.Context, search *schema.CmsQuestionSearch) ([]*entity.Question, int64, error)
|
||||
AdminSearchList(ctx context.Context, search *schema.AdminQuestionSearch) ([]*entity.Question, int64, error)
|
||||
GetQuestionCount(ctx context.Context) (count int64, err error)
|
||||
GetQuestionIDsPage(ctx context.Context, page, pageSize int) (questionIDList []*schema.SiteMapQuestionInfo, err error)
|
||||
}
|
||||
|
|
|
@ -619,7 +619,7 @@ func (qs *QuestionService) SearchUserList(ctx context.Context, userName, order s
|
|||
for _, item := range questionlist {
|
||||
info := &schema.UserQuestionInfo{}
|
||||
_ = copier.Copy(info, item)
|
||||
status, ok := entity.CmsQuestionSearchStatusIntToString[item.Status]
|
||||
status, ok := entity.AdminQuestionSearchStatusIntToString[item.Status]
|
||||
if ok {
|
||||
info.Status = status
|
||||
}
|
||||
|
@ -796,7 +796,7 @@ func (qs *QuestionService) SearchByTitleLike(ctx context.Context, title string,
|
|||
item.AnswerCount = question.AnswerCount
|
||||
item.CollectionCount = question.CollectionCount
|
||||
item.FollowCount = question.FollowCount
|
||||
status, ok := entity.CmsQuestionSearchStatusIntToString[question.Status]
|
||||
status, ok := entity.AdminQuestionSearchStatusIntToString[question.Status]
|
||||
if ok {
|
||||
item.Status = status
|
||||
}
|
||||
|
@ -864,7 +864,7 @@ func (qs *QuestionService) SearchList(ctx context.Context, req *schema.QuestionS
|
|||
}
|
||||
|
||||
func (qs *QuestionService) AdminSetQuestionStatus(ctx context.Context, questionID string, setStatusStr string) error {
|
||||
setStatus, ok := entity.CmsQuestionSearchStatus[setStatusStr]
|
||||
setStatus, ok := entity.AdminQuestionSearchStatus[setStatusStr]
|
||||
if !ok {
|
||||
return fmt.Errorf("question status does not exist")
|
||||
}
|
||||
|
@ -919,10 +919,10 @@ func (qs *QuestionService) AdminSetQuestionStatus(ctx context.Context, questionI
|
|||
return nil
|
||||
}
|
||||
|
||||
func (qs *QuestionService) CmsSearchList(ctx context.Context, search *schema.CmsQuestionSearch, loginUserID string) ([]*schema.AdminQuestionInfo, int64, error) {
|
||||
func (qs *QuestionService) AdminSearchList(ctx context.Context, search *schema.AdminQuestionSearch, loginUserID string) ([]*schema.AdminQuestionInfo, int64, error) {
|
||||
list := make([]*schema.AdminQuestionInfo, 0)
|
||||
|
||||
status, ok := entity.CmsQuestionSearchStatus[search.StatusStr]
|
||||
status, ok := entity.AdminQuestionSearchStatus[search.StatusStr]
|
||||
if ok {
|
||||
search.Status = status
|
||||
}
|
||||
|
@ -930,7 +930,7 @@ func (qs *QuestionService) CmsSearchList(ctx context.Context, search *schema.Cms
|
|||
if search.Status == 0 {
|
||||
search.Status = 1
|
||||
}
|
||||
dblist, count, err := qs.questionRepo.CmsSearchList(ctx, search)
|
||||
dblist, count, err := qs.questionRepo.AdminSearchList(ctx, search)
|
||||
if err != nil {
|
||||
return list, count, err
|
||||
}
|
||||
|
@ -958,11 +958,11 @@ func (qs *QuestionService) CmsSearchList(ctx context.Context, search *schema.Cms
|
|||
return list, count, nil
|
||||
}
|
||||
|
||||
// CmsSearchList
|
||||
func (qs *QuestionService) CmsSearchAnswerList(ctx context.Context, search *entity.CmsAnswerSearch, loginUserID string) ([]*schema.AdminAnswerInfo, int64, error) {
|
||||
// AdminSearchList
|
||||
func (qs *QuestionService) AdminSearchAnswerList(ctx context.Context, search *entity.AdminAnswerSearch, loginUserID string) ([]*schema.AdminAnswerInfo, int64, error) {
|
||||
answerlist := make([]*schema.AdminAnswerInfo, 0)
|
||||
|
||||
status, ok := entity.CmsAnswerSearchStatus[search.StatusStr]
|
||||
status, ok := entity.AdminAnswerSearchStatus[search.StatusStr]
|
||||
if ok {
|
||||
search.Status = status
|
||||
}
|
||||
|
@ -970,7 +970,7 @@ func (qs *QuestionService) CmsSearchAnswerList(ctx context.Context, search *enti
|
|||
if search.Status == 0 {
|
||||
search.Status = 1
|
||||
}
|
||||
dblist, count, err := qs.questioncommon.AnswerCommon.CmsSearchList(ctx, search)
|
||||
dblist, count, err := qs.questioncommon.AnswerCommon.AdminSearchList(ctx, search)
|
||||
if err != nil {
|
||||
return answerlist, count, err
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package report_backyard
|
||||
package report_admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -16,35 +16,35 @@ import (
|
|||
"github.com/answerdev/answer/internal/service/comment_common"
|
||||
questioncommon "github.com/answerdev/answer/internal/service/question_common"
|
||||
"github.com/answerdev/answer/internal/service/report_common"
|
||||
"github.com/answerdev/answer/internal/service/report_handle_backyard"
|
||||
"github.com/answerdev/answer/internal/service/report_handle_admin"
|
||||
usercommon "github.com/answerdev/answer/internal/service/user_common"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/segmentfault/pacman/errors"
|
||||
)
|
||||
|
||||
// ReportBackyardService user service
|
||||
type ReportBackyardService struct {
|
||||
// ReportAdminService user service
|
||||
type ReportAdminService struct {
|
||||
reportRepo report_common.ReportRepo
|
||||
commonUser *usercommon.UserCommon
|
||||
commonRepo *common.CommonRepo
|
||||
answerRepo answercommon.AnswerRepo
|
||||
questionRepo questioncommon.QuestionRepo
|
||||
commentCommonRepo comment_common.CommentCommonRepo
|
||||
reportHandle *report_handle_backyard.ReportHandle
|
||||
reportHandle *report_handle_admin.ReportHandle
|
||||
configRepo config.ConfigRepo
|
||||
}
|
||||
|
||||
// NewReportBackyardService new report service
|
||||
func NewReportBackyardService(
|
||||
// NewReportAdminService new report service
|
||||
func NewReportAdminService(
|
||||
reportRepo report_common.ReportRepo,
|
||||
commonUser *usercommon.UserCommon,
|
||||
commonRepo *common.CommonRepo,
|
||||
answerRepo answercommon.AnswerRepo,
|
||||
questionRepo questioncommon.QuestionRepo,
|
||||
commentCommonRepo comment_common.CommentCommonRepo,
|
||||
reportHandle *report_handle_backyard.ReportHandle,
|
||||
configRepo config.ConfigRepo) *ReportBackyardService {
|
||||
return &ReportBackyardService{
|
||||
reportHandle *report_handle_admin.ReportHandle,
|
||||
configRepo config.ConfigRepo) *ReportAdminService {
|
||||
return &ReportAdminService{
|
||||
reportRepo: reportRepo,
|
||||
commonUser: commonUser,
|
||||
commonRepo: commonRepo,
|
||||
|
@ -57,7 +57,7 @@ func NewReportBackyardService(
|
|||
}
|
||||
|
||||
// ListReportPage list report pages
|
||||
func (rs *ReportBackyardService) ListReportPage(ctx context.Context, dto schema.GetReportListPageDTO) (pageModel *pager.PageModel, err error) {
|
||||
func (rs *ReportAdminService) ListReportPage(ctx context.Context, dto schema.GetReportListPageDTO) (pageModel *pager.PageModel, err error) {
|
||||
var (
|
||||
resp []*schema.GetReportListPageResp
|
||||
flags []entity.Report
|
||||
|
@ -105,7 +105,7 @@ func (rs *ReportBackyardService) ListReportPage(ctx context.Context, dto schema.
|
|||
}
|
||||
|
||||
// HandleReported handle the reported object
|
||||
func (rs *ReportBackyardService) HandleReported(ctx context.Context, req schema.ReportHandleReq) (err error) {
|
||||
func (rs *ReportAdminService) HandleReported(ctx context.Context, req schema.ReportHandleReq) (err error) {
|
||||
var (
|
||||
reported *entity.Report
|
||||
handleData = entity.Report{
|
||||
|
@ -139,7 +139,7 @@ func (rs *ReportBackyardService) HandleReported(ctx context.Context, req schema.
|
|||
return
|
||||
}
|
||||
|
||||
func (rs *ReportBackyardService) parseObject(ctx context.Context, resp *[]*schema.GetReportListPageResp) {
|
||||
func (rs *ReportAdminService) parseObject(ctx context.Context, resp *[]*schema.GetReportListPageResp) {
|
||||
var (
|
||||
res = *resp
|
||||
)
|
|
@ -1,4 +1,4 @@
|
|||
package report_handle_backyard
|
||||
package report_handle_admin
|
||||
|
||||
import (
|
||||
"context"
|
|
@ -1,4 +1,4 @@
|
|||
package user_backyard
|
||||
package user_admin
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -21,8 +21,8 @@ import (
|
|||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
// UserBackyardRepo user repository
|
||||
type UserBackyardRepo interface {
|
||||
// UserAdminRepo user repository
|
||||
type UserAdminRepo interface {
|
||||
UpdateUserStatus(ctx context.Context, userID string, userStatus, mailStatus int, email string) (err error)
|
||||
GetUserInfo(ctx context.Context, userID string) (user *entity.User, exist bool, err error)
|
||||
GetUserInfoByEmail(ctx context.Context, email string) (user *entity.User, exist bool, err error)
|
||||
|
@ -32,22 +32,22 @@ type UserBackyardRepo interface {
|
|||
UpdateUserPassword(ctx context.Context, userID string, password string) (err error)
|
||||
}
|
||||
|
||||
// UserBackyardService user service
|
||||
type UserBackyardService struct {
|
||||
userRepo UserBackyardRepo
|
||||
// UserAdminService user service
|
||||
type UserAdminService struct {
|
||||
userRepo UserAdminRepo
|
||||
userRoleRelService *role.UserRoleRelService
|
||||
authService *auth.AuthService
|
||||
userCommonService *usercommon.UserCommon
|
||||
}
|
||||
|
||||
// NewUserBackyardService new user backyard service
|
||||
func NewUserBackyardService(
|
||||
userRepo UserBackyardRepo,
|
||||
// NewUserAdminService new user admin service
|
||||
func NewUserAdminService(
|
||||
userRepo UserAdminRepo,
|
||||
userRoleRelService *role.UserRoleRelService,
|
||||
authService *auth.AuthService,
|
||||
userCommonService *usercommon.UserCommon,
|
||||
) *UserBackyardService {
|
||||
return &UserBackyardService{
|
||||
) *UserAdminService {
|
||||
return &UserAdminService{
|
||||
userRepo: userRepo,
|
||||
userRoleRelService: userRoleRelService,
|
||||
authService: authService,
|
||||
|
@ -56,7 +56,7 @@ func NewUserBackyardService(
|
|||
}
|
||||
|
||||
// UpdateUserStatus update user
|
||||
func (us *UserBackyardService) UpdateUserStatus(ctx context.Context, req *schema.UpdateUserStatusReq) (err error) {
|
||||
func (us *UserAdminService) UpdateUserStatus(ctx context.Context, req *schema.UpdateUserStatusReq) (err error) {
|
||||
userInfo, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -87,7 +87,7 @@ func (us *UserBackyardService) UpdateUserStatus(ctx context.Context, req *schema
|
|||
}
|
||||
|
||||
// UpdateUserRole update user role
|
||||
func (us *UserBackyardService) UpdateUserRole(ctx context.Context, req *schema.UpdateUserRoleReq) (err error) {
|
||||
func (us *UserAdminService) UpdateUserRole(ctx context.Context, req *schema.UpdateUserRoleReq) (err error) {
|
||||
// Users cannot modify their roles
|
||||
if req.UserID == req.LoginUserID {
|
||||
return errors.BadRequest(reason.UserCannotUpdateYourRole)
|
||||
|
@ -103,7 +103,7 @@ func (us *UserBackyardService) UpdateUserRole(ctx context.Context, req *schema.U
|
|||
}
|
||||
|
||||
// AddUser add user
|
||||
func (us *UserBackyardService) AddUser(ctx context.Context, req *schema.AddUserReq) (err error) {
|
||||
func (us *UserAdminService) AddUser(ctx context.Context, req *schema.AddUserReq) (err error) {
|
||||
_, has, err := us.userRepo.GetUserInfoByEmail(ctx, req.Email)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -138,7 +138,7 @@ func (us *UserBackyardService) AddUser(ctx context.Context, req *schema.AddUserR
|
|||
}
|
||||
|
||||
// UpdateUserPassword update user password
|
||||
func (us *UserBackyardService) UpdateUserPassword(ctx context.Context, req *schema.UpdateUserPasswordReq) (err error) {
|
||||
func (us *UserAdminService) UpdateUserPassword(ctx context.Context, req *schema.UpdateUserPasswordReq) (err error) {
|
||||
userInfo, exist, err := us.userRepo.GetUserInfo(ctx, req.UserID)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -162,7 +162,7 @@ func (us *UserBackyardService) UpdateUserPassword(ctx context.Context, req *sche
|
|||
}
|
||||
|
||||
// GetUserInfo get user one
|
||||
func (us *UserBackyardService) GetUserInfo(ctx context.Context, userID string) (resp *schema.GetUserInfoResp, err error) {
|
||||
func (us *UserAdminService) GetUserInfo(ctx context.Context, userID string) (resp *schema.GetUserInfoResp, err error) {
|
||||
user, exist, err := us.userRepo.GetUserInfo(ctx, userID)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -177,7 +177,7 @@ func (us *UserBackyardService) GetUserInfo(ctx context.Context, userID string) (
|
|||
}
|
||||
|
||||
// GetUserPage get user list page
|
||||
func (us *UserBackyardService) GetUserPage(ctx context.Context, req *schema.GetUserPageReq) (pageModel *pager.PageModel, err error) {
|
||||
func (us *UserAdminService) GetUserPage(ctx context.Context, req *schema.GetUserPageReq) (pageModel *pager.PageModel, err error) {
|
||||
user := &entity.User{}
|
||||
_ = copier.Copy(user, req)
|
||||
|
||||
|
@ -246,7 +246,7 @@ func (us *UserBackyardService) GetUserPage(ctx context.Context, req *schema.GetU
|
|||
return pager.NewPageModel(total, resp), nil
|
||||
}
|
||||
|
||||
func (us *UserBackyardService) setUserRoleInfo(ctx context.Context, resp []*schema.GetUserPageResp) {
|
||||
func (us *UserAdminService) setUserRoleInfo(ctx context.Context, resp []*schema.GetUserPageResp) {
|
||||
var userIDs []string
|
||||
for _, u := range resp {
|
||||
userIDs = append(userIDs, u.UserID)
|
|
@ -138,7 +138,7 @@ func (us *UserService) EmailLogin(ctx context.Context, req *schema.UserEmailLogi
|
|||
}
|
||||
resp.IsAdmin = userCacheInfo.IsAdmin
|
||||
if resp.IsAdmin {
|
||||
err = us.authService.SetCmsUserCacheInfo(ctx, resp.AccessToken, userCacheInfo)
|
||||
err = us.authService.SetAdminUserCacheInfo(ctx, resp.AccessToken, userCacheInfo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -355,7 +355,7 @@ func (us *UserService) UserRegisterByEmail(ctx context.Context, registerUserInfo
|
|||
}
|
||||
resp.IsAdmin = userCacheInfo.IsAdmin
|
||||
if resp.IsAdmin {
|
||||
err = us.authService.SetCmsUserCacheInfo(ctx, resp.AccessToken, &entity.UserCacheInfo{UserID: userInfo.ID})
|
||||
err = us.authService.SetAdminUserCacheInfo(ctx, resp.AccessToken, &entity.UserCacheInfo{UserID: userInfo.ID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -451,7 +451,7 @@ func (us *UserService) UserVerifyEmail(ctx context.Context, req *schema.UserVeri
|
|||
}
|
||||
resp.IsAdmin = userCacheInfo.IsAdmin
|
||||
if resp.IsAdmin {
|
||||
err = us.authService.SetCmsUserCacheInfo(ctx, resp.AccessToken, &entity.UserCacheInfo{UserID: userInfo.ID})
|
||||
err = us.authService.SetAdminUserCacheInfo(ctx, resp.AccessToken, &entity.UserCacheInfo{UserID: userInfo.ID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue