Skip to content

API Documentation for frontend

Siravich Termvadsayanon edited this page Nov 20, 2023 · 11 revisions

Routes

For production please change MONGO_URL in .env to the link provided in important things page column prod.
For testing purpose please change MONGO_URL in .env to the link provided in important things page column dev.

Schedule Route

POST /api/schedule/add

Add sport schedule into db

body =
        {
        "datetime": "datetime.datetime",
        "sport": [{
            "sport_id": int,
            "sport_name": str,
            "is_ceremonies": bool,
            "sport_type": [
                {
                    "type_id": int,
                    "type_name": str,
                    "status": ENUM('CEREMONIES', 'COMPETITIVE', 'TROPHY', 'RECORDED') -> str
                },
                {
                    "type_id": int,
                    "type_name": str,
                    "status": ENUM('CEREMONIES', 'COMPETITIVE', 'TROPHY', 'RECORDED') -> str
                }
            ]}]
    }

GET /api/schedule/all

return all schedule with temporary field of sport_status

{
    "schedule_list": [
        {
            "datetime": "2024-07-24T00:00:00",
            "sport": [
                {
                    "sport_id": 0,
                    "sport_name": "Ceremonies",
                    "sport_type": [],
                    "sport_status": null
                },
                {
                    "sport_id": 1,
                    "sport_name": "Archery",
                    "sport_type": [],
                    "sport_status": null
                },
                {
                    "sport_id": 19,
                    "sport_name": "Football",
                    "sport_type": [
                        {
                            "type_id": 0,
                            "type_name": "0",
                            "status": "COMPETITIVE"
                        }
                    ],
                    "sport_status": "COMPETITIVE"
                }, ...
            ]
        },
        ....
        ]
}

GET /api/schedule/sport

return all sport

{
    "sport_list": [
        {
            "sport_id": 0,
            "sport_name": "Ceremonies",
            "sport_icon": [svg path]
        },
        {
            "sport_id": 1,
            "sport_name": "Football"
            "sport_icon": [svg path]
        },
        {
            "sport_id": 2,
            "sport_name": "Archery"
            "sport_icon": [svg path]
        },
        {
            "sport_id": 3,
            "sport_name": "Artistic Gymnastics"
            "sport_icon": [svg path]
        },
        ...
        ]
}

Record Route

GET /api/record/detail/{date}/{sport_id}

Retrieve sport detail by sport ID and match it with schedule data.

{
    "sport_id": 1,
    "sport_name": "Archery",
    "sport_types": [
        {
            "type_id": 1,
            "type_name": "Individual Men's",
            "status": "RECORDED",
            "participating_country_count": 40,
            "competition_date": "2024-08-04T00:00:00",
            "participants": [
                {
                    "country": "United States",
                    "medal": {
                        "gold": 0,
                        "silver": 0,
                        "bronze": 1
                    }
                },
                {
                    "country": "China",
                    "medal": {
                        "gold": 1,
                        "silver": 0,
                        "bronze": 0
                    }
                },
                {
                    "country": "Bangladesh",
                    "medal": {
                        "gold": 0,
                        "silver": 0,
                        "bronze": 1
                    }
                },
                {
                    "country": "Belgium",
                    "medal": {
                        "gold": 0,
                        "silver": 1,
                        "bronze": 0
                    }
                },
                {
                    "country": "Taiwan, Province of China",
                    "medal": {
                        "gold": 0,
                        "silver": 1,
                        "bronze": 0
                    }
                }
                }
            ]
        }
    ]
}

If status is "TROPHY"

{
    "sport_id": 1,
    "sport_name": "Archery",
    "sport_types": [
        {
            "type_id": 2,
            "type_name": "Individual Women's",
            "status": "TROPHY",
            "competition_date": "2024-08-03T00:00:00",
            "participating_country_count": 38,
            "participating_countries": [
                "Tunisian Republic",
                "People's Republic of Bangladesh",
                "Republic of Indonesia",
                "Republic of India",
                "Italian Republic",
                "Ukraine",
                "Arab Republic of Egypt",
                "United Mexican States",
                "Federal Republic of Germany",
                "Hellenic Republic",
                "Kingdom of Denmark",
                "United States of America",
                "French Republic",
                "Republic of Moldova",
                "Republic of Colombia",
                "Malaysia",
                "Kingdom of the Netherlands",
                "Republic of Estonia",
                "Canada",
                "Republic of Ecuador",
                "United Kingdom of Great Britain and Northern Ireland",
                "Romania",
                "Kingdom of Spain",
                "Japan",
                "Czech Republic",
                "Mongolia",
                "Kingdom of Bhutan",
                "Socialist Republic of Vietnam",
                "People's Republic of China",
                "Slovak Republic",
                "Russian Federation",
                "Republic of Belarus",
                "Kingdom of Sweden",
                "Republic of Turkey",
                "Republic of Chad",
                "Republic of Poland",
                "Commonwealth of Australia",
                "Federative Republic of Brazil"
            ]
        }
    ]
}

POST /api/record/verify

Record medal verification if it meets any restrictions and warn accordingly return a message dict: warning, message in this order or HTTP400 if invalid

message = {"Message": "Successful",
           "Warning": "Appear if message have warning",
           "Monosport": "Appear if have message only 1 participant"}
body = {
     "sport_name": str,
     "participants": [
         {
            "country": str,
            "medal":{
              "gold": int,
              "silver": int,
              "bronze": int
            }
         }
     ]
}

POST /api/record/medal/update

Update medal allocation in sota database

body = {
    "sport_id": 1,
    "sport_type_id": 1,
    "participants": [
        {
            "country": "AU",
            "medal": {
                        "gold": 0,
                        "silver": 1,
                        "bronze": 1
                   }
        },
                   {
                     "country": "BD",
                     "medal": {
                              "gold": 4,
                              "silver": 1,
                              "bronze": 0
                              }
                   },
                   {
                     "country": "BE",
                     "medal": {
                              "gold": 1,
                              "silver": 0,
                              "bronze": 0
                              }
                   }
                        ]
}