-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
538 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?php | ||
|
||
namespace Fradoos\Application; | ||
|
||
use Fradoos\Domain\Helper\HelperParameter; | ||
use Fradoos\Domain\Presentation\Presentations; | ||
use Fradoos\Domain\Repository\Repositories; | ||
use Fradoos\Domain\WorkingGroup; | ||
|
||
/** | ||
* Class ApplicationWorkingGroup | ||
* @package Fradoos\Application | ||
*/ | ||
class ApplicationWorkingGroup extends HttpResources | ||
{ | ||
/** | ||
* @return ApplicationWorkingGroup | ||
*/ | ||
public static function instance() | ||
{ | ||
return new ApplicationWorkingGroup(); | ||
} | ||
|
||
/** | ||
* @SWG\Delete( | ||
* path="/workingGroup/{id}", summary="Delete a workingGroup by id", description="", | ||
* @SWG\Parameter(name="id", in="path", required=true, type="integer", description="WorkingGroup id"), | ||
* @SWG\Response(response=204, description="") | ||
* ) | ||
*/ | ||
public function delete($req, $res, $args) | ||
{ | ||
Repositories::instance()->forWorkingGroup()->delete($args["id"]); | ||
|
||
return $this->response($res, static::STATUS_NO_CONTENT); | ||
} | ||
|
||
/** | ||
* @SWG\Get( | ||
* path="/workingGroup/{id}", summary="Get a workingGroup by id", description="", | ||
* @SWG\Parameter(name="id", in="path", required=true, type="integer", description="WorkingGroup id"), | ||
* @SWG\Response(response=200, description="") | ||
* ) | ||
*/ | ||
public function get($req, $res, $args) | ||
{ | ||
$workingGroup = Repositories::instance()->forWorkingGroup()->get($args["id"]); | ||
|
||
return $this->response( | ||
$res, static::STATUS_OK, | ||
Presentations::instance()->forWorkingGroup()->inJsonWith( | ||
$workingGroup, | ||
HelperParameter::getFields($req->getParam("fields")) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @SWG\Get( | ||
* path="/workingGroup", summary="Get all workingGroups", description="", | ||
* @SWG\Response(response=200, description="") | ||
* ) | ||
*/ | ||
public function getAll($req, $res, $args) | ||
{ | ||
$workingGroups = Repositories::instance()->forWorkingGroup()->getAll(); | ||
|
||
$presentation = Presentations::instance()->forWorkingGroup()->allInJsonWith( | ||
$workingGroups, | ||
HelperParameter::getFields($req->getParam("fields")) | ||
); | ||
|
||
return $this->response($res, static::STATUS_OK, $presentation); | ||
} | ||
|
||
/** | ||
* @SWG\Post( | ||
* path="/workingGroup", summary="Create a workingGroup", description="", | ||
* @SWG\Parameter(name="name", in="formData", required=true, type="string", description="Name"), | ||
* @SWG\Response(response=201, description="") | ||
* ) | ||
*/ | ||
public function post($req, $res, $args) | ||
{ | ||
$workingGroup = new WorkingGroup($req->getParam("name")); | ||
Repositories::instance()->forWorkingGroup()->add($workingGroup); | ||
|
||
return $this->response( | ||
$res, static::STATUS_CREATED, | ||
Presentations::instance()->forWorkingGroup()->inJson($workingGroup) | ||
); | ||
} | ||
|
||
/** | ||
* @SWG\Put( | ||
* path="/workingGroup/{id}", summary="Replace a workingGroup by id", description="", | ||
* @SWG\Parameter(name="id", in="path", required=true, type="integer", description="WorkingGroup id"), | ||
* @SWG\Parameter(name="name", in="formData", required=true, type="string", description="Name"), | ||
* @SWG\Response(response=201, description="") | ||
* ) | ||
*/ | ||
public function put($req, $res, $args) | ||
{ | ||
$presentation = ""; | ||
$status = static::STATUS_NOT_FOUND; | ||
|
||
$workingGroup = Repositories::instance()->forWorkingGroup()->get($args["id"]); | ||
if (!is_null($workingGroup)) { | ||
$workingGroup->setName($req->getParam("name")); | ||
Repositories::instance()->forWorkingGroup()->edit($workingGroup); | ||
$presentation = Presentations::instance()->forWorkingGroup()->inJson($workingGroup); | ||
$status = static::STATUS_CREATED; | ||
} | ||
|
||
return $this->response($res, $status, $presentation); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Application/Presentation/JsonPresentationWorkingGroup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Fradoos\Application\Presentation; | ||
|
||
use Fradoos\Domain\Presentation\IPresentation; | ||
use Fradoos\Domain\WorkingGroup; | ||
|
||
class JsonPresentationWorkingGroup extends SimpleJsonPresentation implements IPresentation | ||
{ | ||
public static $name = 'name'; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
|
||
$this->mappings[JsonPresentationWorkingGroup::$name] = function (WorkingGroup $object) { | ||
return $object->getName(); | ||
}; | ||
} | ||
|
||
public function allDefaultProperties() | ||
{ | ||
return [ | ||
SimpleJsonPresentation::$id, | ||
JsonPresentationWorkingGroup::$name, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Fradoos\Domain\Repository; | ||
|
||
interface IRepositoryWorkingGroup | ||
{ | ||
public function add($user); | ||
|
||
public function delete($id); | ||
|
||
public function edit($user); | ||
|
||
public function get($id); | ||
|
||
public function getAll(); | ||
|
||
public function getByName($name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Fradoos\Domain; | ||
|
||
use Fradoos\Domain\Helper\HelperParameter; | ||
|
||
/** | ||
* Class WorkingGroup | ||
* @package Fradoos\Domain | ||
*/ | ||
class WorkingGroup extends Entity | ||
{ | ||
/** | ||
* @var $name string | ||
*/ | ||
private $name; | ||
|
||
/** | ||
* WorkingGroup constructor. | ||
* @param $name | ||
* @param $email | ||
* @throws Error\ErrorParameter | ||
*/ | ||
public function __construct($name) | ||
{ | ||
$this->setName($name); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @param $name | ||
* @throws Error\ErrorParameter | ||
*/ | ||
public function setName(string $name) | ||
{ | ||
HelperParameter::checkNotEmpty($name, "The workingGroup name is mandatory."); | ||
if ($this->name != $name) { | ||
$this->name = $name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/Infrastructure/Repository/Doctrine/DoctrineRepositoryWorkingGroup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Fradoos\Infrastructure\Repository\Doctrine; | ||
|
||
use Fradoos\Domain\WorkingGroup; | ||
use Fradoos\Domain\Helper\HelperParameter; | ||
use Fradoos\Domain\Repository\IRepositoryWorkingGroup; | ||
|
||
class DoctrineRepositoryWorkingGroup extends SimpleDoctrineRepository implements IRepositoryWorkingGroup | ||
{ | ||
protected static $entity = WorkingGroup::class; | ||
|
||
public function getByName($name) | ||
{ | ||
HelperParameter::checkNotEmpty($name, "Impossible to get working group with empty name."); | ||
return $this->entityManager | ||
->getRepository(WorkingGroup::class) | ||
->findBy(['name' => $name]); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/Infrastructure/Repository/Doctrine/Mapping/Fradoos.Domain.WorkingGroup.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; | ||
|
||
$builder = new ClassMetadataBuilder($metadata); | ||
$builder->setTable("working_group"); | ||
$builder->addField("name", "string", ["length" => 255, "nullable" => false]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.