Standardize the Status responses for APIs.
This commit is contained in:
parent
dcbc08360c
commit
a35e8bf27d
|
@ -92,7 +92,7 @@ abstract class AbstractAdminApiCrudController extends AbstractApiCrudController
|
|||
|
||||
$this->editRecord((array)$request->getParsedBody(), $record);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Changes saved successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -111,6 +111,6 @@ abstract class AbstractAdminApiCrudController extends AbstractApiCrudController
|
|||
|
||||
$this->deleteRecord($record);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Record deleted successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,6 @@ class DeleteCustomAssetAction
|
|||
|
||||
$customAsset->delete();
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::success());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,6 @@ class PostCustomAssetAction
|
|||
|
||||
$customAsset->upload($image);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::success());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,6 +178,6 @@ class RelaysController
|
|||
|
||||
$this->em->flush();
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::success());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,6 +75,6 @@ class SettingsController extends AbstractApiCrudController
|
|||
$settings = $this->settingsRepo->readSettings();
|
||||
$this->editRecord((array)$request->getParsedBody(), $settings);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::success());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,6 +118,6 @@ class UsersController extends AbstractAdminApiCrudController
|
|||
|
||||
$this->deleteRecord($record);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Record deleted successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,6 +21,6 @@ class PutMeAction extends UsersController
|
|||
$user = $request->getUser();
|
||||
$this->editRecord((array)$request->getParsedBody(), $user);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Changes saved successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ abstract class AbstractStationApiCrudController extends AbstractApiCrudControlle
|
|||
|
||||
$this->editRecord((array)$request->getParsedBody(), $record);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Changes saved successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -167,6 +167,6 @@ abstract class AbstractStationApiCrudController extends AbstractApiCrudControlle
|
|||
|
||||
$this->deleteRecord($record);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Record deleted successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,6 @@ class DeleteArtAction
|
|||
|
||||
$mediaRepo->removeAlbumArt($media);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,6 @@ class PostArtAction
|
|||
);
|
||||
$em->flush();
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,6 +85,6 @@ class FlowUploadAction
|
|||
$em->persist($mediaStorage);
|
||||
$em->flush();
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::created());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,6 @@ class MakeDirectoryAction
|
|||
->withJson(new Entity\Api\Error(400, $e->getMessage()));
|
||||
}
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::created());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class RenameAction
|
|||
|
||||
// No-op if paths match
|
||||
if ($from === $to) {
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
$station = $request->getStation();
|
||||
|
@ -44,6 +44,6 @@ class RenameAction
|
|||
|
||||
$batchUtilities->handleRename($from, $to, $storageLocation, $fsMedia);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -292,7 +292,7 @@ class FilesController extends AbstractStationApiCrudController
|
|||
}
|
||||
}
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Changes saved successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
protected function createRecord(array $data, Entity\Station $station): object
|
||||
|
|
|
@ -27,6 +27,6 @@ class DeleteIntroAction
|
|||
|
||||
$mountRepo->clearIntro($mount);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class PostIntroAction
|
|||
|
||||
$mountRepo->setIntro($mount, $flowResponse);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
return $response->withJson($flowResponse);
|
||||
|
|
|
@ -176,7 +176,7 @@ class MountsController extends AbstractStationApiCrudController
|
|||
|
||||
$this->mountRepo->destroy($record);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Record deleted successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -83,6 +83,6 @@ class CloneAction extends AbstractPlaylistsAction
|
|||
|
||||
$this->em->flush();
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::created());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -257,7 +257,7 @@ class PodcastEpisodesController extends AbstractApiCrudController
|
|||
|
||||
$this->editRecord((array)$request->getParsedBody(), $podcast);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Changes saved successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
public function deleteAction(
|
||||
|
@ -276,7 +276,7 @@ class PodcastEpisodesController extends AbstractApiCrudController
|
|||
$fsStation = new StationFilesystems($station);
|
||||
$this->episodeRepository->delete($record, $fsStation->getPodcastsFilesystem());
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Record deleted successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,11 +37,6 @@ class DeleteArtAction
|
|||
$em->persist($podcast);
|
||||
$em->flush();
|
||||
|
||||
return $response->withJson(
|
||||
new Entity\Api\Status(
|
||||
true,
|
||||
__('Podcast artwork successfully cleared.')
|
||||
)
|
||||
);
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class PostArtAction
|
|||
$flowResponse->readAndDeleteUploadedFile()
|
||||
);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
return $response->withJson($flowResponse);
|
||||
|
|
|
@ -31,6 +31,6 @@ class DeleteArtAction
|
|||
$em->persist($episode);
|
||||
$em->flush();
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Episode artwork successfully cleared.')));
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ class PostArtAction
|
|||
$flowResponse->readAndDeleteUploadedFile()
|
||||
);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
return $response->withJson($flowResponse);
|
||||
|
|
|
@ -32,6 +32,6 @@ class DeleteMediaAction
|
|||
$mediaRepo->delete($podcastMedia);
|
||||
}
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ class PostMediaAction
|
|||
$fsStation->getPodcastsFilesystem()
|
||||
);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
return $response->withJson($flowResponse);
|
||||
|
|
|
@ -202,7 +202,7 @@ class PodcastsController extends AbstractApiCrudController
|
|||
|
||||
$this->editRecord((array)$request->getParsedBody(), $podcast);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Changes saved successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::updated());
|
||||
}
|
||||
|
||||
public function deleteAction(
|
||||
|
@ -221,7 +221,7 @@ class PodcastsController extends AbstractApiCrudController
|
|||
$fsStation = new StationFilesystems($station);
|
||||
$this->podcastRepository->delete($record, $fsStation->getPodcastsFilesystem());
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Record deleted successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -180,7 +180,7 @@ class RequestsController
|
|||
$request->getHeaderLine('User-Agent')
|
||||
);
|
||||
|
||||
return $response->withJson(new Entity\Api\Status(true, __('Request submitted successfully.')));
|
||||
return $response->withJson(Entity\Api\Status::success());
|
||||
} catch (Exception $e) {
|
||||
return $response->withStatus(400)
|
||||
->withJson(new Entity\Api\Error(400, $e->getMessage()));
|
||||
|
|
|
@ -187,7 +187,7 @@ class BroadcastsController extends AbstractApiCrudController
|
|||
$this->em->flush();
|
||||
}
|
||||
|
||||
return $response->withJson(new Entity\Api\Status());
|
||||
return $response->withJson(Entity\Api\Status::deleted());
|
||||
}
|
||||
|
||||
protected function getRecord(Entity\Station $station, int $id): ?Entity\StationStreamerBroadcast
|
||||
|
|
|
@ -38,4 +38,24 @@ class Status
|
|||
$this->message = $message;
|
||||
$this->formatted_message = $formatted_message ?? $message;
|
||||
}
|
||||
|
||||
public static function success(): self
|
||||
{
|
||||
return new self(true, __('Changes saved successfully.'));
|
||||
}
|
||||
|
||||
public static function created(): self
|
||||
{
|
||||
return new self(true, __('Record created successfully.'));
|
||||
}
|
||||
|
||||
public static function updated(): self
|
||||
{
|
||||
return new self(true, __('Record updated successfully.'));
|
||||
}
|
||||
|
||||
public static function deleted(): self
|
||||
{
|
||||
return new self(true, __('Record deleted successfully.'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue