RIFT24 / cspquizbackend

Backend for the CSP Quiz
0 stars 26 forks source link

Data Structures Writeup #10

Open herry2333 opened 2 months ago

herry2333 commented 2 months ago

Collections

Blog Python Model code and SQLite Database image

image

Lists and Dictionaries

Blog Python API code and use of List and Dictionaries. image image image

APIs and JSON

image image

The provided code snippet is part of a Flask RESTful API handling HTTP requests for managing user data related to colleges. It supports POST, GET, and PUT methods.

The post method first extracts JSON data from the request body, retrieving the user's ID from the data. It checks if the username is missing, returning an error message and status code 400 if so. Then, it queries the database for the user's record using the obtained ID, returning a 404 error if the user is not found. Next, it decodes the user's college list from the database, queries for colleges matching the list names, converts the query results to JSON format, and returns the data as a response. These steps ensure data validity and provide appropriate error handling during the POST request process. image image image image image

Frontend

Blog JavaScript API fetch code and formatting code to display JSON. image image image