feat: add site info tag config

This commit is contained in:
LinkinStar 2022-11-14 15:17:49 +08:00
parent 94c86fe3f8
commit 5fed2e2608
5 changed files with 86 additions and 5 deletions

View File

@ -54,4 +54,5 @@ const (
SiteTypeGeneral = "general"
SiteTypeInterface = "interface"
SiteTypeBranding = "branding"
SiteTypeWrite = "write"
)

View File

@ -45,7 +45,7 @@ func (sc *SiteInfoController) GetInterface(ctx *gin.Context) {
handler.HandleResponse(ctx, err, resp)
}
// GetBranding get site interface
// GetSiteBranding get site interface
// @Summary get site interface
// @Description get site interface
// @Security ApiKeyAuth
@ -53,8 +53,21 @@ func (sc *SiteInfoController) GetInterface(ctx *gin.Context) {
// @Produce json
// @Success 200 {object} handler.RespBody{data=schema.SiteBrandingResp}
// @Router /answer/admin/api/siteinfo/branding [get]
func (sc *SiteInfoController) GetBranding(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteInterface(ctx)
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}
// @Router /answer/admin/api/siteinfo/branding [get]
func (sc *SiteInfoController) GetSiteWrite(ctx *gin.Context) {
resp, err := sc.siteInfoService.GetSiteWrite(ctx)
handler.HandleResponse(ctx, err, resp)
}
@ -100,7 +113,7 @@ func (sc *SiteInfoController) UpdateInterface(ctx *gin.Context) {
// @Security ApiKeyAuth
// @Tags admin
// @Produce json
// @Param data body schema.SiteInterfaceReq true "branding info"
// @Param data body schema.SiteBrandingReq true "branding info"
// @Success 200 {object} handler.RespBody{}
// @Router /answer/admin/api/siteinfo/branding [put]
func (sc *SiteInfoController) UpdateBranding(ctx *gin.Context) {
@ -112,6 +125,24 @@ func (sc *SiteInfoController) UpdateBranding(ctx *gin.Context) {
handler.HandleResponse(ctx, err, nil)
}
// 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
}
err := sc.siteInfoService.SaveSiteWrite(ctx, req)
handler.HandleResponse(ctx, err, nil)
}
// GetSMTPConfig get smtp config
// @Summary GetSMTPConfig get smtp config
// @Description GetSMTPConfig get smtp config

View File

@ -224,10 +224,12 @@ func (a *AnswerAPIRouter) RegisterAnswerCmsAPIRouter(r *gin.RouterGroup) {
// siteinfo
r.GET("/siteinfo/general", a.siteInfoController.GetGeneral)
r.GET("/siteinfo/interface", a.siteInfoController.GetInterface)
r.GET("/siteinfo/branding", a.siteInfoController.GetBranding)
r.GET("/siteinfo/branding", a.siteInfoController.GetSiteBranding)
r.GET("/siteinfo/write", a.siteInfoController.GetSiteWrite)
r.PUT("/siteinfo/general", a.siteInfoController.UpdateGeneral)
r.PUT("/siteinfo/interface", a.siteInfoController.UpdateInterface)
r.PUT("/siteinfo/branding", a.siteInfoController.UpdateBranding)
r.PUT("/siteinfo/write", a.siteInfoController.UpdateSiteWrite)
r.GET("/setting/smtp", a.siteInfoController.GetSMTPConfig)
r.PUT("/setting/smtp", a.siteInfoController.UpdateSMTPConfig)

View File

@ -37,6 +37,11 @@ type SiteBrandingReq struct {
Favicon string `validate:"omitempty,gt=0,lte=512" form:"favicon" json:"favicon"`
}
// SiteWriteReq site write request
type SiteWriteReq struct {
RequiredTag bool `validate:"required" form:"required_tag" json:"required_tag"`
}
// SiteGeneralResp site general response
type SiteGeneralResp SiteGeneralReq
@ -46,6 +51,9 @@ type SiteInterfaceResp SiteInterfaceReq
// SiteBrandingResp site branding response
type SiteBrandingResp SiteBrandingReq
// SiteWriteResp site write response
type SiteWriteResp SiteWriteReq
// SiteInfoResp get site info response
type SiteInfoResp struct {
General *SiteGeneralResp `json:"general"`

View File

@ -56,6 +56,34 @@ func (s *SiteInfoService) GetSiteInterface(ctx context.Context) (resp *schema.Si
return resp, nil
}
// GetSiteBranding get site info branding
func (s *SiteInfoService) GetSiteBranding(ctx context.Context) (resp *schema.SiteBrandingReq, err error) {
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeBranding)
if err != nil {
return nil, err
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
}
resp = &schema.SiteBrandingReq{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}
// GetSiteWrite get site info write
func (s *SiteInfoService) GetSiteWrite(ctx context.Context) (resp *schema.SiteWriteReq, err error) {
siteInfo, exist, err := s.siteInfoRepo.GetByType(ctx, constant.SiteTypeWrite)
if err != nil {
return nil, err
}
if !exist {
return nil, errors.BadRequest(reason.SiteInfoNotFound)
}
resp = &schema.SiteWriteReq{}
_ = json.Unmarshal([]byte(siteInfo.Content), resp)
return resp, nil
}
func (s *SiteInfoService) SaveSiteGeneral(ctx context.Context, req schema.SiteGeneralReq) (err error) {
req.FormatSiteUrl()
var (
@ -120,6 +148,17 @@ func (s *SiteInfoService) SaveSiteBranding(ctx context.Context, req *schema.Site
return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeBranding, data)
}
// SaveSiteWrite save site configuration about write
func (s *SiteInfoService) SaveSiteWrite(ctx context.Context, req *schema.SiteWriteReq) (err error) {
content, _ := json.Marshal(req)
data := &entity.SiteInfo{
Type: constant.SiteTypeWrite,
Content: string(content),
Status: 1,
}
return s.siteInfoRepo.SaveByType(ctx, constant.SiteTypeWrite, data)
}
// GetSMTPConfig get smtp config
func (s *SiteInfoService) GetSMTPConfig(ctx context.Context) (
resp *schema.GetSMTPConfigResp, err error,