diff --git a/Router/item.py b/Router/item.py index bb144b8..ec7f439 100644 --- a/Router/item.py +++ b/Router/item.py @@ -15,11 +15,18 @@ from Service.purchase_service import PurchaseService from Service.useritem_service import UserItemService import numpy as np + +from Utils.swagger import user_item_list_dict_example + router = APIRouter(tags=["items"], prefix="/items") """ 물품을 리스트로 추가한다. """ -@router.post("/addall") + +@router.post("/addall", summary="여러 품목 구매", description="영수증, 유저 기입 물품 목록 추가", responses={ + 200: {"description": "성공", "content": {"application/json": {"example": {"message": "Item added successfully"}}}}, + 500: {"description": "실패"} +}) def add_items(request: Request, itemadd: ItemAdd): UserItemService.add_userItems(itemadd) purchase_history_list = PurchaseService.purchase_history_list_db(itemadd) @@ -30,7 +37,10 @@ def add_items(request: Request, itemadd: ItemAdd): """ 유저가 보유한 모든 아이템을 가져온다. """ -@router.get("/{user_id}/item", response_model=List[ItemRead]) +@router.get("/{user_id}", summary="유저 아이템", description="유저 보유 물품 조회", responses={ + 200: {"description": "성공", "content": {"application/json": {"example": {"items": user_item_list_dict_example}}}}, + 500: {"description": "실패"} +}, response_model=List[ItemRead]) def get_userItem_all(request : Request, user_id: str): user_item_list = UserItemService.get_all_userItem(user_id) user_item_list_dict = UserItemService.to_userItem_dict(user_item_list) @@ -40,7 +50,11 @@ def get_userItem_all(request : Request, user_id: str): """ 유저가 아이템 소비 """ -@router.post("/consume") +@router.post("/consume", summary="물품 소비", description="물품 소비", responses={ + 200: {"description": "성공", "content": {"application/json": {"example": {"message": "Item consumed successfully"}}}}, + 400: {"description": "실패", "content": {"application/json": {"example": {"message": "Item consume failed"}}}}, + 500: {"description": "실패"} +}) def consume_item(request : Request, user_item_consume: UserItemConsume): result = UserItemService.consume_userItem(user_item_consume) if result is False: @@ -54,7 +68,11 @@ def consume_item(request : Request, user_item_consume: UserItemConsume): 유저가 아이템 추가 TODO : request body에 아이탬 개수 추가 """ -@router.post("/addone") +@router.post("/addone", summary="물품 하나 추가", description="물품 하나 추가", responses={ + 200: {"description": "성공", "content": {"application/json": {"example": {"message": "Item added successfully"}}}}, + 400: {"description": "실패", "content": {"application/json": {"example": {"message": "Too many items added"}}}}, + 500: {"description": "실패", "content": {"application/json": {"example": {"message": "Item added failed"}}}} +}) def add_item(request : Request, userItemAdd: UserItemAdd): try: UserItemService.add_userItem(userItemAdd) @@ -65,7 +83,7 @@ def add_item(request : Request, userItemAdd: UserItemAdd): return JSONResponse(status_code=HTTP_400_BAD_REQUEST, content={"message": "Too many items added"}) -@router.get("/add/{item_name}/{base_consume_expectation}/{base_price}") +@router.post("/add/{item_name}/{base_consume_expectation}/{base_price}", summary="아이템 추가") def add_item(request : Request, item_name: str, base_consume_expectation: int, base_price: int): category_embedding = [] for category in ItemCategory.list(): diff --git a/Router/login.py b/Router/login.py index 98c68b6..85b8233 100644 --- a/Router/login.py +++ b/Router/login.py @@ -7,12 +7,15 @@ from fastapi import Query, Request from Database.models import User from Service.useritem_service import UserItemService - +from Utils.swagger import signin_response_example router = APIRouter(tags=["login"], prefix="/login") -@router.post("/signup") +@router.post("/signup", summary="회원가입", description="회원가입", responses={ + 200: {"description": "성공", "content": {"application/json": {"example": {"message": "User added successfully"}}}}, + 500: {"description": "실패"} +}) def signup(request: Request, userCreate: UserCreate): user = User( name=userCreate.name, @@ -27,7 +30,11 @@ def signup(request: Request, userCreate: UserCreate): return JSONResponse(status_code=HTTP_200_OK, content={"message": "User added successfully"}) -@router.post("/signin") +@router.post("/signin", summary="로그인", description="로그인 패스워드 확인안함", responses={ + 200: {"description": "성공", "content": {"application/json": {"example": signin_response_example}}}, + 204: {"description": "유저 없음", "content": {"application/json": {"example": {"message": "User not found"}}}}, + 500: {"description": "실패"} +}) def signin(request: Request, user: LoginUser): with get_db() as db: user = db.query(User).filter(User.name == user.name).first() diff --git a/Router/price.py b/Router/price.py index 4daa062..2e0c3db 100644 --- a/Router/price.py +++ b/Router/price.py @@ -13,7 +13,11 @@ router = APIRouter(tags=["price"], prefix="/price") -@router.get("/{user_id}") +@router.get("/{user_id}", summary="예상 가격 조회", description="월별 예상 가격 조회 날짜 %Y-%m 형식으로", responses={ + 200: {"description": "성공", "content": {"application/json": {"example": {"price": 10000}}}}, + 400: {"description": "잘못된 날짜 형식", "content": {"application/json": {"example": {"message": "Invalid date format"}}}}, + 500: {"description": "실패"} +}) def get_expected_price(request : Request, user_id: str, date : str = Query(...)): try: year, month = map(int, date.split("-")) diff --git a/Utils/swagger.py b/Utils/swagger.py new file mode 100644 index 0000000..414f96c --- /dev/null +++ b/Utils/swagger.py @@ -0,0 +1,21 @@ +user_item_list_dict_example = [ + { + "user_id": "bbe1596098b24305a3b838e240fb2c1c", + "item_name": "휴지", + "count": 10, + "category": "livingroom", + "consume_date": "2021-01-01" + }, + { + "user_id": "bbe1596098b24305a3b838e240fb2c1c", + "item_name": "샴푸", + "count": 2, + "category": "bathroom", + "consume_date": "2021-01-01" + } + ] + +signin_response_example = { + "message": "User signed in successfully", + "user_id": "bbe1596098b24305a3b838e240fb2c1c" +} \ No newline at end of file