JumboCode / TUTV

JumboCode project for TUTV, currently led by Frank Ma. Led by Deepanshu Utkarsh 2019 - 2020.
4 stars 0 forks source link

Create new API GET endpoint for fetching equipment items specific to a time range #118

Open Frama-99 opened 3 years ago

Frama-99 commented 3 years ago

Currently, the endpoint /api/v1/equipment-types/ return a list of all equipment types as well as their associated items (see below). This is useful for an admin who wishes to see a list of all items, but doesn't provide functionality for a member to view what items are available during a certain timeframe.

Current behavior with GET /api/v1/equipment-types/:

[
    {
        "url": "http://localhost:8000/api/v1/equipment-types/1/",
        "items": [
            {
                "id": 125,
                "url": "http://localhost:8000/api/v1/equipment-items/125/"
            },
            {
                "id": 126,
                "url": "http://localhost:8000/api/v1/equipment-items/126/"
            },
            {
                "id": 127,
                "url": "http://localhost:8000/api/v1/equipment-items/127/"
            }
        ],
        "name": "Light Stand (Small Black)",
        "image": null,
        "description": "",
        "product_url": "",
        "category": "http://localhost:8000/api/v1/equipment-categories/1/"
    },
    {
    .......
    }, 
    {
    .......
    },     
]

Create a new API GET endpoint that, given the timeframe as query strings, return the same list of all equipment types but with the status of each item.

Desired behavior with GET /api/v1/equipment-types/?out=\<time>&in=\<time>/, where \<time> is a string of the format %Y-%m-%dT%H:%M:%S%z:

[
    {
        "url": "http://localhost:8000/api/v1/equipment-types/1/",
        "items": [
            {
                "id": 125,
                "url": "http://localhost:8000/api/v1/equipment-items/125/",
                "available": false
            },
            {
                "id": 126,
                "url": "http://localhost:8000/api/v1/equipment-items/126/",
                "available": true
            },
            {
                "id": 127,
                "url": "http://localhost:8000/api/v1/equipment-items/127/",
                "available": true
            }
        ],
        "name": "Light Stand (Small Black)",
        "image": null,
        "description": "",
        "product_url": "",
        "category": "http://localhost:8000/api/v1/equipment-categories/1/"
    },
    {
    .......
    }, 
    {
    .......
    },     
]

Use the API endpoint /api/v1/availability/ as a reference, which also takes in query strings ?out=\<time>&in=\<time>, except it also takes an ID and returns the availability of only one equipment item.

In order to add the "available" field, it probably isn't a good idea to add a new field to the EquipmentItem model, since this is a field that is dependent on dynamic information.

abarg12 commented 3 years ago

Would checking the permission just amount to making sure the user is logged in?