Skip to content

Commit 746e885

Browse files
committed
some fix
1 parent 516f514 commit 746e885

File tree

7 files changed

+30
-16
lines changed

7 files changed

+30
-16
lines changed

api/config/packages/messenger.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ framework:
1616
'App\Consumer\Handler\DeleteArchive': async
1717
'App\Consumer\Handler\CleanOldArchives': async
1818

19-
# when@test:
20-
# framework:
21-
# messenger:
22-
# transports:
23-
# # replace with your transport name here (e.g., my_transport: 'in-memory://')
24-
# # For more Messenger testing tools, see https://github.com/zenstruck/messenger-test
25-
# async: 'in-memory://'
26-
27-
2819
when@dev:
2920
framework:
3021
messenger:

api/src/Api/Processor/ArchiveProcessor.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,27 @@ public function __construct(
4545

4646
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): Archive
4747
{
48-
$isNew = !isset($context[AbstractItemNormalizer::OBJECT_TO_POPULATE]);
4948

49+
$isNew = false;
50+
if ($operation instanceof \ApiPlatform\Metadata\Post) {
51+
$isNew = true;
52+
}
53+
5054
$this->validator->validate($data, [
5155
'groups' => [
5256
'Default',
5357
$isNew ? 'Post' : 'Patch',
5458
],
5559
]);
5660

57-
$object = $context[AbstractItemNormalizer::OBJECT_TO_POPULATE] ?? new Archive();
61+
if ($isNew) {
62+
$object = new Archive();
63+
} else {
64+
$object = $this->em->find(Archive::class, $uriVariables['id']);
65+
if (null === $object) {
66+
throw new BadRequestHttpException('Archive not found');
67+
}
68+
}
5869

5970
if (null !== $data->getDownloadFilename()) {
6071
$object->setDownloadFilename($data->getDownloadFilename());

api/src/Consumer/Handler/CleanOldArchives.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace App\Consumer\Handler;
66

7-
class CleanOldArchives extends BuildArchive
7+
class CleanOldArchives
88
{
99

1010
}

api/src/Consumer/Handler/DeleteArchive.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
namespace App\Consumer\Handler;
66

7-
class DeleteArchive extends BuildArchive
7+
class DeleteArchive
88
{
9+
public function __construct(private string $id)
10+
{
11+
}
912

13+
public function getId(): string
14+
{
15+
return $this->id;
16+
}
1017
}

api/src/Entity/Archive.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
processor: ArchiveProcessor::class
3838
),
3939
new Get(),
40-
new Patch(),
40+
new Patch(
41+
input: ArchiveInput::class,
42+
processor: ArchiveProcessor::class
43+
),
4144
new Delete(),
4245
],
43-
input: ArchiveInput::class,
4446
output: ArchiveOutput::class
4547
)]
4648
#[ORM\Entity(repositoryClass: ArchiveRepository::class)]

api/tests/Archive/ArchiveApiTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testPatchArchive(): void
8383
$this->assertEquals(200, $response->getStatusCode());
8484

8585
$archive = $this->getArchiveFromDatabase($archive->getId());
86-
// $this->expectedFiles($files, $archive);
86+
$this->expectedFiles($files, $archive);
8787
}
8888

8989
public function testDeleteArchive(): void

api/tests/Archive/PostArchiveApiTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ private function doTestPostArchiveOK(array $files, array $options = []): void
9494
$this->assertEquals('created', $json['status']);
9595
$this->assertArrayHasKey('downloadUrl', $json);
9696
$this->assertMatchesRegularExpression(sprintf('#^http://localhost/archives/%s/download\?jwt=.+$#', $id), $json['downloadUrl']);
97+
98+
$archive = $this->getArchiveFromDatabase($id);
99+
$this->expectedFiles($files, $archive);
97100
}
98101

99102
public function testPostArchiveWithEmptyIdentifierReturns422(): void

0 commit comments

Comments
 (0)