package service import ( "admin/apps/mockpro/domain" dto2 "admin/apps/mockpro/internal/model/dto" "context" "gorm.io/gorm" ) type Service struct { db *gorm.DB whitelistSvc *domain.WhiteListSvc banSvc *domain.BanSvc } func New(db *gorm.DB) *Service { return &Service{ db: db, whitelistSvc: domain.NewWhiteListSvc(db), banSvc: domain.NewBanSvc(db), } } func (svc *Service) CommonList(ctx context.Context, resourceName string, params *dto2.CommonListReq) (*dto2.CommonDtoList, error) { restfulDomainSvc, err := domain.FindRestfulResourceSvc(resourceName) if err != nil { return nil, err } dtoFieldsDescInfo, list, err := restfulDomainSvc.List(params.PageNo, params.PageLen) if err != nil { return nil, err } retList := make([]dto2.CommonDtoValues, 0, len(list)) for _, v := range list { retList = append(retList, v.ToCommonDto()) } return &dto2.CommonDtoList{FieldsDesc: dtoFieldsDescInfo, Rows: retList}, nil } func (svc *Service) CommonPost(ctx context.Context, resourceName string, params dto2.CommonDtoValues) (dto2.CommonDtoValues, error) { restfulDomainSvc, err := domain.FindRestfulResourceSvc(resourceName) if err != nil { return nil, err } et, err := restfulDomainSvc.Post(params) if err != nil { return nil, err } return et.ToCommonDto(), nil } func (svc *Service) CommonPut(ctx context.Context, resourceName string, params dto2.CommonDtoValues) (dto2.CommonDtoValues, error) { restfulDomainSvc, err := domain.FindRestfulResourceSvc(resourceName) if err != nil { return nil, err } et, err := restfulDomainSvc.Put(params) if err != nil { return nil, err } return et.ToCommonDto(), nil } func (svc *Service) CommonDelete(ctx context.Context, resourceName string, id int) error { restfulDomainSvc, err := domain.FindRestfulResourceSvc(resourceName) if err != nil { return err } return restfulDomainSvc.Delete(id) }