Skip to content

Commit 41499ff

Browse files
authored
Merge pull request #24 from niden-code/1.x
Video 12
2 parents e3896e9 + 172ca5c commit 41499ff

File tree

133 files changed

+9501
-525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+9501
-525
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
- '8.2'
4242
- '8.3'
4343
- '8.4'
44+
- '8.5'
4445
steps:
4546
- uses: actions/checkout@v4
4647

@@ -81,6 +82,7 @@ jobs:
8182
- '8.2'
8283
- '8.3'
8384
- '8.4'
85+
- '8.5'
8486

8587
services:
8688
mariadb:

docker-compose.yml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,34 @@ services:
7171
networks:
7272
- app-network
7373
environment:
74-
- PHP_IDE_CONFIG=serverName=rest-api-app-83
74+
- PHP_IDE_CONFIG=serverName=rest-api-app-84
75+
- APP_ENV=development
76+
- APP_ENV_ADAPTER=dotenv
77+
healthcheck:
78+
test: ["CMD", "curl", "-f", "http://localhost/fpm-ping"]
79+
interval: 30s
80+
timeout: 3s
81+
retries: 3
82+
start_period: 5s
83+
84+
app-8.5:
85+
build:
86+
dockerfile: ./resources/docker/Dockerfile
87+
args:
88+
PHP_VERSION: 8.5
89+
hostname: rest-api-app-85
90+
container_name: "${PROJECT_NAME}-api-8.5"
91+
tty: true
92+
working_dir: /app
93+
volumes:
94+
- ./:/app
95+
depends_on:
96+
- app-db
97+
- app-cache
98+
networks:
99+
- app-network
100+
environment:
101+
- PHP_IDE_CONFIG=serverName=rest-api-app-85
75102
- APP_ENV=development
76103
- APP_ENV_ADAPTER=dotenv
77104
healthcheck:
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Phinx\Migration\AbstractMigration;
6+
7+
final class AddCompaniesTable extends AbstractMigration
8+
{
9+
public function down(): void
10+
{
11+
$this->table('co_companies')->drop()->save();
12+
}
13+
14+
public function up(): void
15+
{
16+
$table = $this->table(
17+
'co_companies',
18+
[
19+
'id' => 'com_id',
20+
'signed' => false,
21+
]
22+
);
23+
24+
$table
25+
->addColumn(
26+
'com_name',
27+
'string',
28+
[
29+
'limit' => 128,
30+
'null' => false,
31+
'default' => '',
32+
]
33+
)
34+
->addColumn(
35+
'com_phone',
36+
'string',
37+
[
38+
'limit' => 32,
39+
'null' => false,
40+
'default' => '',
41+
]
42+
)
43+
->addColumn(
44+
'com_email',
45+
'string',
46+
[
47+
'limit' => 128,
48+
'null' => false,
49+
'default' => '',
50+
]
51+
)
52+
->addColumn(
53+
'com_website',
54+
'string',
55+
[
56+
'limit' => 128,
57+
'null' => false,
58+
'default' => '',
59+
]
60+
)
61+
->addColumn(
62+
'com_address_line_1',
63+
'string',
64+
[
65+
'limit' => 128,
66+
'null' => false,
67+
'default' => '',
68+
]
69+
)
70+
->addColumn(
71+
'com_address_line_2',
72+
'string',
73+
[
74+
'limit' => 128,
75+
'null' => false,
76+
'default' => '',
77+
]
78+
)
79+
->addColumn(
80+
'com_city',
81+
'string',
82+
[
83+
'limit' => 128,
84+
'null' => false,
85+
'default' => '',
86+
]
87+
)
88+
->addColumn(
89+
'com_state_province',
90+
'string',
91+
[
92+
'limit' => 64,
93+
'null' => false,
94+
'default' => '',
95+
]
96+
)
97+
->addColumn(
98+
'com_zip_code',
99+
'string',
100+
[
101+
'limit' => 32,
102+
'null' => false,
103+
'default' => '',
104+
]
105+
)
106+
->addColumn(
107+
'com_country',
108+
'string',
109+
[
110+
'limit' => 8,
111+
'null' => false,
112+
'default' => '',
113+
]
114+
)
115+
->addColumn(
116+
'com_created_date',
117+
'timestamp',
118+
[
119+
'timezone' => true,
120+
'default' => 'CURRENT_TIMESTAMP',
121+
]
122+
)
123+
->addColumn(
124+
'com_created_usr_id',
125+
'biginteger',
126+
[
127+
'null' => false,
128+
'default' => 0,
129+
]
130+
)
131+
->addColumn(
132+
'com_updated_date',
133+
'timestamp',
134+
[
135+
'timezone' => true,
136+
'default' => null,
137+
]
138+
)
139+
->addColumn(
140+
'com_updated_usr_id',
141+
'biginteger',
142+
[
143+
'null' => false,
144+
'default' => 0,
145+
]
146+
)
147+
->addIndex(
148+
[
149+
'com_name',
150+
],
151+
[
152+
'name' => 'i_name',
153+
]
154+
)
155+
->addIndex(
156+
[
157+
'com_email',
158+
],
159+
[
160+
'name' => 'i_email',
161+
]
162+
)
163+
->addIndex(
164+
[
165+
'com_city',
166+
],
167+
[
168+
'name' => 'i_city',
169+
]
170+
)
171+
->addIndex(
172+
[
173+
'com_state_province',
174+
],
175+
[
176+
'name' => 'i_state_province',
177+
]
178+
)
179+
->addIndex(
180+
[
181+
'com_country',
182+
],
183+
[
184+
'name' => 'i_country',
185+
]
186+
)
187+
->save()
188+
;
189+
}
190+
}

src/Domain/ADR/InputTypes.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@
2929
* token?: string
3030
* }
3131
*
32+
* @phpstan-type TCompanyInput array{
33+
* id?: int,
34+
* name?: string,
35+
* phone?: string,
36+
* email?: string,
37+
* website?: string,
38+
* addressLine1?: string,
39+
* addressLine2?: string,
40+
* city?: string,
41+
* stateProvince?: string,
42+
* zipCode?: string,
43+
* country?: string,
44+
* createdDate?: string,
45+
* createdUserId?: int,
46+
* updatedDate?: string,
47+
* updatedUserId?: int,
48+
* page?: int,
49+
* perPage?: int
50+
* }
51+
*
3252
* @phpstan-type TUserInput array{
3353
* id?: int,
3454
* status?: int,

src/Domain/Application/Auth/Facade/AuthFacade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
final readonly class AuthFacade
2727
{
2828
/**
29-
* @param CommandBusInterface $bus
29+
* @param CommandBusInterface $bus
30+
* @param AuthCommandFactoryInterface $factory
3031
*/
3132
public function __construct(
3233
private CommandBusInterface $bus,

src/Domain/Application/Auth/Handler/AbstractAuthLogoutRefreshHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use Phalcon\Api\Domain\ADR\InputTypes;
1717
use Phalcon\Api\Domain\Infrastructure\CommandBus\HandlerInterface;
18+
use Phalcon\Api\Domain\Infrastructure\DataSource\Auth\Transformer\AuthTransformer;
1819
use Phalcon\Api\Domain\Infrastructure\DataSource\Validation\ValidatorInterface;
1920
use Phalcon\Api\Domain\Infrastructure\Encryption\TokenManagerInterface;
2021

@@ -25,10 +26,12 @@ abstract class AbstractAuthLogoutRefreshHandler implements HandlerInterface
2526
{
2627
/**
2728
* @param TokenManagerInterface $tokenManager
29+
* @param AuthTransformer $transformer
2830
* @param ValidatorInterface $validator
2931
*/
3032
public function __construct(
3133
protected readonly TokenManagerInterface $tokenManager,
34+
protected readonly AuthTransformer $transformer,
3235
protected readonly ValidatorInterface $validator,
3336
) {
3437
}

src/Domain/Application/Auth/Handler/AuthLoginPostHandler.php

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Phalcon\Api\Domain\Application\Auth\Command\AuthLoginPostCommand;
1919
use Phalcon\Api\Domain\Infrastructure\CommandBus\CommandInterface;
2020
use Phalcon\Api\Domain\Infrastructure\CommandBus\HandlerInterface;
21+
use Phalcon\Api\Domain\Infrastructure\DataSource\Auth\Transformer\AuthTransformer;
2122
use Phalcon\Api\Domain\Infrastructure\DataSource\User\Repository\UserRepositoryInterface;
2223
use Phalcon\Api\Domain\Infrastructure\DataSource\Validation\ValidatorInterface;
2324
use Phalcon\Api\Domain\Infrastructure\Encryption\Security;
@@ -27,19 +28,21 @@
2728
/**
2829
* @phpstan-import-type TAuthLoginInput from InputTypes
2930
*/
30-
final class AuthLoginPostHandler implements HandlerInterface
31+
final readonly class AuthLoginPostHandler implements HandlerInterface
3132
{
3233
/**
3334
* @param UserRepositoryInterface $repository
3435
* @param TokenManagerInterface $tokenManager
36+
* @param AuthTransformer $transformer
3537
* @param Security $security
3638
* @param ValidatorInterface $validator
3739
*/
3840
public function __construct(
39-
private readonly UserRepositoryInterface $repository,
40-
private readonly TokenManagerInterface $tokenManager,
41-
private readonly Security $security,
42-
private readonly ValidatorInterface $validator
41+
private UserRepositoryInterface $repository,
42+
private TokenManagerInterface $tokenManager,
43+
private AuthTransformer $transformer,
44+
private Security $security,
45+
private ValidatorInterface $validator
4346
) {
4447
}
4548

@@ -87,22 +90,6 @@ public function __invoke(CommandInterface $command): Payload
8790
*/
8891
$tokens = $this->tokenManager->issue($domainUser);
8992

90-
/**
91-
* Construct the response
92-
*/
93-
$results = [
94-
'authenticated' => true,
95-
'user' => [
96-
'id' => $domainUser->id,
97-
'name' => $domainUser->fullName(),
98-
'email' => $domainUser->email,
99-
],
100-
'jwt' => [
101-
'token' => $tokens['token'],
102-
'refreshToken' => $tokens['refreshToken'],
103-
],
104-
];
105-
106-
return Payload::success($results);
93+
return Payload::success($this->transformer->login($domainUser, $tokens));
10794
}
10895
}

src/Domain/Application/Auth/Handler/AuthLogoutPostHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public function __invoke(CommandInterface $command): Payload
4949

5050
$this->tokenManager->revoke($domainUser);
5151

52-
return Payload::success(['authenticated' => false]);
52+
return Payload::success($this->transformer->logout());
5353
}
5454
}

src/Domain/Application/Auth/Handler/AuthRefreshPostHandler.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ public function __invoke(CommandInterface $command): Payload
4949

5050
$tokens = $this->tokenManager->refresh($domainUser);
5151

52-
return Payload::success([
53-
'token' => $tokens['token'],
54-
'refreshToken' => $tokens['refreshToken'],
55-
]);
52+
return Payload::success($this->transformer->refresh($tokens));
5653
}
5754
}

0 commit comments

Comments
 (0)