CategoryApiController.php 903 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace internship\controller;
  3. use n2n\web\http\controller\ControllerAdapter;
  4. use n2n\context\attribute\Inject;
  5. use internship\model\CategoryDao;
  6. use n2n\web\http\controller\ParamBody;
  7. use internship\bo\Article;
  8. use n2n\web\http\PageNotFoundException;
  9. class CategoryApiController extends ControllerAdapter {
  10. #[Inject]
  11. private CategoryDao $categoryDao;
  12. function getDoCategory(int $categoryId): void {
  13. $category = $this->categoryDao->getCategoryById($categoryId);
  14. if ($category === null) {
  15. throw new PageNotFoundException();
  16. } else {
  17. $this->sendJson($category);
  18. }
  19. }
  20. function getDoCategories(): void {
  21. $categories = $this->categoryDao->getCategories();
  22. $this->sendJson($categories);
  23. }
  24. function postDoCategory(ParamBody $body): void {
  25. }
  26. function putDoCategory(int $articleId, ParamBody $body): void {
  27. }
  28. function deleteDoCategory(int $articleId): void {
  29. }
  30. }