Skip to content

Commit

Permalink
chore:update swagger docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jingooo5 committed Nov 2, 2024
1 parent df8dd02 commit a121a4e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 9 deletions.
28 changes: 23 additions & 5 deletions Router/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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():
Expand Down
13 changes: 10 additions & 3 deletions Router/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion Router/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("-"))
Expand Down
21 changes: 21 additions & 0 deletions Utils/swagger.py
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit a121a4e

Please sign in to comment.