@@ -90,13 +90,7 @@ func (c clubsService) GetClubActivitiesById(ctx context.Context, id int64, opts
9090 return nil , err
9191 }
9292
93- resp := make ([]models.ClubActivity , 0 , len (activities .GetPayload ()))
94-
95- for _ , a := range activities .GetPayload () {
96- resp = append (resp , * a )
97- }
98-
99- return resp , nil
93+ return convertToListClubActivity (activities .GetPayload ()), nil
10094}
10195
10296func (c clubsService ) GetClubAdminsById (ctx context.Context , id int64 , opts ... GetClubAdminsByIdOpts ) ([]models.SummaryAthlete , error ) {
@@ -129,13 +123,7 @@ func (c clubsService) GetClubAdminsById(ctx context.Context, id int64, opts ...G
129123 return nil , err
130124 }
131125
132- resp := make ([]models.SummaryAthlete , 0 , len (admins .GetPayload ()))
133-
134- for _ , a := range admins .GetPayload () {
135- resp = append (resp , * a )
136- }
137-
138- return resp , nil
126+ return convertToListSummaryAthlete (admins .GetPayload ()), nil
139127}
140128
141129func (c clubsService ) GetClubById (ctx context.Context , id int64 ) (models.DetailedClub , error ) {
@@ -150,7 +138,7 @@ func (c clubsService) GetClubById(ctx context.Context, id int64) (models.Detaile
150138 return models.DetailedClub {}, err
151139 }
152140
153- return * club .GetPayload (), nil
141+ return convertToDetailedClub ( club .GetPayload () ), nil
154142}
155143
156144func (c clubsService ) GetClubMembersById (ctx context.Context , id int64 , opts ... GetClubMembersByIdOpts ) ([]models.ClubAthlete , error ) {
@@ -183,13 +171,7 @@ func (c clubsService) GetClubMembersById(ctx context.Context, id int64, opts ...
183171 return nil , err
184172 }
185173
186- resp := make ([]models.ClubAthlete , 0 , len (members .GetPayload ()))
187-
188- for _ , m := range members .GetPayload () {
189- resp = append (resp , * m )
190- }
191-
192- return resp , nil
174+ return convertToListClubAthlete (members .GetPayload ()), nil
193175}
194176
195177func (c clubsService ) GetLoggedInAthleteClubs (ctx context.Context , opts ... GetLoggedInAthleteClubsOpts ) ([]models.SummaryClub , error ) {
@@ -221,11 +203,101 @@ func (c clubsService) GetLoggedInAthleteClubs(ctx context.Context, opts ...GetLo
221203 return nil , err
222204 }
223205
224- resp := make ([]models.SummaryClub , 0 , len (list .GetPayload ()))
206+ return convertToListSummaryClub (list .GetPayload ()), nil
207+ }
208+
209+ func convertToClubActivity (activity * models.ClubActivity ) models.ClubActivity {
210+ if activity == nil {
211+ return models.ClubActivity {}
212+ }
213+
214+ return * activity
215+ }
216+
217+ func convertToSummaryAthlete (athlete * models.SummaryAthlete ) models.SummaryAthlete {
218+ if athlete == nil {
219+ return models.SummaryAthlete {}
220+ }
221+
222+ return * athlete
223+ }
224+
225+ func convertToClubAthlete (athlete * models.ClubAthlete ) models.ClubAthlete {
226+ if athlete == nil {
227+ return models.ClubAthlete {}
228+ }
229+
230+ return * athlete
231+ }
232+
233+ func convertToSummaryClub (club * models.SummaryClub ) models.SummaryClub {
234+ if club == nil {
235+ return models.SummaryClub {}
236+ }
237+
238+ return * club
239+ }
240+
241+ func convertToDetailedClub (club * models.DetailedClub ) models.DetailedClub {
242+ if club == nil {
243+ return models.DetailedClub {}
244+ }
245+
246+ return * club
247+ }
248+
249+ func convertToListSummaryClub (clubs []* models.SummaryClub ) []models.SummaryClub {
250+ if clubs == nil {
251+ return nil
252+ }
253+
254+ list := make ([]models.SummaryClub , len (clubs ))
255+
256+ for i , club := range clubs {
257+ list [i ] = convertToSummaryClub (club )
258+ }
259+
260+ return list
261+ }
262+
263+ func convertToListClubActivity (activities []* models.ClubActivity ) []models.ClubActivity {
264+ if activities == nil {
265+ return nil
266+ }
267+
268+ list := make ([]models.ClubActivity , len (activities ))
269+
270+ for i , activity := range activities {
271+ list [i ] = convertToClubActivity (activity )
272+ }
273+
274+ return list
275+ }
276+
277+ func convertToListClubAthlete (athletes []* models.ClubAthlete ) []models.ClubAthlete {
278+ if athletes == nil {
279+ return nil
280+ }
281+
282+ list := make ([]models.ClubAthlete , len (athletes ))
283+
284+ for i , athlete := range athletes {
285+ list [i ] = convertToClubAthlete (athlete )
286+ }
287+
288+ return list
289+ }
290+
291+ func convertToListSummaryAthlete (athletes []* models.SummaryAthlete ) []models.SummaryAthlete {
292+ if athletes == nil {
293+ return nil
294+ }
295+
296+ list := make ([]models.SummaryAthlete , len (athletes ))
225297
226- for _ , cl := range list . GetPayload () {
227- resp = append ( resp , * cl )
298+ for i , athlete := range athletes {
299+ list [ i ] = convertToSummaryAthlete ( athlete )
228300 }
229301
230- return resp , nil
302+ return list
231303}
0 commit comments