49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package domain
|
|
|
|
import (
|
|
"admin/apps/game/domain/entity"
|
|
"admin/apps/game/domain/repo"
|
|
"admin/apps/game/model/dto"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type ServerSvc struct {
|
|
serverRepo repo.IServerRepo
|
|
}
|
|
|
|
func NewServerSvc(db *gorm.DB) *ServerSvc {
|
|
svc := &ServerSvc{
|
|
serverRepo: repo.NewServerRepo(db),
|
|
}
|
|
registerRestfulSvc("server", svc)
|
|
return svc
|
|
}
|
|
|
|
func (svc *ServerSvc) List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []IRestfulEntity, error) {
|
|
entityList, err := svc.serverRepo.List(pageNo, pageLen)
|
|
if err != nil {
|
|
return nil, nil, err
|
|
}
|
|
iList := make([]IRestfulEntity, 0, len(entityList))
|
|
for _, v := range entityList {
|
|
iList = append(iList, v)
|
|
}
|
|
return entity.ServerDtoFieldsDescInfo, iList, nil
|
|
}
|
|
|
|
func (svc *ServerSvc) Post(obj dto.CommonDtoValues) (IRestfulEntity, error) {
|
|
et := entity.FromServerDto(obj)
|
|
err := svc.serverRepo.Create(et)
|
|
return et, err
|
|
}
|
|
|
|
func (svc *ServerSvc) Put(obj dto.CommonDtoValues) (IRestfulEntity, error) {
|
|
et := entity.FromServerDto(obj)
|
|
err := svc.serverRepo.Edit(et)
|
|
return et, err
|
|
}
|
|
|
|
func (svc *ServerSvc) Delete(id int) error {
|
|
return svc.serverRepo.Delete(id)
|
|
}
|