@@ -84,7 +84,7 @@ func (a *Affiliation) AddIdentity(identity *Identity) bool {
8484 queryParams ["email" ] = identity .Email
8585 queryParams ["uuid" ] = identity .UUID
8686
87- endpoint := a .AffBaseURL + "/affiliation/" + url .PathEscape (a .ProjectSlug )+ "/add_identity/" + url .PathEscape (identity .Source )
87+ endpoint := a .AffBaseURL + "/affiliation/" + url .PathEscape (a .ProjectSlug ) + "/add_identity/" + url .PathEscape (identity .Source )
8888 _ , res , err := a .httpClient .Request (strings .TrimSpace (endpoint ), "POST" , headers , nil , queryParams )
8989 if err != nil {
9090 log .Println ("Repository: AddIdentity: Could not insert the identity: " , err )
@@ -99,6 +99,96 @@ func (a *Affiliation) AddIdentity(identity *Identity) bool {
9999 return true
100100}
101101
102+ // GetIdentity ...
103+ func (a * Affiliation ) GetIdentity (uuid string ) * Identity {
104+ if uuid == "" {
105+ log .Println ("GetIdentity: uuid is empty" )
106+ return nil
107+ }
108+ token , err := a .auth0Client .ValidateToken (a .Environment )
109+ if err != nil {
110+ log .Println (err )
111+ }
112+ headers := make (map [string ]string , 0 )
113+ headers ["Content-type" ] = "application/json"
114+ headers ["Authorization" ] = fmt .Sprintf ("%s %s" , "Bearer" , token )
115+
116+ endpoint := a .AffBaseURL + "/affiliation/get_identity/" + uuid
117+
118+ _ , res , err := a .httpClient .Request (strings .TrimSpace (endpoint ), "GET" , headers , nil , nil )
119+ if err != nil {
120+ log .Println ("GetIdentity: Could not get the identity: " , err )
121+ return nil
122+ }
123+ var identity Identity
124+ err = json .Unmarshal (res , & identity )
125+ if err != nil {
126+ log .Println ("GetIdentity: failed to unmarshal identity: " , err )
127+ return nil
128+ }
129+ return & identity
130+ }
131+
132+ // GetOrganizations ...
133+ func (a * Affiliation ) GetOrganizations (uuid , projectSlug string ) * []Enrollment {
134+ if uuid == "" || projectSlug == "" {
135+ return nil
136+ }
137+ token , err := a .auth0Client .ValidateToken (a .Environment )
138+ if err != nil {
139+ log .Println (err )
140+ }
141+ headers := make (map [string ]string , 0 )
142+ headers ["Content-type" ] = "application/json"
143+ headers ["Authorization" ] = fmt .Sprintf ("%s %s" , "Bearer" , token )
144+
145+ endpoint := a .AffBaseURL + "/affiliation/" + url .PathEscape (projectSlug ) + "/enrollments/" + uuid
146+
147+ _ , res , err := a .httpClient .Request (strings .TrimSpace (endpoint ), "GET" , headers , nil , nil )
148+ if err != nil {
149+ log .Println ("GetOrganizations: Could not get the organizations: " , err )
150+ return nil
151+ }
152+
153+ var response EnrollmentsResponse
154+ err = json .Unmarshal (res , & response )
155+ if err != nil {
156+ log .Println ("GetOrganizations: failed to unmarshal enrollments response: " , err )
157+ return nil
158+ }
159+ return & response .Enrollments
160+ }
161+
162+ // GetProfile ...
163+ func (a * Affiliation ) GetProfile (uuid , projectSlug string ) * ProfileResponse {
164+ if uuid == "" || projectSlug == "" {
165+ return nil
166+ }
167+ token , err := a .auth0Client .ValidateToken (a .Environment )
168+ if err != nil {
169+ log .Println (err )
170+ }
171+ headers := make (map [string ]string , 0 )
172+ headers ["Content-type" ] = "application/json"
173+ headers ["Authorization" ] = fmt .Sprintf ("%s %s" , "Bearer" , token )
174+
175+ endpoint := a .AffBaseURL + "/affiliation/" + url .PathEscape (projectSlug ) + "/get_profile/" + uuid
176+
177+ _ , res , err := a .httpClient .Request (strings .TrimSpace (endpoint ), "GET" , headers , nil , nil )
178+ if err != nil {
179+ log .Println ("GetProfile: Could not get the profile: " , err )
180+ return nil
181+ }
182+
183+ var response ProfileResponse
184+ err = json .Unmarshal (res , & response )
185+ if err != nil {
186+ log .Println ("GetProfile: failed to unmarshal profile response: " , err )
187+ return nil
188+ }
189+ return & response
190+ }
191+
102192func buildServices (a * Affiliation ) (httpClientProvider * http.ClientProvider , esClientProvider * elastic.ClientProvider , auth0ClientProvider * auth0.ClientProvider , err error ) {
103193 esClientProvider , err = elastic .NewClientProvider (& elastic.Params {
104194 URL : a .ESCacheURL ,
0 commit comments