Debug de l'API

This commit is contained in:
Kouril42
2023-02-14 01:46:32 +01:00
parent 32333be41e
commit 5e75888ab7
9 changed files with 248 additions and 117 deletions
+125 -78
View File
@@ -5,68 +5,100 @@ namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Common\Collections\ArrayCollection;
use App\Repository\SiteRepository;
use App\Repository\RoomRepository;
use App\Repository\FloorRepository;
use App\Repository\PlaceRepository;
use App\Repository\PlaceNameRepository;
use App\Repository\RoomUserNameRepository;
use App\Repository\EditionRepository;
use App\Entity\PlaceName;
use App\Entity\RoomUserName;
use App\Entity\Edition;
class MapApiController extends AbstractController
{
//function get_Name($rep) {return $rep->getName();}
#[Route('/map/api/test')]
public function test(SiteRepository $rep): JsonResponse
public function test(PlaceNameRepository $pNRep, RoomUserNameRepository $uNRep, PlaceRepository $pRep, SiteRepository $sRep): JsonResponse
{
$place0 = $pRep->findPlaceById(1)[0];
return $this->json([
'message' => 'Welcome to your new controller!',
'path' => 'src/Controller/MapApiController.php',
'sites' => $rep->allSites()[0]->getZeroLatitude()
'allUnames' => $uNRep->allNames(),
'allPnames' => $pNRep->allNames(),
'Place0Id' => $place0->getId(),
'Place0UserNames0' => $place0->getRoomUsers()[0]->getUserName(),
'Place0Names0' => $place0->getNames()[0]->getName(),
'sites' => $sRep->allSites()
]);
}
#[Route(' ')]
public function get_floor(FloorRepository $rep, int $id, string $representation): JsonResponse
#[Route('/map/api/get_floor/{id}/{representation}')]
public function get_floor(FloorRepository $rep, int $id, string $representation='Cylinder'): JsonResponse
{
$floor = $rep->findFloorById($id);
$places = $floor->getPlace();
//id is the floor's id, representation being Cylinder or PolySurface or other if implemented
//it defines which representation should we use to project it on 2 dimension
$floors = $rep->findFloorById($id);
if (sizeof($floors)!=1) { return $this->json(["Error : None or Too Many Floors have this id"]); }
$floor = $floors[0];
$places = $floor->getPlaces();
$jsonPlaces = new ArrayCollection();
foreach ($places as $place){
$jsonPlaces[] = $this->json([
'id' => $place->getId(),
'name' => $place->getName(),
'type' => $place->getType(),
'surface' => $place->getTwoDRepresentation($representation, $floor->getAltitude())
]);
if ($representation == 'Cylinder' || $representation == 'PolySurface'){
foreach ($places as $place){
$jsonPlaces[] = array(
'id' => $place->getId(),
'name' => $place->getJoinedNames(),
'type' => $place->getType(),
'surface' => $place->getTwoDRepresentation($representation, $floor->getAltitude())
);
}
}
return $jsonPlaces;
else {
return $this->json(["Error on represantation attribute"]);
}
return $this->json($jsonPlaces->toArray());
}
#[Route('/map/api/find_place_by_name')]
#[Route('/map/api/find_place_by_name/{name}')]
public function find_place_by_name(PlaceRepository $rep, string $name): JsonResponse
{
$places = $rep->findPlaceByName($name);
if (sizeof($places)!=1) {
return false;
}
if (sizeof($places)!=1) { return $this->json([0]); }
else {
$place = $places[0];
$floorsId = array();
foreach ($place->getFloors() as $floor) {
$floorsId[] = $floor->getId();
}
return $this->json([
'idRoom' => $place->getId(),
'idFloor' => $place->getFloor()->getId()
'idFloors' => $floorsId
]);
}
}
#[Route('/map/api/show_place_info')]
#[Route('/map/api/show_place_info/{id}')]
public function index(PlaceRepository $rep, int $id): JsonResponse
{
$places = $rep->findPlaceById($id);
if (sizeof($places)!=1) {
return null;
return $this->json([0]);
}
else {
return $this->json([
'idRoom' => $places[0]->getId(),
'names' => $places[0]->getName(),
'users' => $places[0]->getUser()
'names' => $places[0]->getJoinedNames(),
'users' => $places[0]->getJoinedRoomUsersNames()
]);
}
}
@@ -76,80 +108,95 @@ class MapApiController extends AbstractController
{
$edits = $rep->getAllEditions();
if (sizeof($edits)<1) {
return null;
return $this->json([0]);
}
else {
$listEdits = new ArrayCollection();
$listEdits = array();
foreach ($edits as $edit){
$listEdits[] = $this->json([
$listEdits[] = array(
'id' => $edit->getId(),
'mode' => $edit->getMode(),
'name' => $edit->getNamePlace(),
'idPlace' => $edit->getIdPlace(),
'value' => $edit->getValue()
]);
'placeNames' => $edit->getEditedPlace()->getJoinedNames(),
'placeId' => $edit->getEditedPlace()->getId(),
'editorValue' => $edit->getValue()
);
}
}
return $listEdits;
return $this->json($listEdits);
}
#[Route('/map/api/create_edition')]
public function createEdition(EditionRepository $Erep, PlaceRepository $Prep, string $mode, int $idPlace, string $value): bool
#[Route('/map/api/create_edition/{mode}/{placeId}/{value}')]
public function createEdition(EditionRepository $Erep, PlaceRepository $Prep, string $mode, int $placeId, string $value): JsonResponse
{
//mode is the type of modification, can be AddPlaceName ; DelPlaceName ; AddRoomUserName or DelRoomUserName
$edit = new Edition();
$edit->createEdition($Prep, $mode, $idPlace, $value);
return $Erep->add($edit);
if ($edit->initEdition($Prep, $mode, $placeId, $value) == null) {return $this->json(["Error during initEdition : None or Too Many Places found with id"]);}
$Erep->add($edit, true);
return $this->json(["added"]);
}
#[Route('/map/api/remove_edition')]
public function removeEdition(EditionRepository $rep, int $id): bool
#[Route('/map/api/remove_edition/{id}')]
public function removeEdition(EditionRepository $rep, int $id): JsonResponse
{
$edit = $rep->findEditionById($id);
if ($edit == null) {return false;}
$rep->remove($edit);
return true;
if (sizeof($edit) == 0) {return $this->json([0]);}
$rep->remove($edit[0], true);
return $this->json(["removed"]);
}
#[Route('/map/api/add_place_name/{placeId}/{value}')]
public function addPlaceName(PlaceRepository $pRep, PlaceNameRepository $pNRep, int $placeId, string $value): JsonResponse
{
$places = $pRep->findPlaceById($placeId);
if (sizeof($places) != 1) { return $this->json([0]); }
else{
$names = new ArrayCollection();
foreach($places[0]->getNames() as $plName) { $names[] = $plName->getName(); }
if ($names->contains($value)) { return $this->json([2]); }
else {
$pN = new PlaceName();
$pN->setPlace($places[0]);
$pN->setName($value);
$pNRep->add($pN, true);
return $this->json(["added"]);
}
}
}
#[Route('/map/api/del_place_name/{placeId}/{value}')]
public function delPlaceName(PlaceNameRepository $pNRep, int $placeId, string $value): JsonResponse
{
$pN = $pNRep->findPlaceName($placeId, $value);
if (sizeof($pN)==0) { return $this->json([0]); }
$pNRep->remove($pN[0], true);
return $this->json(["removed"]);
}
#[Route('/map/api/del_place_name')]
public function delPlaceName(PlaceRepository $rep, int $id, string $value): bool
#[Route('/map/api/add_room_user_name/{placeId}/{value}')]
public function addRoomUserName(PlaceRepository $pRep, RoomUserNameRepository $rURep, ManagerRegistry $mr, int $placeId, string $value): JsonResponse
{
$places = $rep->findPlaceById($id);
if (sizeof($places)!=1) { return null; }
else {
$places[0]->removeName($value);
return true;
$places = $pRep->findPlaceById($placeId);
if (sizeof($places) != 1) { return $this->json([0]); }
else{
$names = new ArrayCollection();
foreach($places[0]->getRoomUsers() as $rUser) { $names[] = $rUser->getUserName(); }
if ($names->contains($value)) { return $this->json([2]); }
else {
$rU = new RoomUserName();
$rU->setPlace($places[0]);
$rU->setUserName($value);
$rURep->add($rU, true);
return $this->json(["added"]);
}
}
}
#[Route('/map/api/add_place_name')]
public function addPlaceName(PlaceRepository $rep, int $id, string $value): bool
#[Route('/map/api/del_room_user_name/{placeId}/{value}')]
public function delRoomUserName(RoomUserNameRepository $uRep, int $placeId, string $value): JsonResponse
{
$places = $rep->findPlaceById($id);
if (sizeof($places)!=1) { return null; }
else {
$places[0]->addName($value);
return true;
}
}
#[Route('/map/api/del_room_user_name')]
public function delRoomUserName(PlaceRepository $rep, int $id, string $value): bool
{
$rooms = $rep->findPlaceById($id);
if (sizeof($rooms)!=1) { return null; }
else {
$rooms[0]->removeRoomUser($value);
return true;
}
}
#[Route('/map/api/add_room_user_name')]
public function addRoomUserName(PlaceRepository $rep, int $id, string $value): bool
{
$rooms = $rep->findPlaceById($id);
if (sizeof($rooms)!=1) { return null; }
else {
$rooms[0]->addRoomUser($value);
return true;
}
$rU = $uRep->findRoomUserName($placeId, $value);
if (sizeof($rU)==0) { return $this->json([0]); }
$uRep->remove($rU[0], true);
return $this->json(["removed"]);
}
}