-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathContractsController.php
More file actions
91 lines (81 loc) · 2.43 KB
/
ContractsController.php
File metadata and controls
91 lines (81 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Phparch\SpaceTraders\Controller;
use League\Route\Http\Exception\BadRequestException;
use Phparch\SpaceTraders\Attribute\Route;
use Phparch\SpaceTraders\Client;
use Phparch\SpaceTraders\Controller\Trait\RequestAwareController;
use Phparch\SpaceTraders\Controller\Trait\TwigAwareController;
use Phparch\SpaceTraders\Interface\RequestAware;
use Phparch\SpaceTraders\Interface\TwigAware;
use Psr\Http\Message\ResponseInterface;
class ContractsController implements RequestAware, TwigAware
{
use RequestAwareController;
use TwigAwareController;
public function __construct(
private Client\Contracts $client,
) {
}
/**
* @throws BadRequestException
*/
#[Route(
name: 'accept_contract',
path: '/contract/accept',
methods: ['POST'],
strategy: 'application'
)]
public function accceptContract(): ResponseInterface
{
/**
* @var array{
* id ?: string
* } $post
*/
$post = $this->getRequest()->getParsedBody();
if (!isset($post['id']) || !$post['id']) {
throw new BadRequestException("Contract ID is required");
}
$contract = $this->client->accept($post['id']);
$contracts = $this->client->myContracts();
return $this->render('contracts/accept.html.twig', [
'contract' => $contract,
'contracts' => $contracts->contracts,
]);
}
#[Route(
name: 'list_contracts',
path: '/contracts/',
methods: ['GET'],
strategy: 'application'
)]
public function list(): ResponseInterface
{
$contracts = $this->client->MyContracts()->contracts;
return $this->render('contracts/list.html.twig', [
'contracts' => $contracts,
]);
}
#[Route(
name: 'get_contract',
path: '/contracts/get/',
methods: ['GET'],
strategy: 'application'
)]
public function get(): ResponseInterface
{
/**
* @var array{
* id ?: string
* } $get
*/
$get = $this->getRequest()->getQueryParams();
if (!isset($get['id']) || !$get['id']) {
throw new BadRequestException("Contract ID is required");
}
$contract = $this->client->details($get['id']);
return $this->render('contracts/details.html.twig', [
'contract' => $contract,
]);
}
}