categories.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="categories",
  5. * description="Category Information"
  6. * )
  7. */
  8. $app->get('/categories', function ($request, $response, $args) {
  9. /**
  10. * @OA\Get(
  11. * security={{ "api_key":{} }},
  12. * tags={"categories"},
  13. * path="/api/v2/categories",
  14. * summary="Get all categories",
  15. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  16. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  17. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  18. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  19. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  20. * )
  21. */
  22. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  23. if ($Organizr->qualifyRequest(1, true)) {
  24. $GLOBALS['api']['response']['data'] = $Organizr->getAllTabs();
  25. }
  26. $response->getBody()->write(jsonE($GLOBALS['api']));
  27. return $response
  28. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  29. ->withStatus($GLOBALS['responseCode']);
  30. });
  31. $app->post('/categories', function ($request, $response, $args) {
  32. /**
  33. * @OA\Post(
  34. * security={{ "api_key":{} }},
  35. * tags={"categories"},
  36. * path="/api/v2/categories",
  37. * summary="Add new category",
  38. * @OA\RequestBody(description="Success",required=true,@OA\JsonContent(ref="#/components/schemas/submit-2fa-verify")),
  39. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  40. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  41. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  42. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  43. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  44. * )
  45. */
  46. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  47. if ($Organizr->checkRoute($request)) {
  48. if ($Organizr->qualifyRequest(1, true)) {
  49. $Organizr->addCategory($Organizr->apiData($request));
  50. }
  51. }
  52. $response->getBody()->write(jsonE($GLOBALS['api']));
  53. return $response
  54. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  55. ->withStatus($GLOBALS['responseCode']);
  56. });
  57. $app->put('/categories', function ($request, $response, $args) {
  58. /**
  59. * @OA\Put(
  60. * security={{ "api_key":{} }},
  61. * tags={"categories"},
  62. * path="/api/v2/categories",
  63. * summary="Update category order",
  64. * @OA\RequestBody(description="Success",required=true,@OA\JsonContent(ref="#/components/schemas/submit-2fa-verify")),
  65. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  66. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  67. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  68. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  69. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  70. * )
  71. */
  72. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  73. if ($Organizr->checkRoute($request)) {
  74. if ($Organizr->qualifyRequest(1, true)) {
  75. $Organizr->updateCategoryOrder($Organizr->apiData($request));
  76. }
  77. }
  78. $response->getBody()->write(jsonE($GLOBALS['api']));
  79. return $response
  80. ->withHeader('Content-Type', 'application/json')
  81. ->withStatus($GLOBALS['responseCode']);
  82. });
  83. $app->put('/categories/{id}', function ($request, $response, $args) {
  84. /**
  85. * @OA\Put(
  86. * security={{ "api_key":{} }},
  87. * tags={"categories"},
  88. * path="/api/v2/categories/{id}",
  89. * summary="Update category",
  90. * @OA\RequestBody(description="Success",required=true,@OA\JsonContent(ref="#/components/schemas/submit-2fa-verify")),
  91. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  92. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  93. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  94. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  95. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  96. * )
  97. */
  98. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  99. if ($Organizr->checkRoute($request)) {
  100. if ($Organizr->qualifyRequest(1, true)) {
  101. $Organizr->updateCategory($args['id'], $Organizr->apiData($request));
  102. }
  103. }
  104. $response->getBody()->write(jsonE($GLOBALS['api']));
  105. return $response
  106. ->withHeader('Content-Type', 'application/json')
  107. ->withStatus($GLOBALS['responseCode']);
  108. });
  109. $app->delete('/categories/{id}', function ($request, $response, $args) {
  110. /**
  111. * @OA\Delete(
  112. * security={{ "api_key":{} }},
  113. * tags={"categories"},
  114. * path="/api/v2/categories/{id}",
  115. * summary="Delete category",
  116. * @OA\RequestBody(description="Success",required=true,@OA\JsonContent(ref="#/components/schemas/submit-2fa-verify")),
  117. * @OA\Response(response="200",description="Success",@OA\JsonContent(ref="#/components/schemas/success-message")),
  118. * @OA\Response(response="401",description="Unauthorized",@OA\JsonContent(ref="#/components/schemas/unauthorized-message")),
  119. * @OA\Response(response="404",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  120. * @OA\Response(response="422",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  121. * @OA\Response(response="500",description="Error",@OA\JsonContent(ref="#/components/schemas/error-message")),
  122. * )
  123. */
  124. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  125. if ($Organizr->checkRoute($request)) {
  126. if ($Organizr->qualifyRequest(1, true)) {
  127. $Organizr->deleteCategory($args['id']);
  128. }
  129. }
  130. $response->getBody()->write(jsonE($GLOBALS['api']));
  131. return $response
  132. ->withHeader('Content-Type', 'application/json')
  133. ->withStatus($GLOBALS['responseCode']);
  134. });