findAppListLogic.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package logic
  2. import (
  3. "GtDataStore/app/cmd/organization/internal/svc"
  4. "GtDataStore/app/cmd/organization/pb"
  5. "context"
  6. "github.com/zeromicro/go-zero/core/logx"
  7. )
  8. type FindAppListLogic struct {
  9. ctx context.Context
  10. svcCtx *svc.ServiceContext
  11. logx.Logger
  12. }
  13. func NewFindAppListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindAppListLogic {
  14. return &FindAppListLogic{
  15. ctx: ctx,
  16. svcCtx: svcCtx,
  17. Logger: logx.WithContext(ctx),
  18. }
  19. }
  20. func (l *FindAppListLogic) FindAppList(in *pb.FindAppListReq) (*pb.FindAppListResp, error) {
  21. if in.Page <= 1 {
  22. in.Page = 1
  23. }
  24. offset, limit := (in.Page-1)*in.PageSize, in.PageSize
  25. appInfos, total, err := l.svcCtx.AppInfo.Find(l.ctx, offset, limit, "`id` DESC")
  26. if err != nil {
  27. return nil, err
  28. }
  29. res := make([]*pb.AppInfo, len(appInfos))
  30. for i, info := range appInfos {
  31. res[i] = &pb.AppInfo{
  32. Id: info.Id,
  33. AppName: info.AppName,
  34. ProjectIds: info.ProjectIds,
  35. Secret: info.Secret,
  36. Status: info.Status,
  37. ExpireAt: info.ExpireAt.Format("2006-01-02 15:04:05"),
  38. CTime: info.MTime.Format("2006-01-02 15:04:05"),
  39. }
  40. }
  41. return &pb.FindAppListResp{List: res, Pagination: &pb.Pagination{
  42. Current: uint32(in.Page),
  43. PageSize: uint32(in.PageSize),
  44. Total: uint32(total),
  45. }}, nil
  46. }