Skip to content

Commit a944b49

Browse files
committed
Base files, TODO fix mongo connection
1 parent 726a593 commit a944b49

File tree

5 files changed

+29
-56
lines changed

5 files changed

+29
-56
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"python.pythonPath": "/usr/bin/python3.9"
2+
"python.pythonPath": "/home/blevinscm/src/fastapi-scaffold-base/env/bin/python3.8"
33
}

app/data/models.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,8 @@
1-
from typing import List
2-
3-
from fastapi import FastAPI, HTTPException
4-
1+
import typing
52
from odmantic import AIOEngine, Model, ObjectId
63

74

85
class Hug(Model):
96
kind: str
107
hug_size: float
11-
hugger: str
12-
13-
14-
engine = AIOEngine()
15-
16-
17-
@app.put("/hugs/", response_model=Hug)
18-
async def new_hug(hug: Hug):
19-
await engine.save(hug)
20-
return hug
21-
22-
23-
@app.get("/hugs/", response_model=List[Hug])
24-
async def get_hugs():
25-
trees = await engine.find(Hug)
26-
return trees
27-
28-
29-
@app.get("/hugs/count", response_model=int)
30-
async def count_hugs():
31-
count = await engine.count(Hug)
32-
return count
33-
34-
35-
@app.get("/hugs/{id}", response_model=Hug)
36-
async def get_tree_by_id(id: ObjectId):
37-
hug = await engine.find_one(Hug, Hug.id == id)
38-
if hug is None:
39-
raise HTTPException(404)
40-
return hug
8+
hugger: str

app/routers/hugs.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
from fastapi import APIRouter
2-
from app.data import models
1+
from fastapi import APIRouter, HTTPException
2+
from app.data import models
3+
from typing import List
4+
from odmantic import AIOEngine, Model, ObjectId
35

46
router = APIRouter()
57

8+
Hug = models.Hug
9+
engine = AIOEngine()
610

7-
@router.get("/hugs/", tags=["Friendly_Hugs"])
8-
async def read_hugs():
9-
'''
10-
Returns all huggers available
11-
'''
12-
return [{"hugs": "Pooh"}, {"username": "Bear"}]
11+
@router.put("/hugs/", response_model=Hug, tags=["hugs"])
12+
async def new_hug(hug: Hug):
13+
await engine.save(hug)
14+
return hug
1315

1416

15-
@router.get("/hugs/me", tags=["Friendly_Hugs"])
16-
async def read_huggee_me():
17-
'''
18-
Set to return user context. In this case the hugee.
19-
'''
20-
return {"username": "Huggable Developer"}
17+
@router.get("/hugs/", response_model=List[Hug], tags=["hugs"])
18+
async def get_hugs():
19+
trees = await engine.find(Hug)
20+
return trees
2121

2222

23-
@router.get("/hugs/{type}", tags=["Friendly_Hugs"])
24-
async def read_hug_type(hug_type: str):
25-
'''
26-
Allows user to enter the type of hug they want.
27-
Replace with any single non-enum type.
28-
'''
29-
return {"username": hug_type}
23+
@router.get("/hugs/count", response_model=int, tags=["hugs"])
24+
async def count_hugs():
25+
count = await engine.count(Hug)
26+
return count
27+
28+
29+
@router.get("/hugs/{id}", response_model=Hug, tags=["hugs"])
30+
async def get_tree_by_id(id: ObjectId):
31+
hug = await engine.find_one(Hug, Hug.id == id)
32+
if hug is None:
33+
raise HTTPException(404)
34+
return hug

dockerfile

Whitespace-only changes.

nix-start-FastAPI

100644100755
File mode changed.

0 commit comments

Comments
 (0)