Open martincodes-de opened 1 year ago
I assigned you both (@NiklasBGit @emsbe) because I think that would be a good beginner task for pairprogramming.
Would you construct the PollDataTransferObject like in #33 ? Meaning that this Object would expect a Poll, and two ints when an instance is created?
The converter method expects only 1 poll model and creates + returns the PollDataTransferObject. The Dto has only read-only properties and ofc only public attributes and no methods because it's a datatransferobject
The converter method expects only 1 poll model and creates + returns the PollDataTransferObject. The Dto has only read-only properties and ofc only public attributes and no methods because it's a datatransferobject
I disagree. The converter shouldn't do a db-request
i agree your disagreement
At this moment we want to return a poll at any endpoints with the calculated up- and downvotes like this object
The problem is that we have to calculate and build the response at any endpoint manual. We don't like manual in our team.
To have one consistent representation of a poll in our API and have one place to generate that object for a poll that we only call in our endpoints, we need a
PollDataTransferObject
andPollDataTransferObjectConverter
. (keyword: SOLID principles - single responsibility)PollDataTransferObject
Create a PollDataTransferObject in
app/DTOs/HttpApi/PollDataTransferObject.php
with all attributes from the json above with correct attributes + types (not PHPdoc) and as final & readonly class. Pay attention to namespaces.PollDataTransferObjectConverter
Create a PollDataTransferObjectConverter that has a public, non-static method
convert()
that takes 1Models/Poll
and returns aPollDataTransferObject
. The location should beapp/Converter/PollDataTransferObjectConverter.php
. Inside the convert-method, do the movement from model to data transfer object. Create some unit tests. After that, register the converter as a service to do dependency injection. Without that, we can't use the dependency injection from laravel.