-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
39 lines (30 loc) · 921 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from pydantic import BaseModel
class Memo(BaseModel):
id:str
content:str
memos = []
app = FastAPI()
@app.post("/memos")
def create_memo(memo:Memo):
memos.append(memo)
return '메모 추가에 성공했습니다.'
@app.get("/memos")
def read_memo():
return memos
@app.put("/memos/{memo_id}")
def put_memo(req_memo:Memo):
for memo in memos:
if memo.id==req_memo.id:
memo.content=req_memo.content
return '성공했습니다.'
return '그런 메모는 없습니다.'
@app.delete("/memos/{memo_id}")
def delete_memo(memo_id):
for index,memo in enumerate(memos):
if memo.id==memo_id:
memos.pop(index)
return '성공했습니다.'
return '그런 메모는 없습니다.'
app.mount("/",StaticFiles(directory='static', html=True), name='static')