/
service.go
122 lines (108 loc) · 3.44 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package talent
import (
"context"
"github.com/jobsgowhere/jobsgowhere/internal/models"
)
type SeekingMode int
const (
Inactive SeekingMode = 0
Active SeekingMode = 1
)
func (h SeekingMode) String() string {
switch h {
case Inactive:
return "Inactive"
case Active:
return "Active"
}
return ""
}
// Service is used to facilitate all otp related activities for any request
type Service interface {
GetTalentByID(ctx context.Context, talentID string) (Talent, error)
GetTalents(ctx context.Context, pageNumber int, itemsPerPage int) ([]Talent, error)
CreateTalent(ctx context.Context, iamID string, params TalentParams) (Talent, error)
UpdateTalentByID(ctx context.Context, iamID string, talentID string, params TalentParams) (Talent, error)
DeleteTalentByID(ctx context.Context, iamID string, talentID string) error
SearchTalents(ctx context.Context, searchText string) ([]Talent, error)
}
// talent service struct
type talentService struct {
repo Repository
}
func (j *talentService) GetTalents(ctx context.Context, pageNumber int, itemsPerPage int) ([]Talent, error) {
talents, err := j.repo.GetTalents(ctx, pageNumber, itemsPerPage)
if err != nil {
return nil, err
}
var talentObjs []Talent
for _, talent := range talents {
talentObj := convert(talent)
talentObjs = append(talentObjs, talentObj)
}
return talentObjs, nil
}
func (j *talentService) SearchTalents(ctx context.Context, searchText string) ([]Talent, error) {
talents, err := j.repo.SearchTalents(ctx, searchText)
if err != nil {
return nil, err
}
var talentObjs []Talent
for _, talent := range talents {
talentObj := convert(talent)
talentObjs = append(talentObjs, talentObj)
}
return talentObjs, nil
}
func (j *talentService) GetTalentByID(ctx context.Context, talentID string) (Talent, error) {
talent, err := j.repo.GetTalentByID(ctx, talentID)
if err != nil {
return Talent{}, err
}
talentObj := convert(talent)
return talentObj, nil
}
func (j *talentService) CreateTalent(ctx context.Context, iamID string, params TalentParams) (Talent, error) {
talent, err := j.repo.CreateTalent(ctx, iamID, params)
if err != nil {
return Talent{}, err
}
talentObj := convert(talent)
return talentObj, nil
}
func (j *talentService) UpdateTalentByID(ctx context.Context, iamID string, talentID string, params TalentParams) (Talent, error) {
talent, err := j.repo.UpdateTalentByID(ctx, iamID, talentID, params)
if err != nil {
return Talent{}, err
}
talentObj := convert(talent)
return talentObj, nil
}
func (j *talentService) DeleteTalentByID(ctx context.Context, iamID string, talentID string) error {
if err := j.repo.DeleteTalentByID(ctx, iamID, talentID); err != nil {
return err
}
return nil
}
func convert(talent *models.JobSeeker) Talent {
return Talent{
ID: talent.ID,
Title: talent.Title,
Description: talent.Headline.String,
Website: talent.R.Person.R.PersonProfiles[0].Website.String,
City: talent.City.String,
CreatedAt: talent.CreatedAt,
CreatedBy: User{
ID: talent.R.Person.ID,
FirstName: talent.R.Person.FirstName.String,
LastName: talent.R.Person.LastName.String,
AvatarUrl: talent.R.Person.AvatarURL.String,
JobTitle: talent.R.Person.R.PersonProfiles[0].Headline.String,
Company: talent.R.Person.R.PersonProfiles[0].Company.String,
Profile: UserProfile{
LinkedIn: talent.R.Person.R.PersonProfiles[0].ProfileURL,
},
SeekingMode: SeekingMode(talent.SeekingMode.Int).String(),
},
}
}