-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
51 lines (37 loc) · 1.12 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
package company
import (
"context"
"gorm.io/gorm"
"strconv"
"github.com/gogo/protobuf/types"
pb "github.com/dinhtp/lets-go-pbtype/company"
)
type Service struct {
db *gorm.DB
}
func NewService(db *gorm.DB) *Service {
return &Service{db: db}
}
func (s Service) Create(ctx context.Context, r *pb.Company) (*pb.Company, error) {
return &pb.Company{}, nil
}
func (s Service) Update(ctx context.Context, r *pb.Company) (*pb.Company, error) {
return &pb.Company{}, nil
}
func (s Service) Get(ctx context.Context, r *pb.OneCompanyRequest) (*pb.Company, error) {
if err := validateOne(r); nil != err {
return nil, err
}
id , _ := strconv.Atoi(r.GetId())
company, err := NewRepository(s.db).FindOne(id)
if nil != err {
return nil, err
}
return prepareDataToResponse(company), nil
}
func (s Service) List(ctx context.Context, r *pb.ListCompanyRequest) (*pb.ListCompanyResponse, error) {
return &pb.ListCompanyResponse{}, nil
}
func (s Service) Delete(ctx context.Context, r *pb.OneCompanyRequest) (*types.Empty, error) {
return &types.Empty{}, nil
}