Skip to content

Unlocking the truest potential of nutrition. This is Foobar® Eats.

Notifications You must be signed in to change notification settings

fsek/foobar-eats-backend

 
 

Repository files navigation

Foobar Eats Backend

Specifikation

Hej nya spindel! Nu är det dags att bygga en liten server till FooBar Eats(TM). I korthet ska klienterna (användarnas hemsidor) kunna

  • se vad som finns att köpa
  • lägga en order
  • se orderstatus för någon order med ett givet id.

För den våghalsiga finns även en svårläslig OpenAPI-specifikation som egentligen säger precis samma sak som punktlistan ovan fast på ett superpetigt sätt. Men ni kommer behöva läsa den i sinom tid för att servern ska passa med frontenden som era kollegor bygger. Det hela kan liknas vid Askungen, där era kollegors frontend är foten och er server är glasskon. OpenAPI-specifikationen i samma liknelse skulle vara lästen.1

För att göra livet lite roligare och mer spännande för användarna får ni gärna se till så att lagda ordrar så småningom blir klara. Hur snabbt de ska bli klara väljer ni själva. Resten av specifikationen hann jag tyvärr inte skriva så fråga mig (Åke) istället!

Overview

This repo uses VSCode's Dev Containers extension to standardize the development environment and avoid headache-inducing installation. All development will happen inside a Docker container which installs the same dependencies and versions on every developer's machine.

Installation

You can either run the project locally or via Github codespaces. Since Github has way better servers than most of us and running our projects can be quite demanding for most computers, we recommend using codespaces. In either case, the actual experience when coding will be similar.

Using Codespaces

  1. Go to the main Github page for this repo, scroll up and click the green "Code" button
  2. Go to the codespaces tab and create a new codespace
  3. Everything should set itself up automatically, wait until it says "your application running is available at...".
  4. If you want to get back to the codespace after closing it, go to the repository and once again click the green CODE button. It should show up in a list. You can also choose to open the codespace using vscode if you don't like the URL bar at the top, by clicking the three dots next to the codespace.
  5. After configuration has finished in the open terminal, it should say Done. Press any key to close the terminal. Open main.py and make sure VSCode has selected our Python interpreter from .venv folder: In the bottom right corner of VSCode it should say approximately Python 3.11.2 ('.venv': venv). Otherwise, open Command Palette -> Python: Select Interpreter and choose ./.venv/bin/python.
  6. Open a new Bash terminal (Ctrl + Shift + Ö) and run uvicorn main:app --reload. Terminal should have (.env), otherwise run source .venv/bin/activate.
  7. Go to http://127.0.0.1:8000/docs for the Swagger page automatically generated by FastAPI 🎉

Running Locally

  1. Using Windows? First set up WSL 2.

    • Press Windows -> "Turn Windows features on or off". Enable "Windows Subsystem for Linux", might need to enable "Virtual Machine Platform" also.
    • Open Powershell as admin.
    • wsl --install
    • wsl --set-default-version 2
    • wsl --install -d Ubuntu-22.04
    • wsl --set-default Ubuntu-22.04
    • For more info: Microsoft documentation
  2. Install Docker Desktop.

    • Windows users: Make sure you select Use WSL 2 instead of Hyper-V if the option is presented.
  3. Open a new VSCode window and install Dev Containers extension from the Extensions menu.

  4. Open the Command Palette (Ctrl + Shift + P / Cmd + Shift + P) and select Dev Containers: Clone Repository in Container Volume.... Select GitHub, then enter fsek/foobar-eats-backend.git.

  5. After configuration has finished in the open terminal, it should say Done. Press any key to close the terminal. Open main.py and make sure VSCode has selected our Python interpreter from .venv folder: In the bottom right corner of VSCode it should say approximately Python 3.11.2 ('.venv': venv). Otherwise, open Command Palette -> Python: Select Interpreter and choose ./.venv/bin/python.

  6. Open a new Bash terminal (Ctrl + Shift + Ö) and run uvicorn main:app --reload. Terminal should have (.env), otherwise run source .venv/bin/activate.

  7. Go to http://127.0.0.1:8000/docs for the Swagger page automatically generated by FastAPI 🎉

  8. From now on, whenever you want to open this project: Open a new VSCode window and in Recent, find foobar-eats-backend in a unique volume [Dev Container]. Don't re-run Clone Repository... from step 3.

Play around

  1. Try calling some routes.

  2. Evidently, the database is already filled with some starting data. This was done in the seed.py file when the server started. Go check it out!

  3. You can stop the FastAPI server anytime by entering Ctrl+C in the Bash terminal.

  4. Run pip list to see all installed pip packages.

Footnotes

  1. Förlåt för den liknelsen. Om ni kommer på någon bättre får ni gärna ändra detta dokument och öppna en pull request. Fråga en superman om ni är osäkra på hur ni ska göra.

About

Unlocking the truest potential of nutrition. This is Foobar® Eats.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 77.4%
  • Dockerfile 22.6%