| 123456789101112131415161718192021222324252627 |
- <?php
- namespace internship\controller;
- use n2n\web\http\controller\ControllerAdapter;
- use n2n\context\attribute\Inject;
- use internship\model\CommentDao;
- use n2n\web\http\PageNotFoundException;
- class CommentApiController extends ControllerAdapter {
- #[Inject]
- private CommentDao $commentDao;
- function getDoComments(): void {
- $this->sendJson($this->commentDao->getComments());
- }
- function getDoComment(int $commentId): void {
- $comment = $this->commentDao->getCommentById($commentId);
- if($comment === null) {
- throw new PageNotFoundException();
- } else {
- $this->sendJson($comment);
- }
- }
- }
|