From 2c9e5834d3fdd1d4e970bea52a69310e9cb65e72 Mon Sep 17 00:00:00 2001 From: suricata Date: Tue, 13 Jan 2026 19:08:21 +0000 Subject: [PATCH] python backend --- server/py/fastapi.py | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 server/py/fastapi.py diff --git a/server/py/fastapi.py b/server/py/fastapi.py new file mode 100644 index 0000000..1658177 --- /dev/null +++ b/server/py/fastapi.py @@ -0,0 +1,73 @@ +from fastapi import FastAPI, HTTPException +from pydantic import BaseModel +from typing import Optional +import uvicorn + +app = FastAPI() + +class ConversionData(BaseModel): + input_value: str + conversion_type: str + +class LoginData(BaseModel): + username: str + password: str + +class MeData(BaseModel): + username: str + email: str + profile_picture: Optional[str] = None + + +@app.post("/convert") +async def convert_endpoint(data: ConversionData): + """ + Converts an input value based on the specified conversion type. + """ + # Dummy conversion logic + if data.conversion_type == "uppercase": + converted_value = data.input_value.upper() + elif data.conversion_type == "lowercase": + converted_value = data.input_value.lower() + else: + raise HTTPException(status_code=400, detail="Invalid conversion type") + + return {"converted_value": converted_value} + + +@app.post("/login") +async def login_endpoint(data: LoginData): + """ + Verifies login credentials. + """ + # Dummy verification logic + if data.username == "user" and data.password == "password": + return {"message": "Login successful"} + else: + raise HTTPException(status_code=401, detail="Invalid credentials") + + +@app.get("/me") +async def me_get_endpoint(): + """ + Retrieves user profile data. + """ + # Dummy user data + user_data = { + "username": "example_user", + "email": "user@example.com", + "profile_picture": "https://example.com/profile.jpg" + } + return user_data + +@app.post("/me") +async def me_post_endpoint(data: MeData): + """ + Updates user profile data. + """ + # Dummy update logic + return {"message": "Profile updated successfully", **data.dict()} + + +if __name__ == "__main__": + uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file