Skip to content

Commit f41650c

Browse files
Merge pull request #7537 from nextcloud/fix/appointments/unify-ids
fix(appointments): unify IDs
2 parents 9826fff + 47084f0 commit f41650c

File tree

4 files changed

+55
-48
lines changed

4 files changed

+55
-48
lines changed

appinfo/routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
// Appointments
2222
['name' => 'appointment#index', 'url' => '/appointments/{userId}', 'verb' => 'GET'],
2323
['name' => 'appointment#show', 'url' => '/appointment/{token}', 'verb' => 'GET'],
24-
['name' => 'booking#getBookableSlots', 'url' => '/appointment/{appointmentConfigId}/slots', 'verb' => 'GET'],
25-
['name' => 'booking#bookSlot', 'url' => '/appointment/{appointmentConfigId}/book', 'verb' => 'POST'],
24+
['name' => 'booking#getBookableSlots', 'url' => '/appointment/{appointmentConfigToken}/slots', 'verb' => 'GET'],
25+
['name' => 'booking#bookSlot', 'url' => '/appointment/{appointmentConfigToken}/book', 'verb' => 'POST'],
2626
['name' => 'booking#confirmBooking', 'url' => '/appointment/confirm/{token}', 'verb' => 'GET'],
2727
// Public views
2828
['name' => 'publicView#public_index_with_branding', 'url' => '/p/{token}', 'verb' => 'GET'],

lib/Controller/BookingController.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ public function __construct(string $appName,
8080
* @NoAdminRequired
8181
* @PublicPage
8282
*
83-
* @param int $appointmentConfigId
83+
* @param string $appointmentConfigToken
8484
* @param int $startTime UNIX time stamp for the start time in UTC
8585
* @param string $timeZone
8686
*
8787
* @return JsonResponse
8888
*/
8989
public function getBookableSlots(
90-
int $appointmentConfigId,
90+
string $appointmentConfigToken,
9191
string $dateSelected,
9292
string $timeZone,
9393
): JsonResponse {
@@ -120,9 +120,9 @@ public function getBookableSlots(
120120
}
121121

122122
try {
123-
$config = $this->appointmentConfigService->findById($appointmentConfigId);
123+
$config = $this->appointmentConfigService->findByToken($appointmentConfigToken);
124124
} catch (ServiceException $e) {
125-
$this->logger->error('No appointment config found for id ' . $appointmentConfigId, ['exception' => $e]);
125+
$this->logger->error('No appointment config found for ' . $appointmentConfigToken, ['exception' => $e]);
126126
return JsonResponse::fail(null, Http::STATUS_NOT_FOUND);
127127
}
128128

@@ -135,7 +135,7 @@ public function getBookableSlots(
135135
* @NoAdminRequired
136136
* @PublicPage
137137
*
138-
* @param int $appointmentConfigId
138+
* @param string $appointmentConfigToken
139139
* @param int $start
140140
* @param int $end
141141
* @param string $displayName
@@ -149,7 +149,7 @@ public function getBookableSlots(
149149
*/
150150
#[AnonRateLimit(limit: 10, period: 1200)]
151151
#[UserRateLimit(limit: 10, period: 300)]
152-
public function bookSlot(int $appointmentConfigId,
152+
public function bookSlot(string $appointmentConfigToken,
153153
int $start,
154154
int $end,
155155
string $displayName,
@@ -165,15 +165,15 @@ public function bookSlot(int $appointmentConfigId,
165165
}
166166

167167
try {
168-
$config = $this->appointmentConfigService->findById($appointmentConfigId);
168+
$config = $this->appointmentConfigService->findByToken($appointmentConfigToken);
169169
} catch (ServiceException $e) {
170-
$this->logger->error('No appointment config found for id ' . $appointmentConfigId, ['exception' => $e]);
170+
$this->logger->error('No appointment config found for token ' . $appointmentConfigToken, ['exception' => $e]);
171171
return JsonResponse::fail(null, Http::STATUS_NOT_FOUND);
172172
}
173173
try {
174174
$booking = $this->bookingService->book($config, $start, $end, $timeZone, $displayName, $email, $description);
175175
} catch (NoSlotFoundException $e) {
176-
$this->logger->warning('No slot available for start: ' . $start . ', end: ' . $end . ', config id: ' . $appointmentConfigId, ['exception' => $e]);
176+
$this->logger->warning('No slot available for start: ' . $start . ', end: ' . $end . ', config token: ' . $appointmentConfigToken, ['exception' => $e]);
177177
return JsonResponse::fail(null, Http::STATUS_NOT_FOUND);
178178
} catch (InvalidArgumentException $e) {
179179
$this->logger->warning($e->getMessage(), ['exception' => $e]);

src/services/appointmentService.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { generateUrl } from '@nextcloud/router'
1212
* @param timeZone {String} target time zone for the time stamps
1313
*/
1414
export async function findSlots(config, date, timeZone) {
15-
const url = generateUrl('/apps/calendar/appointment/{id}/slots?dateSelected={date}&timeZone={timeZone}', {
16-
id: config.id,
15+
const url = generateUrl('/apps/calendar/appointment/{token}/slots?dateSelected={date}&timeZone={timeZone}', {
16+
token: config.token,
1717
date,
1818
timeZone,
1919
})
@@ -32,8 +32,8 @@ export async function findSlots(config, date, timeZone) {
3232
* @param timeZone
3333
*/
3434
export async function bookSlot(config, slot, displayName, email, description, timeZone) {
35-
const url = generateUrl('/apps/calendar/appointment/{id}/book', {
36-
id: config.id,
35+
const url = generateUrl('/apps/calendar/appointment/{token}/book', {
36+
token: config.token,
3737
})
3838

3939
const response = await axios.post(url, {

tests/php/unit/Controller/BookingControllerTest.php

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -114,53 +114,56 @@ public function testGetBookableSlots(): void {
114114

115115
$apptConfg = new AppointmentConfig();
116116
$apptConfg->setId(1);
117+
$apptConfg->setToken('abc123');
117118
$this->time->expects(self::once())
118119
->method('getTime')
119120
->willReturn($currentDate);
120121
$this->apptService->expects(self::once())
121-
->method('findById')
122-
->with(1)
122+
->method('findByToken')
123+
->with($apptConfg->getToken())
123124
->willReturn($apptConfg);
124125
$this->bookingService->expects(self::once())
125126
->method('getAvailableSlots')
126127
->with($apptConfg, $sDT, $eDT);
127128

128-
$this->controller->getBookableSlots($apptConfg->getId(), $selectedDate, $selectedTz);
129+
$this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, $selectedTz);
129130
}
130131

131132
public function testGetBookableSlotsDatesInPast(): void {
132133
$currentDate = (new DateTime('2024-7-2'))->getTimestamp();
133134
$selectedDate = '2024-7-1';
134135
$apptConfg = new AppointmentConfig();
135136
$apptConfg->setId(1);
137+
$apptConfg->setToken('abc123');
136138
$this->time->expects(self::once())
137139
->method('getTime')
138140
->willReturn($currentDate);
139141
$this->apptService->expects(self::never())
140-
->method('findById')
141-
->with(1);
142+
->method('findByToken')
143+
->with($apptConfg->getToken());
142144
$this->bookingService->expects(self::never())
143145
->method('getAvailableSlots');
144146
$this->logger->expects(self::once())
145147
->method('warning');
146148

147-
$this->controller->getBookableSlots($apptConfg->getId(), $selectedDate, 'Europe/Berlin');
149+
$this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, 'Europe/Berlin');
148150
}
149151

150152
public function testGetBookableSlotsInvalidTimezone(): void {
151153
$selectedDate = '2024-7-1';
152154
$apptConfg = new AppointmentConfig();
153155
$apptConfg->setId(1);
156+
$apptConfg->setToken('abc123');
154157
$this->time->expects(self::never())
155158
->method('getTime');
156159
$this->apptService->expects(self::never())
157-
->method('findById')
158-
->with(1);
160+
->method('findByToken')
161+
->with($apptConfg->getToken());
159162
$this->bookingService->expects(self::never())
160163
->method('getAvailableSlots');
161164
$this->expectException(Exception::class);
162165

163-
$this->controller->getBookableSlots($apptConfg->getId(), $selectedDate, 'Hook/Neverland');
166+
$this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, 'Hook/Neverland');
164167
}
165168

166169
public function testGetBookableSlotsTimezoneIdentical(): void {
@@ -173,18 +176,19 @@ public function testGetBookableSlotsTimezoneIdentical(): void {
173176

174177
$apptConfg = new AppointmentConfig();
175178
$apptConfg->setId(1);
179+
$apptConfg->setToken('abc123');
176180
$this->time->expects(self::once())
177181
->method('getTime')
178182
->willReturn($currentDate);
179183
$this->apptService->expects(self::once())
180-
->method('findById')
181-
->with(1)
184+
->method('findByToken')
185+
->with($apptConfg->getToken())
182186
->willReturn($apptConfg);
183187
$this->bookingService->expects(self::once())
184188
->method('getAvailableSlots')
185189
->with($apptConfg, $sDT, $eDT);
186190

187-
$this->controller->getBookableSlots($apptConfg->getId(), $selectedDate, $selectedTz);
191+
$this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, $selectedTz);
188192
}
189193

190194
public function testGetBookableSlotsTimezoneMinus10(): void {
@@ -197,18 +201,19 @@ public function testGetBookableSlotsTimezoneMinus10(): void {
197201

198202
$apptConfg = new AppointmentConfig();
199203
$apptConfg->setId(1);
204+
$apptConfg->setToken('abc123');
200205
$this->time->expects(self::once())
201206
->method('getTime')
202207
->willReturn($currentDate);
203208
$this->apptService->expects(self::once())
204-
->method('findById')
205-
->with(1)
209+
->method('findByToken')
210+
->with($apptConfg->getToken())
206211
->willReturn($apptConfg);
207212
$this->bookingService->expects(self::once())
208213
->method('getAvailableSlots')
209214
->with($apptConfg, $sDT, $eDT);
210215

211-
$this->controller->getBookableSlots($apptConfg->getId(), $selectedDate, $timezone);
216+
$this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, $timezone);
212217
}
213218

214219
public function testGetBookableSlotsTimezonePlus10(): void {
@@ -221,18 +226,19 @@ public function testGetBookableSlotsTimezonePlus10(): void {
221226

222227
$apptConfg = new AppointmentConfig();
223228
$apptConfg->setId(1);
229+
$apptConfg->setToken('abc123');
224230
$this->time->expects(self::once())
225231
->method('getTime')
226232
->willReturn($currentDate);
227233
$this->apptService->expects(self::once())
228-
->method('findById')
229-
->with(1)
234+
->method('findByToken')
235+
->with($apptConfg->getToken())
230236
->willReturn($apptConfg);
231237
$this->bookingService->expects(self::once())
232238
->method('getAvailableSlots')
233239
->with($apptConfg, $sDT, $eDT);
234240

235-
$this->controller->getBookableSlots($apptConfg->getId(), $selectedDate, $timezone);
241+
$this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, $timezone);
236242
}
237243

238244
public function testGetBookableSlotsTimezonePlus14(): void {
@@ -245,18 +251,19 @@ public function testGetBookableSlotsTimezonePlus14(): void {
245251

246252
$apptConfg = new AppointmentConfig();
247253
$apptConfg->setId(1);
254+
$apptConfg->setToken('abc123');
248255
$this->time->expects(self::once())
249256
->method('getTime')
250257
->willReturn($currentDate);
251258
$this->apptService->expects(self::once())
252-
->method('findById')
253-
->with(1)
259+
->method('findByToken')
260+
->with($apptConfg->getToken())
254261
->willReturn($apptConfg);
255262
$this->bookingService->expects(self::once())
256263
->method('getAvailableSlots')
257264
->with($apptConfg, $sDT, $eDT);
258265

259-
$this->controller->getBookableSlots($apptConfg->getId(), $selectedDate, $timezone);
266+
$this->controller->getBookableSlots($apptConfg->getToken(), $selectedDate, $timezone);
260267
}
261268

262269
public function testBook(): void {
@@ -268,14 +275,14 @@ public function testBook(): void {
268275
->with($email)
269276
->willReturn(true);
270277
$this->apptService->expects(self::once())
271-
->method('findById')
278+
->method('findByToken')
272279
->willReturn($config);
273280
$this->bookingService->expects(self::once())
274281
->method('book')
275282
->with($config, 1, 1, 'Hook/Neverland', 'Test', $email, 'Test')
276283
->willReturn(new Booking());
277284

278-
$this->controller->bookSlot(1, 1, 1, 'Test', $email, 'Test', 'Hook/Neverland');
285+
$this->controller->bookSlot('abc123', 1, 1, 'Test', $email, 'Test', 'Hook/Neverland');
279286
}
280287

281288

@@ -288,14 +295,14 @@ public function testBookInvalidTimeZone(): void {
288295
->with($email)
289296
->willReturn(true);
290297
$this->apptService->expects(self::once())
291-
->method('findById')
298+
->method('findByToken')
292299
->willReturn($config);
293300
$this->bookingService->expects(self::once())
294301
->method('book')
295302
->with($config, 1, 1, 'Hook/Neverland', 'Test', $email, 'Test')
296303
->willThrowException(new InvalidArgumentException());
297304

298-
$this->controller->bookSlot(1, 1, 1, 'Test', $email, 'Test', 'Hook/Neverland');
305+
$this->controller->bookSlot('abc123', 1, 1, 'Test', $email, 'Test', 'Hook/Neverland');
299306
}
300307

301308
public function testBookInvalidSlot(): void {
@@ -307,14 +314,14 @@ public function testBookInvalidSlot(): void {
307314
->with($email)
308315
->willReturn(true);
309316
$this->apptService->expects(self::once())
310-
->method('findById')
317+
->method('findByToken')
311318
->willReturn($config);
312319
$this->bookingService->expects(self::once())
313320
->method('book')
314321
->with($config, 1, 1, 'Europe/Berlin', 'Test', $email, 'Test')
315322
->willThrowException(new NoSlotFoundException());
316323

317-
$this->controller->bookSlot(1, 1, 1, 'Test', $email, 'Test', 'Europe/Berlin');
324+
$this->controller->bookSlot('abc123', 1, 1, 'Test', $email, 'Test', 'Europe/Berlin');
318325
}
319326

320327
public function testBookInvalidBooking(): void {
@@ -326,7 +333,7 @@ public function testBookInvalidBooking(): void {
326333
->with($email)
327334
->willReturn(true);
328335
$this->apptService->expects(self::once())
329-
->method('findById')
336+
->method('findByToken')
330337
->willReturn($config);
331338
$this->bookingService->expects(self::once())
332339
->method('book')
@@ -337,7 +344,7 @@ public function testBookInvalidBooking(): void {
337344
->with('debug')
338345
->willReturn(false);
339346

340-
$this->controller->bookSlot(1, 1, 1, 'Test', $email, 'Test', 'Europe/Berlin');
347+
$this->controller->bookSlot('abc123', 1, 1, 'Test', $email, 'Test', 'Europe/Berlin');
341348
}
342349

343350
public function testBookInvalidId(): void {
@@ -347,12 +354,12 @@ public function testBookInvalidId(): void {
347354
->with($email)
348355
->willReturn(true);
349356
$this->apptService->expects(self::once())
350-
->method('findById')
357+
->method('findByToken')
351358
->willThrowException(new ServiceException());
352359
$this->bookingService->expects(self::never())
353360
->method('book');
354361

355-
$this->controller->bookSlot(1, 1, 1, 'Test', $email, 'Test', 'Europe/Berlin');
362+
$this->controller->bookSlot('abc123', 1, 1, 'Test', $email, 'Test', 'Europe/Berlin');
356363
}
357364

358365

@@ -364,10 +371,10 @@ public function testBookInvalidEmail(): void {
364371
->with($email)
365372
->willReturn(false);
366373
$this->apptService->expects(self::never())
367-
->method('findById');
374+
->method('findByToken');
368375
$this->bookingService->expects(self::never())
369376
->method('book');
370377

371-
$this->controller->bookSlot(1, 1, 1, 'Test', $email, 'Test', 'Europe/Berlin');
378+
$this->controller->bookSlot('abc123', 1, 1, 'Test', $email, 'Test', 'Europe/Berlin');
372379
}
373380
}

0 commit comments

Comments
 (0)