fix: return 400 for unknown calendar provider instead of silently using Google
This commit is contained in:
parent
3a42a01ebb
commit
dacd8bc082
1 changed files with 16 additions and 6 deletions
|
|
@ -141,9 +141,14 @@ namespace ShiftScheduler.Server.Controllers
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ICalendarService service = provider == "nextcloud"
|
ICalendarService service = provider switch
|
||||||
? _nextcloudCalendarService
|
{
|
||||||
: _googleCalendarService;
|
"google" => (ICalendarService)_googleCalendarService,
|
||||||
|
"nextcloud" => _nextcloudCalendarService,
|
||||||
|
_ => null!
|
||||||
|
};
|
||||||
|
if (service is null)
|
||||||
|
return BadRequest($"Unknown provider '{provider}'. Supported values: google, nextcloud.");
|
||||||
|
|
||||||
var calendars = await service.GetCalendarsAsync();
|
var calendars = await service.GetCalendarsAsync();
|
||||||
return Ok(calendars);
|
return Ok(calendars);
|
||||||
|
|
@ -161,9 +166,14 @@ namespace ShiftScheduler.Server.Controllers
|
||||||
{
|
{
|
||||||
var shiftsWithTransport = await BuildShiftsWithTransportAsync(request.Year, request.Month);
|
var shiftsWithTransport = await BuildShiftsWithTransportAsync(request.Year, request.Month);
|
||||||
|
|
||||||
ICalendarService service = request.Provider == "nextcloud"
|
ICalendarService service = request.Provider switch
|
||||||
? _nextcloudCalendarService
|
{
|
||||||
: _googleCalendarService;
|
"google" => (ICalendarService)_googleCalendarService,
|
||||||
|
"nextcloud" => _nextcloudCalendarService,
|
||||||
|
_ => null!
|
||||||
|
};
|
||||||
|
if (service is null)
|
||||||
|
return BadRequest($"Unknown provider '{request.Provider}'. Supported values: google, nextcloud.");
|
||||||
|
|
||||||
await service.SyncShiftsToCalendarAsync(request.CalendarId, shiftsWithTransport);
|
await service.SyncShiftsToCalendarAsync(request.CalendarId, shiftsWithTransport);
|
||||||
return Ok(new { message = "Shifts synced successfully!" });
|
return Ok(new { message = "Shifts synced successfully!" });
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue