mirror of
https://github.com/Karaka-Management/oms-Profile.git
synced 2026-02-15 06:48:41 +00:00
Implement failed profile creation response
This commit is contained in:
parent
53516cb4ae
commit
3c3f0835af
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user