Commit 4c17afcf authored by sireesha.k's avatar sireesha.k

committed

parent d04f951e
from scripts.service.requestmethods import app_route
from fastapi import FastAPI
app = FastAPI()
app.include_router(app_route)
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (cal_api)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/cal_api.iml" filepath="$PROJECT_DIR$/.idea/cal_api.iml" />
</modules>
</component>
</project>
\ No newline at end of file
from pydantic import BaseModel
class Schema1(BaseModel):
input1: int
input2: int
enter_ur_choice: str="1.addition 2.substraction 3.multiplication 4.division"
operation: int
from fastapi import APIRouter,HTTPException
from scripts.handler.schemas import Schema1
app_route = APIRouter(prefix="/calculator")
@app_route.post("/calculate")
def operation(request_data: Schema1):
if(request_data is not None):
if request_data.operation == 1:
return "Addition:" + str(request_data.input1 + request_data.input2)
elif request_data.operation == 2:
return "Substraction:" + str(request_data.input1 - request_data.input2)
elif request_data.operation == 3:
return "Multiplication:" + str(request_data.input1 * request_data.input2)
elif request_data.operation == 4:
try:
return "Division:" + str(request_data.input1 / request_data.input2)
except ZeroDivisionError:
return "Cannot divide by zero"
else:
return "Invalid Operation"
else:
raise HTTPException(status_code=404,detail="data not found")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment