Code Monkey home page Code Monkey logo

py-fastapi-city-temperature-management-api's Introduction

Task Description

You are required to create a FastAPI application that manages city data and their corresponding temperature data. The application will have two main components (apps):

  1. A CRUD (Create, Read, Update, Delete) API for managing city data.
  2. An API that fetches current temperature data for all cities in the database and stores this data in the database. This API should also provide a list endpoint to retrieve the history of all temperature data.

Part 1: City CRUD API

  1. Create a new FastAPI application.
  2. Define a Pydantic model City with the following fields:
    • id: a unique identifier for the city.
    • name: the name of the city.
    • additional_info: any additional information about the city.
  3. Implement a SQLite database using SQLAlchemy and create a corresponding City table.
  4. Implement the following endpoints:
    • POST /cities: Create a new city.
    • GET /cities: Get a list of all cities.
    • Optional: GET /cities/{city_id}: Get the details of a specific city.
    • Optional: PUT /cities/{city_id}: Update the details of a specific city.
    • DELETE /cities/{city_id}: Delete a specific city.

Part 2: Temperature API

  1. Define a Pydantic model Temperature with the following fields:
    • id: a unique identifier for the temperature record.
    • city_id: a reference to the city.
    • date_time: the date and time when the temperature was recorded.
    • temperature: the recorded temperature.
  2. Create a corresponding Temperature table in the database.
  3. Implement an endpoint POST /temperatures/update that fetches the current temperature for all cities in the database from an online resource of your choice. Store this data in the Temperature table. You should use an async function to fetch the temperature data.
  4. Implement the following endpoints:
    • GET /temperatures: Get a list of all temperature records.
    • GET /temperatures/?city_id={city_id}: Get the temperature records for a specific city.

Additional Requirements

  • Use dependency injection where appropriate.
  • Organize your project according to the FastAPI project structure guidelines.

Evaluation Criteria

Your task will be evaluated based on the following criteria:

  • Functionality: Your application should meet all the requirements outlined above.
  • Code Quality: Your code should be clean, readable, and well-organized.
  • Error Handling: Your application should handle potential errors gracefully.
  • Documentation: Your code should be well-documented (README.md).

Deliverables

Please submit the following:

  • The complete source code of your application.
  • A README file that includes:
    • Instructions on how to run your application.
    • A brief explanation of your design choices.
    • Any assumptions or simplifications you made.

Good luck!

py-fastapi-city-temperature-management-api's People

Contributors

danylott avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.