12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package logic
- import (
- "context"
- "fmt"
- "strings"
- "app.yhyue.com/moapp/jy_docs/rpc/stdlib/internal/svc"
- "app.yhyue.com/moapp/jy_docs/rpc/stdlib/stdlib"
- stdlibService "app.yhyue.com/moapp/jy_docs/services/stdlib"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type DocQueryLogic struct {
- ctx context.Context
- svcCtx *svc.ServiceContext
- logx.Logger
- }
- var (
- QuerySort = map[string]bool{
- "uploadDate": true,
- "viewTimes": true,
- "downTimes": true,
- }
- )
- func NewDocQueryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DocQueryLogic {
- return &DocQueryLogic{
- ctx: ctx,
- svcCtx: svcCtx,
- Logger: logx.WithContext(ctx),
- }
- }
- func (l *DocQueryLogic) DocQuery(in *stdlib.DocQueryRequest) (*stdlib.DocQueryResponse, error) {
- if in.PageNum < 1 {
- in.PageNum = 1
- }
- if in.UserId != "" && in.AppId == "" {
- return &stdlib.DocQueryResponse{
- Code: 0,
- Msg: "缺少参数appId",
- }, nil
- }
- for _, v := range in.Sort {
- if !QuerySort[v] && !QuerySort[strings.TrimLeft(v, "-")] {
- return &stdlib.DocQueryResponse{
- Code: 0,
- Msg: fmt.Sprintf("sort数组中%s值不合法", v),
- }, nil
- }
- }
- return stdlibService.DocQuery(in), nil
- }
|