Completed
Push — master ( 9af059...286024 )
by Luc
12s
created

CompanyController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\Company\Controllers;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\Serializer\SerializerInterface;
8
use VSV\GVQ_API\Company\Models\Company;
9
use VSV\GVQ_API\Company\Repositories\CompanyRepository;
10
11
class CompanyController
12
{
13
    /**
14
     * @var CompanyRepository
15
     */
16
    private $companyRepository;
17
18
    /**
19
     * @var SerializerInterface
20
     */
21
    private $companySerializer;
22
23
    /**
24
     * @param CompanyRepository $companyRepository
25
     * @param SerializerInterface $companySerializer
26
     */
27
    public function __construct(
28
        CompanyRepository $companyRepository,
29
        SerializerInterface $companySerializer
30
    ) {
31
        $this->companyRepository = $companyRepository;
32
        $this->companySerializer = $companySerializer;
33
    }
34
35
    /**
36
     * @param Request $request
37
     * @return Response
38
     */
39
    public function save(Request $request): Response
40
    {
41
        $json = $request->getContent();
42
        /** @var Company $company */
43
        $company = $this->companySerializer->deserialize($json, Company::class, 'json');
44
45
        $this->companyRepository->save($company);
46
47
        $response = new Response('{"id":"'.$company->getId()->toString().'"}');
48
        $response->headers->set('Content-Type', 'application/json');
49
50
        return $response;
51
    }
52
}
53