-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
84 lines (68 loc) · 2.72 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package advertiser
import (
"context"
"github.com/minipkg/selection_condition"
"github.com/pkg/errors"
"github.com/minipkg/log"
)
// IService encapsulates usecase logic for user.
type IService interface {
New(ctx context.Context) (*Advertiser, error)
Get(ctx context.Context, id uint, langID uint) (*Advertiser, error)
Query(ctx context.Context, condition *selection_condition.SelectionCondition, langID uint) ([]Advertiser, error)
First(ctx context.Context, condition *selection_condition.SelectionCondition, langID uint) (*Advertiser, error)
Count(ctx context.Context, condition *selection_condition.SelectionCondition, langID uint) (uint, error)
Create(ctx context.Context, obj *Advertiser, langID uint) error
Update(ctx context.Context, obj *Advertiser, langID uint) error
Delete(ctx context.Context, id uint) error
}
type service struct {
//Domain Domain
logger log.Logger
repository Repository
}
var _ IService = (*service)(nil)
// NewService creates a new service.
func NewService(logger log.Logger, repo Repository) IService {
s := &service{
logger: logger,
repository: repo,
}
repo.SetDefaultConditions(s.defaultConditions())
return s
}
// Defaults returns defaults params
func (s service) defaultConditions() *selection_condition.SelectionCondition {
return &selection_condition.SelectionCondition{}
}
func (s *service) New(ctx context.Context) (*Advertiser, error) {
return s.repository.New(ctx)
}
// Get returns the entity with the specified ID.
func (s *service) Get(ctx context.Context, id uint, langID uint) (*Advertiser, error) {
entity, err := s.repository.Get(ctx, id, langID)
if err != nil {
return nil, errors.Wrapf(err, "Can not get a %v by id: %v", EntityType, id)
}
return entity, nil
}
// Query returns the items with the specified offset and limit.
func (s *service) Query(ctx context.Context, condition *selection_condition.SelectionCondition, langID uint) ([]Advertiser, error) {
return s.repository.Query(ctx, condition, langID)
}
func (s *service) First(ctx context.Context, condition *selection_condition.SelectionCondition, langID uint) (*Advertiser, error) {
return s.repository.First(ctx, condition, langID)
}
// Count returns the number of items.
func (s *service) Count(ctx context.Context, condition *selection_condition.SelectionCondition, langID uint) (uint, error) {
return s.repository.Count(ctx, condition, langID)
}
func (s *service) Create(ctx context.Context, obj *Advertiser, langID uint) error {
return s.repository.Create(ctx, obj, langID)
}
func (s *service) Update(ctx context.Context, obj *Advertiser, langID uint) error {
return s.repository.Update(ctx, obj, langID)
}
func (s *service) Delete(ctx context.Context, id uint) error {
return s.repository.Delete(ctx, id)
}