-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
handle_user_driver.go
62 lines (59 loc) · 1.46 KB
/
handle_user_driver.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
package main
import (
"strings"
"go.mongodb.org/mongo-driver/mongo"
)
// OrganizationsFormToOrganizationsV2 함수는 form 문자를 받아서 []Organization 을 생성한다.
func OrganizationsFormToOrganizationsV2(client *mongo.Client, s string) ([]Organization, error) {
var results []Organization
orgs := strings.Split(s, ":")
for _, org := range orgs {
parts := strings.Split(org, ",")
if len(parts) != 6 { // [ Primary여부(true||false), Division, Department, Team, Role, Position ] 총 6개의 마디로 되어있다.
continue
}
org := Organization{}
if parts[0] == "true" {
org.Primary = true
} else {
org.Primary = false
}
if parts[1] != "unknown" {
division, err := getDivisionV2(client, parts[1])
if err != nil {
return results, err
}
org.Division = division
}
if parts[2] != "unknown" {
department, err := getDepartmentV2(client, parts[2])
if err != nil {
return results, err
}
org.Department = department
}
if parts[3] != "unknown" {
team, err := getTeamV2(client, parts[3])
if err != nil {
return results, err
}
org.Team = team
}
if parts[4] != "unknown" {
role, err := getRoleV2(client, parts[4])
if err != nil {
return results, err
}
org.Role = role
}
if parts[5] != "unknown" {
position, err := getPositionV2(client, parts[5])
if err != nil {
return results, err
}
org.Position = position
}
results = append(results, org)
}
return results, nil
}