Skip to content

Commit a69d0d0

Browse files
Return 404 when user is not found
1 parent 93c82c0 commit a69d0d0

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

composer.lock

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Controllers/Attachments/UploadAttachmentController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
class UploadAttachmentController extends Controller
1414
{
1515
public function __construct(protected readonly AttachmentRepository $attachmentRepository,
16-
protected readonly AttachmentFilePath $attachmentFilePathService,
17-
protected readonly RedisServer $redisServer)
16+
protected readonly AttachmentFilePath $attachmentFilePathService,
17+
protected readonly RedisServer $redisServer)
1818
{
1919
}
2020

@@ -31,7 +31,7 @@ public function __invoke(ServerRequestInterface $request, array $args): array
3131
$index = 0;
3232
foreach ($files as $file) {
3333
/** @var UploadedFileInterface $file */
34-
$this->logger->debug('file uploaded', ['filename' => $file->getClientFilename(), 'type' => $file->getClientMediaType(), 'size' => $file->getSize()]);
34+
$this->logger()->debug('file uploaded', ['filename' => $file->getClientFilename(), 'type' => $file->getClientMediaType(), 'size' => $file->getSize()]);
3535
$attachment = $this->uploadAttachment($file, $parentType, $parentId, $userId);
3636

3737
if ('command' === $parentType) {
@@ -43,7 +43,7 @@ public function __invoke(ServerRequestInterface $request, array $args): array
4343
])
4444
);
4545
if (false === $queueLen) {
46-
$this->logger->error('Item could not be pushed to the queue', ['queue' => 'tasks-results:queue']);
46+
$this->logger()->error('Item could not be pushed to the queue', ['queue' => 'tasks-results:queue']);
4747
}
4848
}
4949

src/Controllers/Users/GetUserController.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Reconmap\Controllers\Users;
44

5+
use Psr\Http\Message\ResponseInterface;
56
use Psr\Http\Message\ServerRequestInterface;
67
use Reconmap\Controllers\Controller;
78
use Reconmap\Repositories\UserRepository;
@@ -12,13 +13,16 @@ public function __construct(private readonly UserRepository $userRepository)
1213
{
1314
}
1415

15-
public function __invoke(ServerRequestInterface $request, array $args): array
16+
public function __invoke(ServerRequestInterface $request, array $args): array|ResponseInterface
1617
{
1718
$userId = (int)$args['userId'];
1819

1920
$user = $this->userRepository->findById($userId);
2021

21-
22+
if (null === $user) {
23+
return $this->createNotFoundResponse();
24+
}
25+
2226
if (is_string($user['preferences']) && json_validate($user['preferences'])) {
2327
$user['preferences'] = json_decode($user['preferences'], true);
2428
} else {

tests/Controllers/Attachments/UploadAttachmentControllerTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Reconmap\Controllers\Attachments;
44

5+
use Monolog\Logger;
6+
use Psr\Container\ContainerInterface;
57
use Psr\Http\Message\ServerRequestInterface;
68
use Psr\Http\Message\UploadedFileInterface;
79
use Reconmap\ControllerTestCase;
@@ -67,7 +69,13 @@ public function testHappyPath()
6769

6870
$args = ['attachmentId' => $fakeAttachmentId];
6971

72+
$mockContainer = $this->createMock(ContainerInterface::class);
73+
$mockContainer->expects($this->once())
74+
->method('get')
75+
->willReturn($this->createStub(Logger::class));
76+
7077
$controller = $this->injectController(new UploadAttachmentController($mockAttachmentRepository, $mockAttachmentFilePath, $mockRedisServer));
78+
$controller->setContainer($mockContainer);
7179
$response = $controller($mockRequest, $args);
7280

7381
$this->assertTrue($response['success']);

0 commit comments

Comments
 (0)