Skip to content

implemented get and post for characters endpoint#7

Open
lithiil wants to merge 1 commit intomasterfrom
crud
Open

implemented get and post for characters endpoint#7
lithiil wants to merge 1 commit intomasterfrom
crud

Conversation

@lithiil
Copy link
Member

@lithiil lithiil commented Sep 24, 2019

Implemented get and post for character endpoints in order to have a basis for a discussion about the actual design.

@lithiil lithiil added the enhancement New feature or request label Sep 24, 2019
@lithiil lithiil added this to the Alpha milestone Sep 24, 2019
@lithiil lithiil requested a review from aifrim September 24, 2019 20:06
@lithiil lithiil self-assigned this Sep 24, 2019
return $response->withStatus(400, 'Invalid Json');
}
$characters = $request->getBody();
$GLOBALS['db']->dnd->characters->insertOne(json_decode($characters, true));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$character = new Character(json_decode($payload);
insert($character);

Only take from the $payload the actual properties you require.
Return a 400 Bad Request if the $payload does not have all the required properties.

$app->post('/characters', function (Request $request, Response $response) {
$request_type = $request->getHeader('CONTENT_TYPE');
if($request_type[0] != 'application/json'){
$response->getBody()->write('Only application/json accepted');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$response->getBody()->write('Character generated successfully');
return $response->withStatus(200);
foreach ($characters as $character) {
$response->getBody()->write(json_encode($character, JSON_PRETTY_PRINT));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to JSON_PRETTY_PRINT.
But if you really want to, only do so in development, not production.
Maybe use a env var to state the environment type?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants