listserviceslogic.go 893 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Code scaffolded by goctl. Safe to edit.
  2. // goctl 1.10.2
  3. package logic
  4. import (
  5. "context"
  6. "udeServer/internal/svc"
  7. "udeServer/internal/types"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. type ListServicesLogic struct {
  11. logx.Logger
  12. ctx context.Context
  13. svcCtx *svc.ServiceContext
  14. }
  15. func NewListServicesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListServicesLogic {
  16. return &ListServicesLogic{
  17. Logger: logx.WithContext(ctx),
  18. ctx: ctx,
  19. svcCtx: svcCtx,
  20. }
  21. }
  22. func (l *ListServicesLogic) ListServices() (*types.ServiceListResp, error) {
  23. list, err := l.svcCtx.ServiceModel.FindAll(l.ctx)
  24. if err != nil {
  25. l.Errorf("list services failed: %v", err)
  26. return nil, err
  27. }
  28. resp := &types.ServiceListResp{
  29. List: make([]types.ServiceResp, 0, len(list)),
  30. }
  31. for i := range list {
  32. resp.List = append(resp.List, *toServiceResp(&list[i]))
  33. }
  34. return resp, nil
  35. }