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