49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
|
package domain
|
||
|
|
||
|
import (
|
||
|
"admin/apps/mockpro/domain/entity"
|
||
|
"admin/apps/mockpro/domain/repo"
|
||
|
"admin/apps/mockpro/internal/model/dto"
|
||
|
"gorm.io/gorm"
|
||
|
)
|
||
|
|
||
|
type BanSvc struct {
|
||
|
BanRepo repo.IBanRepo
|
||
|
}
|
||
|
|
||
|
func NewBanSvc(db *gorm.DB) *BanSvc {
|
||
|
svc := &BanSvc{
|
||
|
BanRepo: repo.NewBanRepo(db),
|
||
|
}
|
||
|
registerRestfulSvc("ban", svc)
|
||
|
return svc
|
||
|
}
|
||
|
|
||
|
func (svc *BanSvc) List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []IRestfulEntity, error) {
|
||
|
entityList, err := svc.BanRepo.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.BanDtoFieldsDescInfo, iList, nil
|
||
|
}
|
||
|
|
||
|
func (svc *BanSvc) Post(obj dto.CommonDtoValues) (IRestfulEntity, error) {
|
||
|
et := entity.FromBanDto(obj)
|
||
|
err := svc.BanRepo.Create(et)
|
||
|
return et, err
|
||
|
}
|
||
|
|
||
|
func (svc *BanSvc) Put(obj dto.CommonDtoValues) (IRestfulEntity, error) {
|
||
|
et := entity.FromBanDto(obj)
|
||
|
err := svc.BanRepo.Edit(et)
|
||
|
return et, err
|
||
|
}
|
||
|
|
||
|
func (svc *BanSvc) Delete(id int) error {
|
||
|
return svc.BanRepo.Delete(id)
|
||
|
}
|