2022-09-27 17:59:05 +08:00
|
|
|
package controller_backyard
|
|
|
|
|
|
|
|
import (
|
2022-12-05 17:18:56 +08:00
|
|
|
"net/http"
|
|
|
|
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/base/handler"
|
2022-11-15 11:24:39 +08:00
|
|
|
"github.com/answerdev/answer/internal/base/middleware"
|
2022-10-24 16:51:05 +08:00
|
|
|
"github.com/answerdev/answer/internal/schema"
|
2022-11-03 11:12:20 +08:00
|
|
|
"github.com/answerdev/answer/internal/service/siteinfo"
|
2022-09-27 17:59:05 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2022-11-14 11:50:00 +08:00
|
|
|
// SiteInfoController site info controller
|
2022-09-27 17:59:05 +08:00
|
|
|
type SiteInfoController struct {
|
2022-11-03 11:12:20 +08:00
|
|
|
siteInfoService *siteinfo.SiteInfoService
|
2022-09-27 17:59:05 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 11:50:00 +08:00
|
|
|
// NewSiteInfoController new site info controller
|
2022-11-03 11:12:20 +08:00
|
|
|
func NewSiteInfoController(siteInfoService *siteinfo.SiteInfoService) *SiteInfoController {
|
2022-09-27 17:59:05 +08:00
|
|
|
return &SiteInfoController{
|
|
|
|
siteInfoService: siteInfoService,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-02 15:02:27 +08:00
|
|
|
// GetGeneral get site general information
|
|
|
|
// @Summary get site general information
|
|
|
|
// @Description get site general information
|
2022-09-27 17:59:05 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} handler.RespBody{data=schema.SiteGeneralResp}
|
|
|
|
// @Router /answer/admin/api/siteinfo/general [get]
|
|
|
|
func (sc *SiteInfoController) GetGeneral(ctx *gin.Context) {
|
|
|
|
resp, err := sc.siteInfoService.GetSiteGeneral(ctx)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
2022-11-02 15:02:27 +08:00
|
|
|
// GetInterface get site interface
|
|
|
|
// @Summary get site interface
|
|
|
|
// @Description get site interface
|
2022-09-27 17:59:05 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} handler.RespBody{data=schema.SiteInterfaceResp}
|
|
|
|
// @Router /answer/admin/api/siteinfo/interface [get]
|
|
|
|
func (sc *SiteInfoController) GetInterface(ctx *gin.Context) {
|
|
|
|
resp, err := sc.siteInfoService.GetSiteInterface(ctx)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:17:49 +08:00
|
|
|
// GetSiteBranding get site interface
|
2022-11-14 11:50:00 +08:00
|
|
|
// @Summary get site interface
|
|
|
|
// @Description get site interface
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} handler.RespBody{data=schema.SiteBrandingResp}
|
|
|
|
// @Router /answer/admin/api/siteinfo/branding [get]
|
2022-11-14 15:17:49 +08:00
|
|
|
func (sc *SiteInfoController) GetSiteBranding(ctx *gin.Context) {
|
|
|
|
resp, err := sc.siteInfoService.GetSiteBranding(ctx)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetSiteWrite get site interface
|
|
|
|
// @Summary get site interface
|
|
|
|
// @Description get site interface
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} handler.RespBody{data=schema.SiteWriteResp}
|
2022-11-14 17:04:25 +08:00
|
|
|
// @Router /answer/admin/api/siteinfo/write [get]
|
2022-11-14 15:17:49 +08:00
|
|
|
func (sc *SiteInfoController) GetSiteWrite(ctx *gin.Context) {
|
|
|
|
resp, err := sc.siteInfoService.GetSiteWrite(ctx)
|
2022-11-14 11:50:00 +08:00
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
2022-11-14 17:04:25 +08:00
|
|
|
// GetSiteLegal Set the legal information for the site
|
|
|
|
// @Summary Set the legal information for the site
|
|
|
|
// @Description Set the legal information for the site
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} handler.RespBody{data=schema.SiteLegalResp}
|
|
|
|
// @Router /answer/admin/api/siteinfo/legal [get]
|
|
|
|
func (sc *SiteInfoController) GetSiteLegal(ctx *gin.Context) {
|
|
|
|
resp, err := sc.siteInfoService.GetSiteLegal(ctx)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
2022-12-05 17:18:56 +08:00
|
|
|
// GetSeo get site seo information
|
|
|
|
// @Summary get site seo information
|
|
|
|
// @Description get site seo information
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {object} handler.RespBody{data=schema.SiteSeoResp}
|
|
|
|
// @Router /answer/admin/api/siteinfo/seo [get]
|
|
|
|
func (sc *SiteInfoController) GetSeo(ctx *gin.Context) {
|
|
|
|
resp, err := sc.siteInfoService.GetSeo(ctx)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRobots get site robots information
|
|
|
|
// @Summary get site robots information
|
|
|
|
// @Description get site robots information
|
|
|
|
// @Tags site
|
|
|
|
// @Produce json
|
|
|
|
// @Success 200 {string} txt ""
|
|
|
|
// @Router /robots.txt [get]
|
|
|
|
func (sc *SiteInfoController) GetRobots(ctx *gin.Context) {
|
|
|
|
resp, err := sc.siteInfoService.GetSeo(ctx)
|
|
|
|
if err != nil {
|
|
|
|
ctx.String(http.StatusOK, "")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.String(http.StatusOK, resp.Robots)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateSeo update site seo information
|
|
|
|
// @Summary update site seo information
|
|
|
|
// @Description update site seo information
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Param data body schema.SiteSeoReq true "seo"
|
|
|
|
// @Success 200 {object} handler.RespBody{}
|
|
|
|
// @Router /answer/admin/api/siteinfo/seo [put]
|
|
|
|
func (sc *SiteInfoController) UpdateSeo(ctx *gin.Context) {
|
|
|
|
req := schema.SiteSeoReq{}
|
|
|
|
if handler.BindAndCheck(ctx, &req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := sc.siteInfoService.SaveSeo(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
|
|
|
|
2022-11-02 15:02:27 +08:00
|
|
|
// UpdateGeneral update site general information
|
|
|
|
// @Summary update site general information
|
|
|
|
// @Description update site general information
|
2022-09-27 17:59:05 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Param data body schema.SiteGeneralReq true "general"
|
|
|
|
// @Success 200 {object} handler.RespBody{}
|
|
|
|
// @Router /answer/admin/api/siteinfo/general [put]
|
|
|
|
func (sc *SiteInfoController) UpdateGeneral(ctx *gin.Context) {
|
|
|
|
req := schema.SiteGeneralReq{}
|
2022-09-30 15:30:50 +08:00
|
|
|
if handler.BindAndCheck(ctx, &req) {
|
|
|
|
return
|
|
|
|
}
|
2022-09-27 17:59:05 +08:00
|
|
|
err := sc.siteInfoService.SaveSiteGeneral(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
|
|
|
|
2022-11-02 15:02:27 +08:00
|
|
|
// UpdateInterface update site interface
|
|
|
|
// @Summary update site info interface
|
|
|
|
// @Description update site info interface
|
2022-09-27 17:59:05 +08:00
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Param data body schema.SiteInterfaceReq true "general"
|
|
|
|
// @Success 200 {object} handler.RespBody{}
|
|
|
|
// @Router /answer/admin/api/siteinfo/interface [put]
|
|
|
|
func (sc *SiteInfoController) UpdateInterface(ctx *gin.Context) {
|
|
|
|
req := schema.SiteInterfaceReq{}
|
2022-09-30 15:30:50 +08:00
|
|
|
if handler.BindAndCheck(ctx, &req) {
|
|
|
|
return
|
|
|
|
}
|
2022-09-27 17:59:05 +08:00
|
|
|
err := sc.siteInfoService.SaveSiteInterface(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
2022-10-20 16:38:56 +08:00
|
|
|
|
2022-11-14 11:50:00 +08:00
|
|
|
// UpdateBranding update site branding
|
|
|
|
// @Summary update site info branding
|
|
|
|
// @Description update site info branding
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
2022-11-14 15:17:49 +08:00
|
|
|
// @Param data body schema.SiteBrandingReq true "branding info"
|
2022-11-14 11:50:00 +08:00
|
|
|
// @Success 200 {object} handler.RespBody{}
|
|
|
|
// @Router /answer/admin/api/siteinfo/branding [put]
|
|
|
|
func (sc *SiteInfoController) UpdateBranding(ctx *gin.Context) {
|
|
|
|
req := &schema.SiteBrandingReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := sc.siteInfoService.SaveSiteBranding(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
|
|
|
|
2022-11-14 15:17:49 +08:00
|
|
|
// UpdateSiteWrite update site write info
|
|
|
|
// @Summary update site write info
|
|
|
|
// @Description update site write info
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Param data body schema.SiteWriteReq true "write info"
|
|
|
|
// @Success 200 {object} handler.RespBody{}
|
|
|
|
// @Router /answer/admin/api/siteinfo/write [put]
|
|
|
|
func (sc *SiteInfoController) UpdateSiteWrite(ctx *gin.Context) {
|
|
|
|
req := &schema.SiteWriteReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
2022-11-15 11:24:39 +08:00
|
|
|
req.UserID = middleware.GetLoginUserIDFromContext(ctx)
|
|
|
|
|
2022-11-16 10:38:15 +08:00
|
|
|
resp, err := sc.siteInfoService.SaveSiteWrite(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
2022-11-14 15:17:49 +08:00
|
|
|
}
|
|
|
|
|
2022-11-14 17:04:25 +08:00
|
|
|
// UpdateSiteLegal update site legal info
|
|
|
|
// @Summary update site legal info
|
|
|
|
// @Description update site legal info
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
|
|
|
// @Param data body schema.SiteLegalReq true "write info"
|
|
|
|
// @Success 200 {object} handler.RespBody{}
|
|
|
|
// @Router /answer/admin/api/siteinfo/legal [put]
|
|
|
|
func (sc *SiteInfoController) UpdateSiteLegal(ctx *gin.Context) {
|
|
|
|
req := &schema.SiteLegalReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := sc.siteInfoService.SaveSiteLegal(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|
|
|
|
|
2022-10-20 16:38:56 +08:00
|
|
|
// GetSMTPConfig get smtp config
|
|
|
|
// @Summary GetSMTPConfig get smtp config
|
|
|
|
// @Description GetSMTPConfig get smtp config
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
2022-10-21 10:26:32 +08:00
|
|
|
// @Success 200 {object} handler.RespBody{data=schema.GetSMTPConfigResp}
|
2022-10-20 16:38:56 +08:00
|
|
|
// @Router /answer/admin/api/setting/smtp [get]
|
|
|
|
func (sc *SiteInfoController) GetSMTPConfig(ctx *gin.Context) {
|
|
|
|
resp, err := sc.siteInfoService.GetSMTPConfig(ctx)
|
|
|
|
handler.HandleResponse(ctx, err, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateSMTPConfig update smtp config
|
|
|
|
// @Summary update smtp config
|
|
|
|
// @Description update smtp config
|
|
|
|
// @Security ApiKeyAuth
|
|
|
|
// @Tags admin
|
|
|
|
// @Produce json
|
2022-10-21 10:26:32 +08:00
|
|
|
// @Param data body schema.UpdateSMTPConfigReq true "smtp config"
|
2022-10-20 16:38:56 +08:00
|
|
|
// @Success 200 {object} handler.RespBody{}
|
|
|
|
// @Router /answer/admin/api/setting/smtp [put]
|
|
|
|
func (sc *SiteInfoController) UpdateSMTPConfig(ctx *gin.Context) {
|
|
|
|
req := &schema.UpdateSMTPConfigReq{}
|
|
|
|
if handler.BindAndCheck(ctx, req) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err := sc.siteInfoService.UpdateSMTPConfig(ctx, req)
|
|
|
|
handler.HandleResponse(ctx, err, nil)
|
|
|
|
}
|