GeriLife / companionship

Promoting companionship and well-being for everyone.
European Union Public License 1.2
7 stars 18 forks source link

Add rest API endpoints to Circles to allow CRUD requests #213

Open werberger opened 1 year ago

werberger commented 1 year ago

This resolves issue #195.

@brylie please review and give me any feedback. I have tested using the Browsable API and Postman.

Test coverage was 83% isort and black both run.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 81.25% and project coverage change: -0.04 :warning:

Comparison is base (9343835) 82.48% compared to head (76ef839) 82.44%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #213 +/- ## ========================================== - Coverage 82.48% 82.44% -0.04% ========================================== Files 23 24 +1 Lines 508 524 +16 ========================================== + Hits 419 432 +13 - Misses 89 92 +3 ``` | [Impacted Files](https://codecov.io/gh/CompanionshipCare/companionship-care/pull/213?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CompanionshipCare) | Coverage Δ | | |---|---|---| | [project/circles/views.py](https://codecov.io/gh/CompanionshipCare/companionship-care/pull/213?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CompanionshipCare#diff-cHJvamVjdC9jaXJjbGVzL3ZpZXdzLnB5) | `56.80% <70.00%> (+1.14%)` | :arrow_up: | | [project/circles/serializers.py](https://codecov.io/gh/CompanionshipCare/companionship-care/pull/213?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CompanionshipCare#diff-cHJvamVjdC9jaXJjbGVzL3NlcmlhbGl6ZXJzLnB5) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CompanionshipCare). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CompanionshipCare)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

brylie commented 1 year ago

This looks good so far, in that it creates a view that lists all circles.

The next step would be to return only the circles that the requesting user has the right to view. Check the code for the existing "circles" view to get an idea of how to narrow down the queryset.

https://github.com/CompanionshipCare/companionship-care/blob/9343835b92c1ba0202a03f7b8eff60ac727c37de/project/circles/templates/circles/circle_list.html#L23

werberger commented 1 year ago

I have got this working. At least it works in Postman. However attempting a GET request in the browser returns:

"detail": "Authentication credentials were not provided."

I have attempted including the token as part of the url, i.e.

http://127.0.0.1:8000/api/v1/circles/?format=api&Authorization=Token

as well as passing it as a query parameter, i.e. in the browser console, using

document.cookie = 'Authorization=Token ;'

but neither of these solutions work

Assuming this doesn't matter I'll update the PR. But if it does matter, would appreciate some suggestions.

brylie commented 1 year ago

Typically, authorization tokens are passed in via a request header. See the following document for more details about authorizing requests with Postman: https://learning.postman.com/docs/sending-requests/authorization/

werberger commented 1 year ago

Typically, authorization tokens are passed in via a request header. See the following document for more details about authorizing requests with Postman: https://learning.postman.com/docs/sending-requests/authorization/

Is this article not talking about passing them in Postman? I have it working in Postman. It is in the browsable API that I can't get it working.

werberger commented 1 year ago

@brylie I managed to get it working - I needed to use a browser extension to edit the header.

brylie commented 1 year ago

Ah, I understand. FWIW, we don't need to test these API endpoints in a browser since they will be used in a mobile client. Only Postman should be necessary, along with automated tests from Python.

werberger commented 1 year ago

To explain the rogue activity on this PR, I pushed my work on #197 which automatically added it to this PR. I subsequently reverted the commits.

I hope I haven't caused any issues @brylie. Please let me know if there was a better way to have dealt with this.