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 WhiteListSvc struct {
|
||
|
proRepo repo.IWhiteListRepo
|
||
|
}
|
||
|
|
||
|
func NewWhiteListSvc(db *gorm.DB) *WhiteListSvc {
|
||
|
svc := &WhiteListSvc{
|
||
|
proRepo: repo.NewWhiteListRepo(db),
|
||
|
}
|
||
|
registerRestfulSvc("whitelist", svc)
|
||
|
return svc
|
||
|
}
|
||
|
|
||
|
func (svc *WhiteListSvc) List(pageNo, pageLen int) ([]*dto.CommonDtoFieldDesc, []IRestfulEntity, error) {
|
||
|
entityList, err := svc.proRepo.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.WhiteListDtoFieldsDescInfo, iList, nil
|
||
|
}
|
||
|
|
||
|
func (svc *WhiteListSvc) Post(obj dto.CommonDtoValues) (IRestfulEntity, error) {
|
||
|
et := entity.FromWhiteListDto(obj)
|
||
|
err := svc.proRepo.Create(et)
|
||
|
return et, err
|
||
|
}
|
||
|
|
||
|
func (svc *WhiteListSvc) Put(obj dto.CommonDtoValues) (IRestfulEntity, error) {
|
||
|
et := entity.FromWhiteListDto(obj)
|
||
|
err := svc.proRepo.Edit(et)
|
||
|
return et, err
|
||
|
}
|
||
|
|
||
|
func (svc *WhiteListSvc) Delete(id int) error {
|
||
|
return svc.proRepo.Delete(id)
|
||
|
}
|