82 lines
1.9 KiB
Python
82 lines
1.9 KiB
Python
from fastapi import FastAPI, HTTPException
|
|
from pydantic import BaseModel
|
|
from typing import Optional
|
|
import uvicorn
|
|
import pymysql
|
|
|
|
class mysql_params:
|
|
host = "127.0.0.1"
|
|
user = "yt2mp3_nuxt"
|
|
db = "yt2mp3_nuxt"
|
|
pwd = "ultratopsecret,bro"
|
|
|
|
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="127.0.0.1", port=8003) |