config.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * @OA\Tag(
  4. * name="config",
  5. * description="Organizr Configuration Items"
  6. * )
  7. */
  8. $app->get('/config[/{item}]', function ($request, $response, $args) {
  9. /**
  10. * @OA\Get(
  11. * tags={"config"},
  12. * path="/api/v2/config",
  13. * summary="Get Organizr Coniguration Items",
  14. * @OA\Response(
  15. * response="200",
  16. * description="Success",
  17. * @OA\JsonContent(ref="#/components/schemas/success-message"),
  18. * ),
  19. * @OA\Response(response="401",description="Unauthorized"),
  20. * security={{ "api_key":{} }}
  21. * )
  22. */
  23. /**
  24. * @OA\Get(
  25. * tags={"config"},
  26. * path="/api/v2/config/{item}",
  27. * summary="Get Organizr Coniguration Item",
  28. * @OA\Parameter(name="item",description="The key of the item you want to grab",@OA\Schema(type="string"),in="path",required=true,example="configVersion"),
  29. * @OA\Response(
  30. * response="200",
  31. * description="Success",
  32. * @OA\JsonContent(ref="#/components/schemas/success-message"),
  33. * ),
  34. * @OA\Response(response="401",description="Unauthorized"),
  35. * security={{ "api_key":{} }}
  36. * )
  37. */
  38. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  39. if ($Organizr->qualifyRequest(1, true)) {
  40. if (isset($args['item'])) {
  41. $Organizr->getConfigItem($args['item']);
  42. } else {
  43. $GLOBALS['api']['response']['data'] = $Organizr->getConfigItems();
  44. }
  45. }
  46. $response->getBody()->write(jsonE($GLOBALS['api']));
  47. return $response
  48. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  49. ->withStatus($GLOBALS['responseCode']);
  50. });
  51. $app->put('/config', function ($request, $response, $args) {
  52. /**
  53. * @OA\Put(
  54. * tags={"config"},
  55. * path="/api/v2/config",
  56. * summary="Update Organizr Coniguration Item(s)",
  57. * @OA\RequestBody(
  58. * description="Success",
  59. * required=true,
  60. * @OA\JsonContent(ref="#/components/schemas/config-items-example"),
  61. * ),
  62. * @OA\Response(
  63. * response="200",
  64. * description="Success",
  65. * @OA\JsonContent(ref="#/components/schemas/success-message"),
  66. * ),
  67. * @OA\Response(response="401",description="Unauthorized"),
  68. * security={{ "api_key":{} }}
  69. * )
  70. */
  71. $Organizr = ($request->getAttribute('Organizr')) ?? new Organizr();
  72. if ($Organizr->qualifyRequest(1, true)) {
  73. $Organizr->updateConfigItems($Organizr->apiData($request));
  74. }
  75. $response->getBody()->write(jsonE($GLOBALS['api']));
  76. return $response
  77. ->withHeader('Content-Type', 'application/json;charset=UTF-8')
  78. ->withStatus($GLOBALS['responseCode']);
  79. });