|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace VSV\GVQ_API\Question\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
7
|
|
|
use VSV\GVQ_API\Question\Models\Question; |
|
8
|
|
|
use VSV\GVQ_API\Question\Repositories\QuestionRepository; |
|
9
|
|
|
use VSV\GVQ_API\Question\Serializers\QuestionSerializer; |
|
10
|
|
|
|
|
11
|
|
|
class QuestionController |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var QuestionSerializer |
|
15
|
|
|
*/ |
|
16
|
|
|
private $questionSerializer; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var QuestionRepository |
|
20
|
|
|
*/ |
|
21
|
|
|
private $questionRepository; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param QuestionSerializer $questionSerializer |
|
25
|
|
|
* @param QuestionRepository $questionRepository |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct( |
|
28
|
|
|
QuestionSerializer $questionSerializer, |
|
29
|
|
|
QuestionRepository $questionRepository |
|
30
|
|
|
) { |
|
31
|
|
|
$this->questionSerializer = $questionSerializer; |
|
32
|
|
|
$this->questionRepository = $questionRepository; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param Request $request |
|
37
|
|
|
* @return Response |
|
38
|
|
|
*/ |
|
39
|
|
|
public function create(Request $request): Response |
|
40
|
|
|
{ |
|
41
|
|
|
// @todo: check for missing id |
|
42
|
|
|
$json = $request->getContent(); |
|
43
|
|
|
|
|
44
|
|
|
/** @var Question $question */ |
|
45
|
|
|
$question = $this->questionSerializer->deserialize( |
|
46
|
|
|
$json, |
|
47
|
|
|
Question::class, |
|
48
|
|
|
'json' |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
$this->questionRepository->save($question); |
|
52
|
|
|
|
|
53
|
|
|
return new Response('QUESTION CREATED'); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getAll(Request $request): Response |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
return new Response('GETALL'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getById(Request $request, string $id): Response |
|
|
|
|
|
|
62
|
|
|
{ |
|
63
|
|
|
return new Response('GETBYID'); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.