Spaces:
Running
Running
| from fastapi import APIRouter, Form, File, UploadFile | |
| from utils.common import CommonResponse | |
| router = APIRouter( | |
| prefix="/test", | |
| tags=["test"] | |
| ) | |
| def test_home(): | |
| try: | |
| return CommonResponse(success=True) | |
| except Exception as e: | |
| return CommonResponse(success=False, msg=str(e)) | |
| def test_info(name: str = "", age: int = 0): | |
| try: | |
| # 비즈니스 로직 처리 | |
| data = { | |
| "name": name, | |
| "age": age | |
| } | |
| return CommonResponse(success=True, data=data) | |
| except Exception as e: | |
| return CommonResponse(success=False, msg=str(e)) | |
| def mytest(username: str = "", password: str=""): | |
| try: | |
| # 비즈니스 로직 처리 | |
| data = { | |
| "username": username, | |
| "password": password | |
| } | |
| return CommonResponse(success=True, data=data) | |
| except Exception as e: | |
| return CommonResponse(success=False, msg=str(e)) | |
| def post_mytest(username: str = Form(""), password: str = Form("")): | |
| try: | |
| # business logic | |
| data = { | |
| "username": username, | |
| "password": password | |
| } | |
| return CommonResponse(success=True, data=data) | |
| except Exception as e: | |
| return CommonResponse(success=False, msg=str(e)) | |
| async def upload_file(file: UploadFile = File(...)): | |
| try: | |
| # business logic | |
| contents = await file.read() | |
| data = { | |
| "filename": file.filename, | |
| "content_type": file.content_type, | |
| "size": len(contents) | |
| } | |
| return CommonResponse(success=True, data=data) | |
| except Exception as e: | |
| return CommonResponse(success=False, msg=str(e)) | |