File size: 1,804 Bytes
6e755f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c4d1e86
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from fastapi import APIRouter, Form, File, UploadFile
from utils.common import CommonResponse

router = APIRouter(
    prefix="/test",
    tags=["test"]
)

@router.get("/")
def test_home():
    try:
        return CommonResponse(success=True)
    except Exception as e:
        return CommonResponse(success=False, msg=str(e))

@router.get("/info")
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))

@router.get("/mytest")
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))

@router.post("/mytest")
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))

@router.post("/upload")
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))