/
organization.go
59 lines (44 loc) · 1.55 KB
/
organization.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
package org
import (
"context"
"github.com/c1emon/lemontree/pkg/gormx"
"github.com/c1emon/lemontree/pkg/httpx"
"github.com/pkg/errors"
)
func NewOrganizationService() *OrganizationService {
repo := &gormOrganizationRepository{
db: gormx.GetGormDB(),
}
repo.InitDB()
return &OrganizationService{repository: repo}
}
type OrganizationService struct {
repository OrganizationRepository
}
func (s *OrganizationService) Create(name string) (*Organization, error) {
err := s.repository.CreateOne(context.Background(), &Organization{Name: name})
if err != nil {
return nil, errors.WithMessage(err, "name "+name)
}
org, err := s.repository.GetOneByName(context.Background(), name)
return org, errors.WithMessage(err, "name "+name)
}
func (s *OrganizationService) GetById(id string) (*Organization, error) {
org, err := s.repository.GetOneById(context.Background(), id)
return org, errors.WithMessage(err, "organization")
}
func (s *OrganizationService) GetByName(name string) (*Organization, error) {
org, err := s.repository.GetOneByName(context.Background(), name)
return org, errors.WithMessage(err, "organization")
}
func (s *OrganizationService) GetByNameAll(pageable httpx.Pageable, name string) []Organization {
return s.repository.GetAllByName(context.Background(), pageable, name)
}
func (s *OrganizationService) DeleteOne(id string) error {
return errors.WithMessage(s.repository.DeleteOneById(context.Background(), id), "organization")
}
func (s *OrganizationService) UpdateOne() error {
return nil
}
func (s *OrganizationService) FindAll() {
}