chatbotterms.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace Meramo\Crazytermsapi\Api;
  3. use http\Client\Request;
  4. use http\Message\Body;
  5. use Meramo\Begriffmgt\Domain\Model\Type;
  6. use nn\t3;
  7. use Nng\Nnrestapi\Api\AbstractApi;
  8. use Nng\Nnrestapi\Annotations as Api;
  9. use Meramo\Begriffmgt\Domain\Model\Term as TermModel;
  10. use Meramo\Begriffmgt\Domain\Repository\TermRepository;
  11. use Symfony\Component\HttpFoundation\JsonResponse;
  12. use TYPO3\CMS\Core\Http\Response;
  13. /**
  14. * This annotation registers this class as an Endpoint!
  15. *
  16. * @Api\Endpoint()
  17. */
  18. class chatbotterms extends AbstractApi
  19. {
  20. /**
  21. * Constructor
  22. * Inject the TermRepository.
  23. *
  24. * @return void
  25. */
  26. public function __construct(TermRepository $termRepository)
  27. {
  28. $this->termRepository = t3::injectClass( TermRepository::class );
  29. $this->termRepositoryOri = $termRepository;
  30. }
  31. /**
  32. * # Retrieve existing Terms
  33. *
  34. * Send a simple POST request to retrieve terms by type or category or whatever from the database.
  35. * The actual request is made based on the combination of params you provide.
  36. * ```
  37. * https://www.this-sites-url.com/api/chatbotterms
  38. * ```
  39. * Add your request parameters to the request.
  40. * Based on the fields in the db a possible request could be i.e.:
  41. * ```
  42. * ?type=gedoens
  43. * ```
  44. * which retrieves all terms with type 'gedoens' or
  45. * ```
  46. * ?category=obst
  47. * ```
  48. * which retrieves all terms of category 'obst' or
  49. * ```
  50. * ?type=gedoens&category=obst
  51. * ```
  52. * which retrieves all terms with type 'gedoens' and category 'obst' or even
  53. * ```
  54. * ```
  55. * which retrieves all terms objects.
  56. *
  57. * @Api\Access("fe_users")
  58. * @Api\Localize()
  59. * @Api\Label("/api/chatbotterms")
  60. * @return array
  61. */
  62. public function getIndexAction()
  63. {
  64. $requestArgs = $this->getRequest()->getArguments();
  65. $type = $requestArgs['type'];
  66. $category = $requestArgs['category'];
  67. $termsQueryResults = $this->termRepositoryOri->findAllTermsByTypeOrCategoryOrSimplyAll($type, $category);
  68. $response = json_decode(json_encode($termsQueryResults));
  69. return $response;
  70. }
  71. }