setcachelogic.go 960 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Code scaffolded by goctl. Safe to edit.
  2. // goctl 1.10.2
  3. package custompage
  4. import (
  5. "context"
  6. "strings"
  7. "udeServer/internal/apierr"
  8. pagecache "udeServer/internal/custompage"
  9. "udeServer/internal/svc"
  10. "udeServer/internal/types"
  11. "github.com/zeromicro/go-zero/core/logx"
  12. )
  13. type SetCacheLogic struct {
  14. logx.Logger
  15. ctx context.Context
  16. svcCtx *svc.ServiceContext
  17. }
  18. // 设置自定义页面信息(标题/logo)
  19. func NewSetCacheLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetCacheLogic {
  20. return &SetCacheLogic{
  21. Logger: logx.WithContext(ctx),
  22. ctx: ctx,
  23. svcCtx: svcCtx,
  24. }
  25. }
  26. func (l *SetCacheLogic) SetCache(req *types.SetCacheReq) (*types.SetCacheResp, error) {
  27. if strings.TrimSpace(req.Name) == "" && strings.TrimSpace(req.Logo) == "" {
  28. return nil, apierr.BadRequest("页面标题与 logo 不能同时为空")
  29. }
  30. pagecache.SetCache(req.Name, req.Logo)
  31. return &types.SetCacheResp{Name: req.Name, Logo: req.Logo}, nil
  32. }