user_adaptor.go
1.9 KB
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
package adaptor
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/service_gateway/translator"
)
type UserAdaptor struct {
}
func (adaptor *UserAdaptor) ToParticipator(companyId int64, orgId int64, userId int64, aRoleName string) (interface{}, error) {
userServiceGateway := service_gateway.NewHttplibUserServiceGateway()
response, err := userServiceGateway.GetUser(companyId, orgId, userId)
if err != nil {
return map[string]interface{}{}, err
}
if userTranslator, err := translator.NewUserTranslator(); err != nil {
return map[string]interface{}{}, err
} else {
switch aRoleName {
case "Relevant":
relevant, err := userTranslator.ToRelevantFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, err
}
return relevant, nil
case "Referrer":
referrer, err := userTranslator.ToReferrerFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, err
}
return referrer, nil
case "Salesman":
salesman, err := userTranslator.ToSalesmanFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return salesman, nil
case "Undertaker":
undertaker, err := userTranslator.ToUndertakerFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return undertaker, nil
case "Operator":
operator, err := userTranslator.ToOperatorFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return operator, nil
case "User":
user, err := userTranslator.ToUserFromRepresentation(response)
if err != nil {
return map[string]interface{}{}, nil
}
return user, nil
}
}
return map[string]interface{}{}, nil
}
func NewUserAdaptor() (*UserAdaptor, error) {
return &UserAdaptor{}, nil
}