Skip to content
Snippets Groups Projects
Commit 9aefd71d authored by Pierre Fleutot's avatar Pierre Fleutot
Browse files

API : les requêtes qui ne modifient pas de données passent en GET

parent deb7b593
No related branches found
No related tags found
No related merge requests found
......@@ -60,9 +60,9 @@ class ApiEntryController extends ApiBaseController
// }
/**
* Recherche d'une entrée par graphie et par langue, dans un ensemble de lexiques
* Recherche d'une entrée par graphie et par langue dans un ensemble de lexiques
*
* @Route("/search", name="api_entry_search", methods={"POST"})
* @Route("/search", name="api_entry_search", methods={"GET"})
*
* @OA\Response(response=200, description="success",
* @OA\JsonContent(type="array",
......@@ -71,38 +71,33 @@ class ApiEntryController extends ApiBaseController
* @OA\Response(response=401, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=403, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=500, description="error", @OA\JsonContent(type="string"))
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"graphy", "language"},
* @OA\Property(property="graphy", type="string", example="souris"),
* @OA\Property(property="language", type="string", example="fr"),
* @OA\Property(property="target_lex", type="array", description="Tableau des ids des lexiques où créer l'entrée",
* example={3, 4},
* @OA\Items(
* type="integer"
* )
* )
* )
* )
*
* @OA\Parameter(name="graphy", required=true, in="query", @OA\Schema(type="string"))
* @OA\Parameter(name="language", required=true, in="query", @OA\Schema(type="string", example="en"))
* @OA\Parameter(name="target_lex", in="query", @OA\Schema(type="array", description="Tableau des ids des lexiques où créer l'entrée",
* example={3, 4},
* @OA\Items(type="integer")
* ))
*
* @OA\Tag(name="Entries")
* @Security(name="OAuth2")
*/
public function search(Request $request, SerializerInterface $serializer): Response
{
$data = json_decode($request->getContent(), true);
if (!$data) {
return $this->createJsonResponse(401, ['error' => sprintf("Json non valide")]);
$language = $request->get('language');
$graphy = $request->get('graphy');
if (!$language) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour « language »")]);
}
if ($missingFields = $this->getMissingFields($data, ['graphy', 'language'])) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour: %s", implode(', ', $missingFields))]);
if (!$graphy) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour « graphy »")]);
}
$lexicons = isset($data['target_lex']) ? $this->getLexicons($data['target_lex']) : [];
$filter = [
'graphy' => $data['graphy'],
'language' => $data['language'],
'graphy' => $graphy,
'language' => $language,
'lexicons' => $lexicons,
];
......
......@@ -77,67 +77,65 @@ class ApiLogController extends ApiBaseController
/**
* Recherche de logs par date ou user
*
* @Route("/search", name="api_log_search", methods={"POST"})
* @Route("/search", name="api_log_search", methods={"GET"})
*
* @OA\Response(response=200, description="success", @OA\JsonContent(type="string"))
* @OA\Response(response=401, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=403, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=500, description="error", @OA\JsonContent(type="string"))
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* @OA\Property(property="date", type="date"),
* @OA\Property(property="category", type="string", example="update_comment OU update_discussion"),
* @OA\Property(property="user_id", type="integer", example="4"),
* @OA\Property(property="lexicon_id", type="integer", example="4"),
* @OA\Property(property="entry_id", type="integer", example="4"),
* )
* )
*
* @OA\Parameter(name="date", in="query", @OA\Schema(type="date", example="2023-01-09"))
* @OA\Parameter(name="category", in="query", @OA\Schema(type="string", example="update_comment OU update_discussion"))
* @OA\Parameter(name="user_id", in="query", @OA\Schema(type="integer"))
* @OA\Parameter(name="lexicon_id", in="query", @OA\Schema(type="integer"))
* @OA\Parameter(name="entry_id", in="query", @OA\Schema(type="integer"))
*
* @OA\Tag(name="Logs")
* @Security(name="OAuth2")
*/
public function search(Request $request, SerializerInterface $serializer): Response
{
$data = json_decode($request->getContent(), true);
if (!$data) {
return $this->createJsonResponse(401, ['error' => sprintf("Json non valide")]);
}
if (!isset($data['date']) && !isset($data['user_id']) && !isset($data['lexicon_id']) && !isset($data['entry_id'])) {
$date = $request->get('date');
$category = $request->get('category');
$userId = $request->get('user_id');
$lexiconId = $request->get('lexicon_id');
$entryId = $request->get('entry_id');
if (!$date && !$userId && !$lexiconId && !$entryId) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez spécifier au moins un paramètre de recherche parmi: date, user_id, lexicon_id, entry_id")]);
}
if (($data['category'] ?? null) && !in_array($data['category'], Log::LOG_LIST_CATEGORIES)) {
return $this->createJsonResponse(401, ['error' => sprintf("La catégorie de log %s n'existe pas", $data['category'])]);
if (($category ?? null) && !in_array($category, Log::LOG_LIST_CATEGORIES)) {
return $this->createJsonResponse(401, ['error' => sprintf("La catégorie de log %s n'existe pas", $category)]);
}
$filter = [];
if ($data["lexicon_id"] ?? null) {
$lexicon = $this->doctrine->getRepository(Lexicon::class)->find($data['lexicon_id']);
if ($lexiconId ?? null) {
$lexicon = $this->doctrine->getRepository(Lexicon::class)->find($lexiconId);
if (!$lexicon) {
return $this->createJsonResponse(401, ['error' => sprintf("Pas de lexique trouvé pour l'id %s", $data['lexicon_id'])]);
return $this->createJsonResponse(401, ['error' => sprintf("Pas de lexique trouvé pour l'id %s", $lexiconId)]);
} else {
$filter['lexicon'] = $lexicon;
}
}
if ($data["entry_id"] ?? null) {
$entry = $this->doctrine->getRepository(Entry::class)->find($data['entry_id']);
if ($entryId ?? null) {
$entry = $this->doctrine->getRepository(Entry::class)->find($entryId);
if (!$entry) {
return $this->createJsonResponse(401, ['error' => sprintf("Pas d'entrée trouvée pour l'id %s", $data['entry_id'])]);
return $this->createJsonResponse(401, ['error' => sprintf("Pas d'entrée trouvée pour l'id %s", $entryId)]);
} else {
$filter['entry'] = $entry;
}
}
if ($data['date'] ?? null) {
$date = date_create_from_format('Y-m-d', $data['date']);
if ($date === false) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une date au format aaaa-mm-jj pour le paramètre «date»")]);
if ($date ?? null) {
$dateFilter = date_create_from_format('Y-m-d', $date);
if ($dateFilter === false) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une date au format aaaa-mm-jj pour le paramètre « date »")]);
} else {
$filter['date'] = $date;
$filter['date'] = $dateFilter;
}
}
if ($data["user_id"] ?? null) {
$user = $this->doctrine->getRepository(User::class)->find($data['user_id']);
if ($userId ?? null) {
$user = $this->doctrine->getRepository(User::class)->find($userId);
if (!$user) {
return $this->createJsonResponse(401, ['error' => sprintf("Pas d'utilisateur trouvé pour l'id %s", $data['user_id'])]);
return $this->createJsonResponse(401, ['error' => sprintf("Pas d'utilisateur trouvé pour l'id %s", $userId)]);
} else {
$filter['user'] = $user;
}
......@@ -148,7 +146,7 @@ class ApiLogController extends ApiBaseController
$logs = $this->doctrine->getRepository(Log::class)->search($filter);
$content = $serializer->serialize($logs, 'json', ['groups' => ["log:read"]]);
$content = $serializer->serialize($logs, 'json', ['groups' => ["log:read", "user:read"]]);
return new JsonResponse($content, 200, [], true);
}
......
......@@ -102,7 +102,7 @@ class ApiMetaInfoController extends ApiBaseController
/**
* Recherche de metaInfos id graphie ou id de modèle méta information
*
* @Route("/search", name="api_meta_info_search", methods={"POST"})
* @Route("/search", name="api_meta_info_search", methods={"GET"})
*
* @OA\Response(response=200, description="success",
* @OA\JsonContent(type="array",
......@@ -111,38 +111,33 @@ class ApiMetaInfoController extends ApiBaseController
* @OA\Response(response=401, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=403, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=500, description="error", @OA\JsonContent(type="string"))
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* @OA\Property(property="graphy_id", type="integer"),
* @OA\Property(property="template_id", type="integer")
* )
* )
*
* @OA\Parameter(name="graphy_id", in="query", @OA\Schema(type="integer"))
* @OA\Parameter(name="template_id", in="query", @OA\Schema(type="integer"))
*
* @OA\Tag(name="MetaInfos")
* @Security(name="OAuth2")
*/
public function search(Request $request, SerializerInterface $serializer): Response
{
$data = json_decode($request->getContent(), true);
if (!$data) {
return $this->createJsonResponse(401, ['error' => sprintf("Json non valide")]);
}
if (!isset($data['date']) && !isset($data['graphy_id']) && !isset($data['template_id'])) {
$graphyId = $request->get('graphy_id');
$templateId = $request->get('template_id');
if (!$graphyId && !$templateId) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez spécifier au moins un paramètre de recherche parmi: graphy_id, template_id")]);
}
$filter = [];
if ($data['graphy_id'] ?? null) {
$filter['graphy'] = $data['graphy_id'];
if ($graphyId ?? null) {
$filter['graphy'] = $graphyId;
}
if ($data['template_id'] ?? null) {
$filter['metaInfoTemplate'] = $data['template_id'];
if ($templateId ?? null) {
$filter['metaInfoTemplate'] = $templateId;
}
$metaInfos = $this->doctrine->getRepository(MetaInfo::class)->findBy($filter, ['createdAt' => 'DESC']);
$content = $serializer->serialize($metaInfos, 'json', [
'groups' => ["metaInfo:read", "user:read"],
'groups' => ["metaInfo:read", "user:read", "graphy:read"],
'datetime_format' => 'Y-m-d h:i:s.u'
]);
......
......@@ -151,7 +151,7 @@ class ApiTraceController extends ApiBaseController
/**
* Recherche de traces par date ou user ou action ou origin
*
* @Route("/search", name="api_trace_search", methods={"POST"})
* @Route("/search", name="api_trace_search", methods={"GET"})
*
* @OA\Response(response=200, description="success",
* @OA\JsonContent(type="array",
......@@ -160,59 +160,57 @@ class ApiTraceController extends ApiBaseController
* @OA\Response(response=401, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=403, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=500, description="error", @OA\JsonContent(type="string"))
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* @OA\Property(property="date", type="date"),
* @OA\Property(property="date_client", type="date"),
* @OA\Property(property="user_id", type="integer", example="4"),
* @OA\Property(property="origin", type="string", example="Prisms"),
* @OA\Property(property="action", type="string", example="action"),
* )
* )
*
* @OA\Parameter(name="date", in="query", @OA\Schema(type="date", example="2023-01-09"))
* @OA\Parameter(name="date_client", in="query", @OA\Schema(type="date", example="2023-01-09"))
* @OA\Parameter(name="user_id", in="query", @OA\Schema(type="date", example="4"))
* @OA\Parameter(name="origin", in="query", @OA\Schema(type="date", example="Prisms"))
* @OA\Parameter(name="action", in="query", @OA\Schema(type="date", example="action"))
*
* @OA\Tag(name="Traces")
* @Security(name="OAuth2")
*/
public function search(Request $request, SerializerInterface $serializer): Response
{
$data = json_decode($request->getContent(), true);
if (!$data) {
return $this->createJsonResponse(401, ['error' => sprintf("Json non valide")]);
}
if (!isset($data['date']) && !isset($data['date_client']) && !isset($data['user_id']) && !isset($data['origin']) && !isset($data['action'])) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez spécifier au moins un paramètre de recherche parmi: date, user_id, action, origin")]);
$date = $request->get('date');
$dateClient = $request->get('date_client');
$userId = $request->get('user_id');
$origin = $request->get('origin');
$action = $request->get('action');
if (!$date && !$dateClient && !$userId && !$origin && !$action) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez spécifier au moins un paramètre de recherche parmi: date, date_client, user_id, action, origin")]);
}
$filter = [];
if ($data['date'] ?? null) {
$date = date_create_from_format('Y-m-d', $data['date']);
if ($date ?? null) {
$date = date_create_from_format('Y-m-d', $date);
if ($date === false) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une date au format aaaa-mm-jj pour le paramètre «date»")]);
} else {
$filter['date'] = $date;
}
}
if ($data['date_client'] ?? null) {
$dateClient = date_create_from_format('Y-m-d', $data['date_client']);
if ($dateClient ?? null) {
$dateClient = date_create_from_format('Y-m-d', $dateClient);
if ($dateClient === false) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une date au format aaaa-mm-jj pour le paramètre «date client»")]);
} else {
$filter['date_client'] = $dateClient;
}
}
if ($data["user_id"] ?? null) {
$user = $this->doctrine->getRepository(User::class)->find($data['user_id']);
if ($userId ?? null) {
$user = $this->doctrine->getRepository(User::class)->find($userId);
if (!$user) {
return $this->createJsonResponse(401, ['error' => sprintf("Pas d'utilisateur trouvé pour l'id %s", $data['user_id'])]);
return $this->createJsonResponse(401, ['error' => sprintf("Pas d'utilisateur trouvé pour l'id %s", $userId)]);
} else {
$filter['user'] = $user;
}
}
if ($data['origin'] ?? null) {
$filter['origin'] = $data['origin'];
if ($origin ?? null) {
$filter['origin'] = $origin;
}
if ($data['action'] ?? null) {
$filter['action'] = $data['action'];
if ($action ?? null) {
$filter['action'] = $action;
}
$traces = $this->doctrine->getRepository(Trace::class)->search($filter);
......
......@@ -26,7 +26,7 @@ class ApiWiktionaryController extends ApiBaseController
{
/**
* @Route("/search", name="api_wiktionary_search", methods={"POST"})
* @Route("/search", name="api_wiktionary_search", methods={"GET"})
*
* @OA\Response(
* response=200,
......@@ -38,27 +38,23 @@ class ApiWiktionaryController extends ApiBaseController
* @OA\Response(response=403, description="error", @OA\JsonContent(type="string"))
* @OA\Response(response=500, description="error", @OA\JsonContent(type="string"))
*
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* @OA\Property(property="graphy", type="string", example="green"),
* @OA\Property(property="language", type="string", example="en")
* )
* )
* )
* @OA\Parameter(name="graphy", required=true, in="query", @OA\Schema(type="string"))
* @OA\Parameter(name="language", required=true, in="query", @OA\Schema(type="string", example="en"))
*
* @OA\Tag(name="Wiktionary")
* @Security(name="OAuth2")
*/
public function searchWiktionary(Request $request)
{
$data = json_decode($request->getContent(), true);
if (!$data) {
return $this->createJsonResponse(401, ['error' => sprintf("Json non valide")]);
$language = $request->get('language');
$graphy = $request->get('graphy');
if (!$language) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour « language »")]);
}
if ($missingFields = $this->getMissingFields($data, ['graphy', 'language'])) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour: %s", implode(', ', $missingFields))]);
if (!$graphy) {
return $this->createJsonResponse(401, ['error' => sprintf("Veuillez fournir une valeur pour « graphy »")]);
}
$wikData = $this->wiktionaryManager->search($data['graphy'], $data['language']);
$wikData = $this->wiktionaryManager->search($graphy, $language);
return new JsonResponse($wikData, 200, []);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment