Implement failed profile creation response

This commit is contained in:
Dennis Eichhorn 2019-02-18 17:25:03 +01:00
parent 53516cb4ae
commit 3c3f0835af

View File

@ -47,29 +47,40 @@ final class ApiController extends Controller
{ {
$profiles = $this->createProfilesFromRequest($request); $profiles = $this->createProfilesFromRequest($request);
$created = []; $created = [];
$status = true;
foreach ($profiles as $profile) { foreach ($profiles as $profile) {
$this->apiProfileCreateDbEntry($profile, $request); $status = $status && $this->apiProfileCreateDbEntry($profile, $request);
$created[] = $profile; $created[] = $profile;
} }
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Profil', 'Profil successfully created.', $created); $this->fillJsonResponse(
$request, $response,
$status ? NotificationLevel::OK : NotificationLevel::WARNING,
'Profil',
$status ? 'Profil successfully created.' : 'Profile already existing.',
$created
);
} }
/** /**
* @param Profile $profile Profile to create in the database * @param Profile $profile Profile to create in the database
* @param RequestAbstract $request Request * @param RequestAbstract $request Request
* *
* @return void * @return bool
* *
* @since 1.0.0 * @since 1.0.0
*/ */
public function apiProfileCreateDbEntry(Profile $profile, RequestAbstract $request) : void public function apiProfileCreateDbEntry(Profile $profile, RequestAbstract $request) : bool
{ {
if ($profile->getId() === 0) { if ($profile->getId() !== 0) {
$this->createModel($request, $profile, ProfileMapper::class, 'profile'); return false;
} }
$this->createModel($request, $profile, ProfileMapper::class, 'profile');
return true;
} }
/** /**