ThreeSixtyGiving / datastore

A Data Store application for 360Giving
GNU Affero General Public License v3.0
0 stars 1 forks source link

API Endpoints for Grants Data #167

Closed R2ZER0 closed 10 months ago

R2ZER0 commented 10 months ago

This PR adds endpoints to access grant data relating to an organisation in the datastore. The new endpoints:

Following RESTy ideas, we've got two resources/data types: Organisation and Grant. I've given every object a self URL which, unsurprisingly, is the URL where detail about the object can be found. Grants always have grant_id and Organisations always have org_id. For references to other objects, I've made them be a subobject that containts self too, vaguely following the ideas from Terrifically Simple JSON. I've never used Terrifically Simple JSON before, but looks like an easy entrypoint to "linked" data vs going full JSON-LD etc.

Questions:

There's no tests, until we know we're not going to immediately throw this design away.

Examples:

Organisation - Detail

GET /api/experimental/org/GB-CHC-1090123

HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "self": "http://localhost:8000/api/experimental/org/GB-CHC-1090123",
    "org_id": "GB-CHC-1090123",
    "grants_made": "http://localhost:8000/api/experimental/org/GB-CHC-1090123/grants_made",
    "grants_received": "http://localhost:8000/api/experimental/org/GB-CHC-1090123/grants_received",
    "funder": null,
    "recipient": {
        "org_id": "GB-CHC-1090123",
        "name": "Coventry Refugee and Migrant Centre",
        "aggregate": {
            "grants": 3,
            "currencies": {
                "GBP": {
                    "avg": 18333.333333333332,
                    "max": 20000,
                    "min": 15000,
                    "total": 55000,
                    "grants": 3
                }
            },
            "maxAwardDate": "2020-04-23",
            "minAwardDate": "2017-07-04"
        },
        "additional_data": {
            "alternative_names": []
        },
        "source": "GRANT"
    },
    "publisher": null
}

Organisation - Grants Received

GET /api/experimental/org/GB-CHC-1090123/grants_received

HTTP 200 OK
Allow: GET, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "count": 3,
    "next": null,
    "previous": null,
    "results": [
        {
            "self": "http://localhost:8000/api/experimental/grant/360G-ABCT-0065I000002UMWBQA4",
            "publisher": {
                "org_id": "GB-CHC-1000147",
                "self": "http://localhost:8000/api/experimental/org/GB-CHC-1000147"
            },
            "recipients": [
                {
                    "org_id": "GB-CHC-1090123",
                    "self": "http://localhost:8000/api/experimental/org/GB-CHC-1090123"
                }
            ],
            "funders": [
                {
                    "org_id": "GB-CHC-1000147",
                    "self": "http://localhost:8000/api/experimental/org/GB-CHC-1000147"
                }
            ],
            "grant_id": "360G-ABCT-0065I000002UMWBQA4",
            "data": {
                "id": "360G-ABCT-0065I000002UMWBQA4",
                "title": "A grant to Coventry Refugee and Migrant Centre",
                "Website": {
                    "Decision Notes": "An unrestricted grant of £20,000",
                    "Project Detail": "Coventry Refugee and Migrant Centreprovides advice, guidance and support to asylum seekers, refugees and migrants living in Coventry through housing, employment and immigration support"
                },
                "currency": "GBP",
                "awardDate": "2020-04-23T00:00:00+00:00",
                "dataSource": "http://abcharitabletrust.org.uk/",
                "description": "An unrestricted grant of £20,000. Coventry Refugee and Migrant Centreprovides advice, guidance and support to asylum seekers, refugees and migrants living in Coventry through housing, employment and immigration support",
                "fromOpenCall": "Yes",
                "amountAwarded": 20000,
                "grantProgramme": [
                    {
                        "code": "Open Programme",
                        "title": "Migrants and Refugees"
                    }
                ],
                "beneficiaryLocation": [
                    {
                        "name": "West Midlands - Warwickshire"
                    }
                ],
                "fundingOrganization": [
                    {
                        "id": "GB-CHC-1000147",
                        "name": "A B Charitable Trust"
                    }
                ],
                "recipientOrganization": [
                    {
                        "id": "GB-CHC-1090123",
                        "url": "http://www.covrefugee.org/",
                        "name": "Coventry Refugee and Migrant Centre",
                        "postalCode": "CV1 5FX",
                        "charityNumber": "1090123"
                    }
                ],
                "Award Date - website format": "2020-04-23T00:00:00+00:00",
                "Amount Awarded - website format": 20000
            },
            "additional_data": {
                "codeListLookup": {
                    "regrantType": "",
                    "toIndividualsDetails": {
                        "grantPurpose": [],
                        "primaryGrantReason": "",
                        "secondaryGrantReason": ""
                    }
                },
                "locationLookup": [],
                "TSGRecipientType": "Organisation",
                "recipientLocation": "     ",
                "recipientOrgInfos": []
            }
        },
        ...
    ]
}