Closed Ragnar-H closed 6 years ago
@skabbi this might be a decent medium sized issue to deal with if you want
@Ragnar-H I'm a bit unclear on the expected results. Should there be a "politicians" field under "district"?
Yes
Instead of it being
"district": {
"politicians": [
{
"name": "bbla",
"id": 1,
},
{
"name": "yeah",
"id": 2
}
]
}
It should be
"district": {
"politicians": [ 1, 2 ]
}
As in, it should not return the Politician
object, but the ids of each Politician
I imagine it using something like PrimaryKeyRelatedField for serialization
This can also be done in some other serializers. Not 100% sure which, but that requires some quick investigation :)
Quick question. The "district" field seems to be the same as when calling localhost:8000/api/v1/districts/
, e.g.
[
{
"name": "Reykjavik Norður",
"id": 1,
"abbreviation": "Reykv. N.",
"politicians": [
{
"name": "Andrés Ingi Jónsson",
"id": 1,
"initials": "AIJ",
"party": {
"name": "Vinstri Hreyfingin - Grænt Framboð",
"id": 3,
"website": "http://vg.is/",
"created": "2017-04-25T17:41:28Z",
"modified": "2017-04-25T17:41:28Z"
},
"promises": []
},
....
],
"created": "2017-04-25T17:41:28Z",
"modified": "2017-04-25T17:41:28Z"
},
...
]
Should the districts endpoint remain unchanged?
Some additional questions.
If i remember correctly the Icelandic translation is "Kjördæmanúmer" (see here) which I think is which seat they got from their district. Each district has X amount of seats (lets say 10 for district Y) so someone is nr 1, someone is nr 2 etc
All objects that inherit the Entity
object contain those fields. I think its nice to have created / modified for all objects just to keep track of them. Name is also pretty widely used for most objects. Abbreviation is sometimes used but nice to have the option.
On the frontend it will be possible to "getPoliticianById", where you supply the id and get the json object.
Yes, return the districtId :)
@AriHrannar Thanks for the reply, but I still have a few questions/comments.
I see, good explanation. A minor point; google translate says "Kjördæmi" translates to constituency not district, but I don't think it's worth changing if we all know what if refers to.
Ok, just wanted to make sure since the examples given for expected results don't include them.
So is the idea that when viewing a politician in the UI, it calls "getPoliticianById" for each ID and show a list of all politicians in the same district? My main reason for the original question was that this seems like data the UI should be getting from the districts endpoint, but I might be wrong.
I'm not sure we are on the same page. So just to be sure; I'm talking about since the main point of this issue is to remove duplicate data, that instead of returning e.g.
"district": { "id": 1, "politicians": [1, 7, ...], ... },
for each politician in same district, to simply return
"districtId: 1"
so data about districts can be fetched as needed.
Lastly, it would be nice to get an answer to my original question. "Should the districts endpoint remain unchanged?" Since the politician endpoint is sharing code with the districts endpoint.
/politicians
service and call it with a district
query parameter to filter politicians by district. Im not sure what is better but I imaging calling the /politicians
service with a district query parameter involves less code. @Ragnar-H thoughts?Lastly: Would be nice to also change the districts endpoint to return a list of politician ids instead of a list of politicians :)
Im gonna hijack this :)
Description
Due to some hacky solutions by yours truly, we've got some duplicates in the data returned by various HTTP calls
f.x.
GET http://localhost:8000/api/v1/politicians/
Note that there are more endpoints and serializers that I hacked. These should also be fixed
I hacked this together when we just wanted to get going with some UI components.
Steps to reproduce
Expected result
Since we're Reduxing the frontend, we want to normalize state e.g. use ids and expose first-level endpoints
Note that districtNumber is NOT the same as districtId