[Chapter9] WIP

This commit is contained in:
Carlos Buenosvinos
2022-03-06 21:48:17 +01:00
parent 1f596272bb
commit 7f4b80b6c9
3 changed files with 18 additions and 9 deletions

View File

@@ -22,14 +22,14 @@ final class CountFollowersController extends AbstractController
{
$httpCode = Response::HTTP_ACCEPTED;
$httpContent = [
'_meta' => [],
'meta' => [],
'data' => [],
];
$query = null;
try {
$query = CountFollowersQuery::ofAuthor($authorId);
$timeline = $queryBus->query($query);
$httpContent['_meta']['message_id'] = $query->messageId()?->toString();
$httpContent['data'] = $timeline;
} catch (AuthorDoesNotExist $e) {
$httpCode = Response::HTTP_NOT_FOUND;
@@ -37,6 +37,8 @@ final class CountFollowersController extends AbstractController
} catch (InvalidArgumentException $e) {
$httpCode = Response::HTTP_INTERNAL_SERVER_ERROR;
$httpContent['data'] = $e->getMessage();
} finally {
$httpContent['meta']['message_id'] = $query?->messageId()?->toString();
}
return $this->json(

View File

@@ -28,10 +28,11 @@ final class GetTimelineController extends AbstractController
$httpCode = Response::HTTP_ACCEPTED;
$httpContent = [
'_meta' => [],
'meta' => [],
'data' => [],
];
$query = null;
try {
$query = TimelineQuery::fromArray([
'author_id' => $authorId,
@@ -40,7 +41,6 @@ final class GetTimelineController extends AbstractController
]);
$timeline = $queryBus->query($query);
$httpContent['_meta']['message_id'] = $query->messageId()?->toString();
$httpContent['data'] = $timeline;
} catch (AuthorDoesNotExist $e) {
$httpCode = Response::HTTP_NOT_FOUND;
@@ -48,6 +48,8 @@ final class GetTimelineController extends AbstractController
} catch (\InvalidArgumentException $e) {
$httpCode = Response::HTTP_INTERNAL_SERVER_ERROR;
$httpContent['data'] = $e->getMessage();
} finally {
$httpContent['meta']['message_id'] = $query?->messageId()?->toString();
}
return $this->json(

View File

@@ -20,22 +20,27 @@ final class SignUpAuthorController extends AbstractController
public function __invoke(Request $request, CommandBus $commandBus): Response
{
$httpCode = Response::HTTP_ACCEPTED;
$httpContent = [
'meta' => [],
'data' => [],
];
$command = null;
try {
$command = SignUpCommand::fromArray(
$this->getRequestContentInJson($request)
);
$commandBus->handle($command);
$httpContent = [
'message_id' => $command->messageId()?->toString(),
'author_id' => $command->authorId(),
];
$httpContent['data']['author_id'] = $command->authorId();
} catch (
AuthorAlreadyExists
|InvalidArgumentException $exception
) {
$httpCode = Response::HTTP_INTERNAL_SERVER_ERROR;
$httpContent = ['message' => $exception->getMessage()];
$httpContent['data']['message'] = $exception->getMessage();
} finally {
$httpContent['meta']['message_id'] = $command?->messageId()?->toString();
}
return $this->buildJsonResponse($httpContent, $httpCode);