/
catgsrv.go
48 lines (38 loc) · 1.32 KB
/
catgsrv.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
46
47
48
package app
import (
"context"
"github.com/gimmickless/keat-kit-service/internal/domain"
"github.com/uptrace/opentelemetry-go-extra/otelzap"
)
type ICategoryService interface {
Create(ctx context.Context, catg domain.Category) (string, error)
Update(ctx context.Context, id string, catg domain.Category) error
Delete(ctx context.Context, id string) error
Get(ctx context.Context, id string) (domain.Category, error)
GetAll(ctx context.Context) ([]domain.Category, error)
}
type CategoryService struct {
logger *otelzap.SugaredLogger
catgRepo ICategoryRepo
}
func NewCategoryService(
logger *otelzap.SugaredLogger,
catgRepo ICategoryRepo,
) *CategoryService {
return &CategoryService{logger, catgRepo}
}
func (s *CategoryService) Create(ctx context.Context, catg domain.Category) (string, error) {
return s.catgRepo.Insert(ctx, catg)
}
func (s *CategoryService) Update(ctx context.Context, id string, catg domain.Category) error {
return s.catgRepo.Update(ctx, id, catg)
}
func (s *CategoryService) Delete(ctx context.Context, id string) error {
return s.catgRepo.Delete(ctx, id)
}
func (s *CategoryService) Get(ctx context.Context, id string) (domain.Category, error) {
return s.catgRepo.Get(ctx, id)
}
func (s *CategoryService) GetAll(ctx context.Context) ([]domain.Category, error) {
return s.catgRepo.GetAll(ctx)
}