@@ -92,7 +92,7 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
92
92
}
93
93
st , err := time .Parse (time .RFC3339 , body .StartTime )
94
94
if err != nil {
95
- mock_errors .WriteBadRequest (w , "Invalid timezone provided" )
95
+ mock_errors .WriteBadRequest (w , "Invalid/malformed start_time provided" )
96
96
return
97
97
}
98
98
if body .Timezone == "" {
@@ -104,9 +104,13 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
104
104
mock_errors .WriteBadRequest (w , "Invalid timezone provided" )
105
105
return
106
106
}
107
+
108
+ var isRecurring bool
109
+
107
110
if body .IsRecurring == nil {
108
- mock_errors .WriteBadRequest (w , "Missing is_recurring" )
109
- return
111
+ isRecurring = false
112
+ } else {
113
+ isRecurring = * body .IsRecurring
110
114
}
111
115
112
116
if len (body .Title ) > 140 {
@@ -129,7 +133,7 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
129
133
ID : eventID ,
130
134
StartTime : st .UTC ().Format (time .RFC3339 ),
131
135
EndTime : et .UTC ().Format (time .RFC3339 ),
132
- IsRecurring : * body . IsRecurring ,
136
+ IsRecurring : isRecurring ,
133
137
IsVacation : false ,
134
138
CategoryID : body .CategoryID ,
135
139
Title : body .Title ,
@@ -142,7 +146,7 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
142
146
mock_errors .WriteServerError (w , err .Error ())
143
147
return
144
148
}
145
- if * body . IsRecurring {
149
+ if isRecurring {
146
150
// just a years worth of recurring events; mock data
147
151
for i := 0 ; i < 52 ; i ++ {
148
152
weekAdd := (i + 1 ) * 7 * 24
@@ -154,7 +158,7 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
154
158
ID : eventID ,
155
159
StartTime : startTime .Format (time .RFC3339 ),
156
160
EndTime : endTime .Format (time .RFC3339 ),
157
- IsRecurring : * body . IsRecurring ,
161
+ IsRecurring : isRecurring ,
158
162
IsVacation : false ,
159
163
CategoryID : body .CategoryID ,
160
164
Title : body .Title ,
@@ -176,6 +180,16 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
176
180
return
177
181
}
178
182
b := dbr .Data .(database.Schedule )
183
+
184
+ // Remove timezone from JSON given in response
185
+ for i := range b .Segments {
186
+ b .Segments [i ].Timezone = ""
187
+ }
188
+
189
+ if b .Vacation .StartTime == "" && b .Vacation .EndTime == "" {
190
+ b .Vacation = nil
191
+ }
192
+
179
193
bytes , _ := json .Marshal (b )
180
194
w .Write (bytes )
181
195
}
@@ -314,6 +328,16 @@ func (e ScheduleSegment) patchSegment(w http.ResponseWriter, r *http.Request) {
314
328
return
315
329
}
316
330
b = dbr .Data .(database.Schedule )
331
+
332
+ // Remove timezone from JSON given in response
333
+ for i := range b .Segments {
334
+ b .Segments [i ].Timezone = ""
335
+ }
336
+
337
+ if b .Vacation .StartTime == "" && b .Vacation .EndTime == "" {
338
+ b .Vacation = nil
339
+ }
340
+
317
341
bytes , _ := json .Marshal (b )
318
342
w .Write (bytes )
319
343
}
0 commit comments