-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
41 lines (34 loc) · 1.1 KB
/
app.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
40
41
from typing import Union
from fastapi import FastAPI
from allrequests import getquotes, addquotes,deletequotes,updatequotes
app = FastAPI()
@app.get("/")
def quotes():
return getquotes()
@app.post("/add/")
async def addquote(quotes: str, author: str):
quotes= quotes.strip()
author= author.strip()
if len(quotes) == 0 or len(author) == 0:
return {"error": "Quotes and Author are required"}
return addquotes(quotes,author)
@app.delete("/delete/")
async def deletequote(id):
id=id.strip()
if id is None:
return {"error":"ID Cannot be Empty"}
return deletequotes(id)
@app.put("/update/")
async def updatequote(id:str,quotes:str,author:str):
id=id.strip()
quotes= quotes.strip()
author= author.strip()
if len(quotes) == 0 and len(author) == 0:
return {"error":"Quotes Or Author are required"}
if id is None:
return {"error":"Please Pass the ID Too"}
if len(quotes) == 0:
return updatequotes("None",author,id)
elif len(author) == 0:
return updatequotes(quotes,"None",id)
return updatequotes(quotes,author,id)