Last active
February 7, 2025 10:54
Revisions
-
leriaetnasta revised this gist
Feb 2, 2025 . 1 changed file with 1 addition and 5 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() @@ -9,10 +9,6 @@ class Starship(BaseModel): price: float discount: float | None @app.post("/addStarship") async def add_starship(starship: Starship): return { -
leriaetnasta revised this gist
Feb 2, 2025 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ from fastapi import FastAPI from pydantic import BaseModel, computed_field app = FastAPI() -
leriaetnasta revised this gist
Feb 2, 2025 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ app = FastAPI() class Starship(BaseModel): id: str name: str price: float discount: float | None -
leriaetnasta revised this gist
Feb 2, 2025 . 1 changed file with 8 additions and 10 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,24 +1,22 @@ from fastapi import FastAPI from pydantic import BaseModel, computed_field, Field import uuid app = FastAPI() class Starship(BaseModel): id: str = Field(default_factory=lambda: f"schorle-{uuid.uuid4()}") name: str price: float discount: float | None @computed_field def total(self) -> float: return self.price - (self.price * self.discount / 100) @app.post("/addStarship") async def add_starship(starship: Starship): return { "starship_id": starship.id, "starship": starship } -
leriaetnasta revised this gist
Feb 2, 2025 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -18,7 +18,6 @@ class Jedi(BaseModel): @app.post("/addStarship/{starship_id}") async def add_starship(starship: Starship, starship_id: int): return { "starship_id": starship_id, "starship": starship } -
leriaetnasta revised this gist
Feb 2, 2025 . 2 changed files with 25 additions and 17 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ from fastapi import FastAPI, Body from pydantic import BaseModel, computed_field app = FastAPI() class Starship(BaseModel): name: str price: float discount: float @computed_field def total(self) -> float: return self.price - (self.price * self.discount / 100) class Jedi(BaseModel): name: str lightsaber_color: str @app.post("/addStarship/{starship_id}") async def add_starship(starship: Starship, starship_id: int): return { "message": "Starship added!", "starship_id": starship_id, "starship": starship } This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,17 +0,0 @@ -
leriaetnasta revised this gist
Feb 2, 2025 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,10 +3,10 @@ app = FastAPI() class Starship(BaseModel): name: str class Jedi(BaseModel): name: str lightsaber_color: str -
leriaetnasta revised this gist
Feb 2, 2025 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,10 +3,10 @@ app = FastAPI() class Starship(): name: str class Jedi(): name: str lightsaber_color: str -
leriaetnasta renamed this gist
Feb 2, 2025 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
leriaetnasta created this gist
Feb 2, 2025 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ from fastapi import FastAPI, Body from pydantic import BaseModel app = FastAPI() class Starship(BaseModel): name: str class Jedi(BaseModel): name: str lightsaber_color: str @app.post("/jedi/{jedi_id}/purchase/{starship_id}") def purchase(jedi_id: int, starship_id: int, jedi: Jedi = Body(...), starship: Starship = Body(...)): return { "message": f"Jedi {jedi.name} [ID: {jedi_id}] owns the {starship.name} [ID: {starship_id}]" }