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

✨ [#147] Convenience endpoint for Klantcontact/Betrokkene/Onderwerpobject #260

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

stevenbal
Copy link
Collaborator

@stevenbal stevenbal commented Oct 3, 2024

Fixes #147

Changes

  • Convenience endpoint for Klantcontact/Betrokkene/Onderwerpobject
  • Fix incorrect viewname for onderwerpobject URL attribute
  • Add typehints to remove redoc warnings
  • Fix tests not running in CI due to changed-files action

TODO:

  • rename endpoint to maak-klantcontact

@stevenbal stevenbal marked this pull request as draft October 3, 2024 13:38
@stevenbal stevenbal force-pushed the feature/147-convenience-endpoint branch 5 times, most recently from 4709654 to d03fd1b Compare October 3, 2024 14:38
@stevenbal stevenbal marked this pull request as ready for review October 3, 2024 14:42
@@ -48,6 +49,11 @@
router.register("betrokkenen", BetrokkeneViewSet)
router.register("onderwerpobjecten", OnderwerpobjectViewSet)
router.register("bijlagen", BijlageViewSet)
router.register(
"klantcontact-convenience",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

not sure how else I could name it without being way too long 😬

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is a good name 👍

@stevenbal
Copy link
Collaborator Author

stevenbal commented Oct 3, 2024

I had several questions, mostly related to the datamodel itself, because I haven't looked at it before:

  • should it be possible to pass Onderwerpobject.wasKlantcontact via convenience endpoint? Why does this field exist in the first place? -> yes
  • should it be possible to create without Onderwerpobject? -> yes
  • why does Betrokkene have had_klantcontact/klantcontact and was_partij/partij? -> naming to avoid having to use "was_partij" everywhere in the code

@stevenbal stevenbal force-pushed the feature/147-convenience-endpoint branch from dc1e6ba to 61d3f1f Compare October 7, 2024 14:28
@joeribekker
Copy link
Member

@stevenbal nog even bespreken? Voordat je merged :)

@stevenbal
Copy link
Collaborator Author

@joeribekker ja dat lijkt me goed, was ook nog niet van plan het te mergen :p

@joeribekker
Copy link
Member

@stevenbal please contact me on Slack to discuss when you pick this up again.

@stevenbal
Copy link
Collaborator Author

@bart-maykin I discussed with Joeri and I made both Betrokkene and OnderwerpObject optional on the convenience endpoint

Copy link
Contributor

Choose a reason for hiding this comment

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

You should be able to rebase onto master whenever #268 gets merged

@@ -367,7 +367,7 @@ class Meta:
extra_kwargs = {
"uuid": {"read_only": True},
"url": {
"view_name": "klantinteracties:klantcontact-detail",
"view_name": "klantinteracties:onderwerpobject-detail",
Copy link
Contributor

Choose a reason for hiding this comment

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

🙈

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure how this wasn't caught by tests 😬

Create the objects and use the original serializers to ensure all the correct
fields show up in the response
"""
klantcontact_data = validated_data["klantcontact"]
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens here when no klantcontact was given in the request data? Will it raise a KeyError?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Because it is required on the serializer, you will get a validation error:

{
  "type": "http://localhost:8000/ref/fouten/ValidationError/",
  "code": "invalid",
  "title": "Invalid input.",
  "status": 400,
  "detail": "",
  "instance": "urn:uuid:5f54a6d6-5327-4ad5-a831-27b7be3c1035",
  "invalidParams": [
    {
      "name": "klantcontact",
      "code": "required",
      "reason": "Dit veld is vereist."
    }
  ]
}

@@ -48,6 +49,11 @@
router.register("betrokkenen", BetrokkeneViewSet)
router.register("onderwerpobjecten", OnderwerpobjectViewSet)
router.register("bijlagen", BijlageViewSet)
router.register(
"klantcontact-convenience",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is a good name 👍

src/openklant/components/klantinteracties/api/urls.py Outdated Show resolved Hide resolved
src/openklant/components/klantinteracties/api/urls.py Outdated Show resolved Hide resolved
betrokkene = None
if betrokkene_data := validated_data.pop("betrokkene", None):
betrokkene_data["had_klantcontact"] = {"uuid": str(klantcontact.uuid)}
# TODO for some reason `was_partij` is converted to `partij` by the serializer
Copy link
Contributor

Choose a reason for hiding this comment

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

It is caused by the source option given to the was_partij field

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm I see, I don't think there's a way around this, since it always gets deserialized to partij right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I never knew this was how the source option behaved 😮. The comment can be removed though right?

previously this used the Klantcontact view, causing incorrect URLs to appear in the detail response for the Onderwerpobject endpoint
…ject

to allow creation of these three resources in a single API call
… endpoint

because it should be possible to create e.g.:
- a KlantContact with a Betrokkene but no OnderwerpObject
- a KlantContact with an OnderwerpObject but no Betrokkene
@stevenbal stevenbal force-pushed the feature/147-convenience-endpoint branch from 8c883f0 to 424d9fb Compare October 18, 2024 08:57
@stevenbal stevenbal force-pushed the feature/147-convenience-endpoint branch from 424d9fb to ba76269 Compare October 18, 2024 09:11
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice this saved the tests some code 👍

"""

serializer_class = KlantContactConvenienceSerializer
authentication_classes = (TokenAuthentication,)
Copy link
Contributor

Choose a reason for hiding this comment

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

In think this should be the default for the API but is not part of the ticket 😀

betrokkene = None
if betrokkene_data := validated_data.pop("betrokkene", None):
betrokkene_data["had_klantcontact"] = {"uuid": str(klantcontact.uuid)}
# TODO for some reason `was_partij` is converted to `partij` by the serializer
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I never knew this was how the source option behaved 😮. The comment can be removed though right?

@stevenbal stevenbal marked this pull request as draft October 22, 2024 10:42
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.

Gecombineerd API endpoint om klantcontact, betrokkene en onderwerpobject te maken
4 participants