-
Notifications
You must be signed in to change notification settings - Fork 3
/
crud_service.go
45 lines (36 loc) · 1.18 KB
/
crud_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gorm_crud
type CrudServiceInterface interface {
BaseServiceInterface
GetModel() InterfaceEntity
GetItem(id uint) (InterfaceEntity, error)
GetList(parameters ListParametersInterface) ([]InterfaceEntity, error)
Create(item InterfaceEntity) InterfaceEntity
Update(item InterfaceEntity) InterfaceEntity
Delete(id uint) error
}
type CrudService struct {
*BaseService
Repository CrudRepositoryInterface
}
func NewCrudService(repository CrudRepositoryInterface, logger LoggerInterface) *CrudService {
service := NewBaseService(repository, logger)
return &CrudService{service, repository}
}
func (c CrudService) GetModel() InterfaceEntity {
return c.Repository.GetModel()
}
func (c CrudService) GetItem(id uint) (InterfaceEntity, error) {
return c.Repository.Find(id)
}
func (c CrudService) GetList(parameters ListParametersInterface) ([]InterfaceEntity, error) {
return c.Repository.List(parameters)
}
func (c CrudService) Create(item InterfaceEntity) InterfaceEntity {
return c.Repository.Create(item)
}
func (c CrudService) Update(item InterfaceEntity) InterfaceEntity {
return c.Repository.Update(item)
}
func (c CrudService) Delete(id uint) error {
return c.Repository.Delete(id)
}