Skip to content
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

Feature/46 producttype nl api #23

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

Floris272
Copy link
Contributor

@Floris272 Floris272 commented Dec 11, 2024

Changes

  • Adds the producttypen api

Notes

  • location, organisation & contact will be added in a later pr.
  • api will get refactored after all viewsets/serializers are done.

@Floris272 Floris272 self-assigned this Dec 11, 2024
@Floris272 Floris272 requested a review from Coperh December 11, 2024 11:52
@Floris272 Floris272 linked an issue Dec 13, 2024 that may be closed by this pull request
Copy link

@Coperh Coperh left a comment

Choose a reason for hiding this comment

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

Generally looks good I think. Nothing is broken. The use of the exclude field is generally bad

From the default project:

Check that ModelForms use Meta.fields instead of Meta.exclude.

ModelForm.Meta.exclude is dangerous because it doesn't protect against
fields that are added later. Explicit white-listing is safer and prevents
bugs such as IMA #645.

Also a few questions and random remarks

Should be Changed (or can be changed quickly):

  • Formatted translation might cause issues
  • Useself.get_queryset()instead of the model
  • use fields = (.....) instead of exclude = (.....) ==> easier to understand and removes unexpected fields
  • Reverses instead of hard coded URLS

Could Be Changed:

  • Should use self.client get/post/patch/put instead of BaseApiTestCase methods
  • Test that fields are actually set on basic creation tests
  • Perform database stuff after validation i.e. do not perform if not validated
  • Related to the last: only test for errors if the field is not none

Minor Suggestions:

  • Simple serializers not in the files matching their name
  • Might want to move API to separate direction but that can probably wait or just not be done
  • router.py should be urls.py
  • using a nested router for actuele-prijzen I think?
  • (Some) validation can be moved to validators
  • Could use DRF status enum
  • Some better ordering in prijs update

I will not be here next week, so I cannot review changes for a while

from open_producten.producttypen.models import Bestand, ProductType


# TODO does not have viewset
Copy link

Choose a reason for hiding this comment

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

Is this still the case?

Copy link

Choose a reason for hiding this comment

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

Yes. Is there a reason why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Bestand needs a special serializer to be able to upload files which I not gotten working.

src/open_producten/utils/serializers.py Outdated Show resolved Hide resolved
src/open_producten/producttypen/router.py Outdated Show resolved Hide resolved
src/open_producten/producttypen/views.py Show resolved Hide resolved
serializer_class=ProductTypeActuelePrijsSerializer,
url_path="actuele-prijzen",
)
def actuele_prijzen(self, request):
Copy link

Choose a reason for hiding this comment

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

This seems wrong to me or at least the URL.

What if in the future you want prices but for one product type?
Should it not be all producttypen/alles-actuele-prijzen/
or is producttypen/actuele-prijzen/ for all and producttypen/<id>/actuele-prijzen/ for one fine?

Not too familiar with API design TBH. Might be something you want to ask in slack

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added producttypen/<id>/actuele-prijs. This also seems to be the correct way in drf using @action(detail=True)

src/open_producten/producttypen/tests/api/test_prijs.py Outdated Show resolved Hide resolved

def test_update_prijs_creating_and_deleting_opties(self):
prijs = self._create_prijs()
PrijsOptieFactory.create(prijs=prijs)
Copy link

Choose a reason for hiding this comment

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

prijs_optie = PrijsOptieFactory.create(prijs=prijs)

if you delete prijs_optie, its id will be set to -1 which might be useful. Not sure if it works with custom ids though

src/open_producten/producttypen/tests/api/test_prijs.py Outdated Show resolved Hide resolved
src/open_producten/producttypen/tests/api/test_prijs.py Outdated Show resolved Hide resolved
@Floris272
Copy link
Contributor Author

Should be Changed (or can be changed quickly):

Formatted translation might cause issues
Useself.get_queryset()instead of the model
use fields = (.....) instead of exclude = (.....) ==> easier to understand and removes unexpected fields
Reverses instead of hard coded URLS

Could Be Changed:

Should use self.client get/post/patch/put instead of BaseApiTestCase methods Kept BaseApiTestCase for client login
Test that fields are actually set on basic creation tests
Perform database stuff after validation i.e. do not perform if not validated
Related to the last: only test for errors if the field is not none

Minor Suggestions:

Simple serializers not in the files matching their name -> what to do about circular dependency?
Might want to move API to separate direction but that can probably wait or just not be done Will be done in future pr
router.py should be urls.py
using a nested router for actuele-prijzen I think? -> added detail variant producttypen/<id>/actuele-prijs
(Some) validation can be moved to validators
Could use DRF status enum
Some better ordering in prijs update

  • Moved clean validation to seperate method that is called inside the model.clean and inside a Validator on the serializer.
  • replaced Treebeard with an FK to self for onderwerp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nederlandstalige API + Datamodel
2 participants