hackoregon / emergency-response-backend

backend repo for the emergency response project team 2017
4 stars 3 forks source link

Responder table endpoints #13

Open BrianHGrant opened 7 years ago

BrianHGrant commented 7 years ago

Responder does not have a single primary key field but has composite key of incident_id and responder_id, what is best path for representing this as model and as a retrieve endpoint?

Current model, which works for list method:

class Responder(models.Model):
    incident_id = models.IntegerField(primary_key=True)
    responder_id = models.IntegerField()
    responderunit = models.ForeignKey('ResponderUnit', models.DO_NOTHING, blank=True, null=True)
    codetosc = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'responder'
        unique_together = [
            ('incident_id', 'responder_id'),
        ]

This fails though when using a generics.RetrieveAPIView, as an attempt to retrieve a responder instance based on primary key will return many when the get() method is expecting a single instance.

A possible solution is to keep current model and build custom endpoint that will expect multiple responses for the single endpoint.

futurechris commented 7 years ago

I think we discussed this in the meeting last night, but just to document here: Since our data is static, we thought it might be easiest to solve this hackishly, by creating an intermediate table that converts the composite key into a single key.

The responder info will need to be accessible via API one way or another, eventually. We may not need it (via API) for the demo and 'bagel shop incident' projects, though.