@@ -278,6 +278,37 @@ type CalendarEventListRequestFilters struct {
278278 Limit int64
279279}
280280
281+ func (c CalendarEventListRequestFilters ) apply (req * http.Request ) {
282+ query := req .URL .Query ()
283+ if ! c .StartedAfterDate .IsZero () {
284+ query .Set ("startedAfterDate" , c .StartedAfterDate .String ())
285+ }
286+ if ! c .EndedBeforeDate .IsZero () {
287+ query .Set ("endedBeforeDate" , c .EndedBeforeDate .String ())
288+ }
289+ if len (c .Include ) > 0 {
290+ for _ , include := range c .Include {
291+ query .Add ("include" , string (include ))
292+ }
293+ }
294+ if c .Cursor != "" {
295+ query .Set ("cursor" , c .Cursor )
296+ }
297+ if c .Limit > 0 {
298+ query .Set ("limit" , strconv .FormatInt (c .Limit , 10 ))
299+ }
300+ // hardcoded filters to simplify API usage
301+ query .Set ("includeMasterInstances" , "false" )
302+ query .Set ("showDeletedInstances" , "false" )
303+ query .Set ("includeInstances" , "true" )
304+ query .Set ("includeOngoingEvents" , "true" )
305+ query .Set ("includeDeletedInstances" , "false" )
306+ query .Set ("includeModifiedInstances" , "true" )
307+ query .Set ("includeTimelogs" , "false" )
308+
309+ req .URL .RawQuery = query .Encode ()
310+ }
311+
281312// CalendarEventListRequest represents the request for loading calendar events.
282313//
283314// https://apidocs.teamwork.com/docs/teamwork/v3/calendar-events/get-projects-api-v3-calendars-calendar-id-events-json
@@ -310,35 +341,8 @@ func (c CalendarEventListRequest) HTTPRequest(ctx context.Context, server string
310341 if err != nil {
311342 return nil , err
312343 }
344+ c .Filters .apply (req )
313345
314- query := req .URL .Query ()
315- if ! c .Filters .StartedAfterDate .IsZero () {
316- query .Set ("startedAfterDate" , c .Filters .StartedAfterDate .String ())
317- }
318- if ! c .Filters .EndedBeforeDate .IsZero () {
319- query .Set ("endedBeforeDate" , c .Filters .EndedBeforeDate .String ())
320- }
321- if len (c .Filters .Include ) > 0 {
322- for _ , include := range c .Filters .Include {
323- query .Add ("include" , string (include ))
324- }
325- }
326- if c .Filters .Cursor != "" {
327- query .Set ("cursor" , c .Filters .Cursor )
328- }
329- if c .Filters .Limit > 0 {
330- query .Set ("limit" , strconv .FormatInt (c .Filters .Limit , 10 ))
331- }
332- // hardcoded filters to simplify API usage
333- query .Set ("includeMasterInstances" , "false" )
334- query .Set ("showDeletedInstances" , "false" )
335- query .Set ("includeInstances" , "true" )
336- query .Set ("includeOngoingEvents" , "true" )
337- query .Set ("includeDeletedInstances" , "false" )
338- query .Set ("includeModifiedInstances" , "true" )
339- query .Set ("includeTimelogs" , "false" )
340-
341- req .URL .RawQuery = query .Encode ()
342346 return req , nil
343347}
344348
0 commit comments