69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"admin/apps/game/domain"
|
|
"admin/apps/game/model/dto"
|
|
"context"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Service struct {
|
|
db *gorm.DB
|
|
projectSvc *domain.ProjectSvc
|
|
serverSvc *domain.ServerSvc
|
|
}
|
|
|
|
func NewCmdServerSvc(db *gorm.DB) *Service {
|
|
return &Service{
|
|
db: db,
|
|
projectSvc: domain.NewProjectSvc(db),
|
|
serverSvc: domain.NewServerSvc(db),
|
|
}
|
|
}
|
|
|
|
func (svc *Service) CommonList(ctx context.Context, resourceName string, params *dto.CommonListReq) (*dto.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([]*dto.CommonDtoValues, 0, len(list))
|
|
for _, v := range list {
|
|
retList = append(retList, v.ToCommonDto())
|
|
}
|
|
return &dto.CommonDtoList{FieldsDesc: dtoFieldsDescInfo, Rows: retList}, nil
|
|
}
|
|
|
|
func (svc *Service) CommonPost(ctx context.Context, resourceName string, params *dto.CommonDtoValues) (*dto.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 *dto.CommonDtoValues) (*dto.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)
|
|
}
|