-
Notifications
You must be signed in to change notification settings - Fork 0
REST principles and best practices #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| return new JsonResponse(['status' => 'ok']); | ||
| } | ||
|
|
||
| public function list() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's keep index() is more semantical in terms on REST APIs
| public function list() | |
| public function index() |
| $address->setNumber($request->get('number')); | ||
| $address->setCity($request->get('city')); | ||
|
|
||
| $clinic = new Clinic(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, continue using forms
| return new JsonResponse(['msg' => 'Clinic not found!'], Response::HTTP_NOT_FOUND); | ||
| } | ||
|
|
||
| $address = $clinic->getAddress(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid to do that, please continue using forms
| $entityManager->flush(); | ||
|
|
||
| $response = new Response('Pet created whit success!', Response::HTTP_CREATED); | ||
| $response->headers->set('Location', '/some/programmer/url'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's that?
| if (empty($pet)) { | ||
| return new JsonResponse(['msg' => 'Pet not found!'], Response::HTTP_NOT_FOUND); | ||
| } | ||
| // reference: https://symfonycasts.com/screencast/symfony-rest/form-post |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this comment
| if (!empty($pet->getPetName())) { | ||
| $entityManager = $this->getDoctrine()->getManager(); | ||
| $entityManager->flush(); | ||
| $pet = new Pet(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't make sense. Why are you instantiating a new Pet object here?
|
|
||
| return new JsonResponse(['msg' => 'Check the empty fields'], Response::HTTP_NOT_ACCEPTABLE); | ||
| $response = new Response('Pet edited whit success!', Response::HTTP_OK); | ||
| $response->headers->set('Location', '/some/programmer/url'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/some/programmer/url?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On line 80: In a video lesson, is done a recommendation for send an URL where consumer can view the entered data, but i forgot of alter. Should i keep, fix or remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, could you please remove?
| return new JsonResponse(['msg' => 'We could not find'], Response::HTTP_NOT_ACCEPTABLE); | ||
| $response = new JsonResponse(['msg'=>'Clinic deleted whit success!'], Response::HTTP_OK); | ||
|
|
||
| return $response; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This return $response is unnecessary. You can just return the new JsonResponse object, like this:
| return $response; | |
| return new JsonResponse(['msg' => 'We could not find'], Response::HTTP_OK); |
In this PR i applied the best practices, following recommendations from issue #3