-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f2fc7b3
commit cfc29de
Showing
20 changed files
with
232 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from app.v2.badges.dtos.badge_dto import BadgeCodeDTO | ||
from app.v2.badges.models.badge import Badge | ||
|
||
|
||
class BadgeService: | ||
@classmethod | ||
async def get_badges(cls, user_id: str) -> list[BadgeCodeDTO]: | ||
badges_raw = await Badge.get_badge_codes_by_user_id(user_id=user_id) | ||
return [BadgeCodeDTO.builder(badge) for badge in badges_raw] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class CheeseResponseDTO(BaseModel): | ||
cheeseBalance: int | ||
|
||
@classmethod | ||
def builder(cls, cheese_balance: int) -> "CheeseResponseDTO": | ||
return cls(cheeseBalance=cheese_balance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from fastapi import APIRouter, status | ||
|
||
from app.v2.cheese_managers.dtos.cheese_dto import CheeseResponseDTO | ||
from app.v2.cheese_managers.services.cheese_service import CheeseService | ||
from app.v2.users.services.user_service import UserService | ||
|
||
router = APIRouter(prefix="/cheese", tags=["Cheese"]) | ||
|
||
|
||
@router.get("", response_model=CheeseResponseDTO, status_code=status.HTTP_200_OK) | ||
async def get_cheese_handler(): | ||
user_id = "180a4e40-62f8-46be-b1eb-e7e3dd91cddf" | ||
user = await UserService.get_user_info(user_id=user_id) | ||
cheese_amount = await CheeseService.get_cheese_balance(user["cheese_manager_id"]) | ||
|
||
return CheeseResponseDTO.builder(cheese_balance=cheese_amount) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from app.v2.cheese_managers.models.cheese_manager import CheeseManager | ||
|
||
|
||
class CheeseService: | ||
|
||
@classmethod | ||
async def get_cheese_balance(cls, cheese_manager_id: str) -> int: | ||
return await CheeseManager.get_total_cheese_amount_by_manager( | ||
cheese_manager_id=cheese_manager_id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from app.v2.colors.dtos.color_dto import ColorCodeDTO | ||
from app.v2.colors.models.color import Color | ||
|
||
|
||
class ColorService: | ||
@classmethod | ||
async def get_colors(cls, user_id: str) -> list[ColorCodeDTO]: | ||
colors_raw = await Color.get_color_codes_by_user_id(user_id=user_id) | ||
return [ColorCodeDTO.builder(color) for color in colors_raw] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import asyncio | ||
|
||
from app.v2.levels.dtos.level_dto import LevelDTO | ||
from app.v2.levels.models.level import Level | ||
|
||
|
||
class LevelService: | ||
@classmethod | ||
async def get_level_info(cls, user_id: str) -> LevelDTO: | ||
# 레벨 정보를 조회하는 로직 | ||
level_info_raw = await Level.get_level_info_by_user_id(user_id=user_id) | ||
return LevelDTO.builder( | ||
level=level_info_raw.get("level_level"), | ||
current_exp=level_info_raw.get("level_exp"), | ||
) | ||
|
||
@classmethod | ||
async def level_up(cls, user_id: str) -> dict: | ||
""" | ||
유저가 레벨업 가능한지 확인 후, 레벨업 처리 | ||
""" | ||
level_dto, required_exp_raw = await asyncio.gather( | ||
cls.get_level_info(user_id=user_id), | ||
Level.get_required_exp_by_user_id(user_id=user_id), | ||
) | ||
|
||
level = level_dto.level | ||
current_exp = level_dto.current_exp | ||
required_exp = required_exp_raw["required_exp"] | ||
|
||
if current_exp >= required_exp: | ||
new_exp = current_exp - required_exp | ||
new_level = level + 1 | ||
|
||
await Level.update_level_and_exp( | ||
user_id=user_id, new_level=new_level, new_exp=new_exp | ||
) | ||
|
||
return { | ||
"status": "success", | ||
"message": "레벨업 성공", | ||
"new_level": new_level, | ||
"remaining_exp": new_exp, | ||
} | ||
|
||
return { | ||
"status": "failure", | ||
"message": "레벨업에 필요한 경험치가 부족합니다", | ||
"current_level": level, | ||
"current_exp": current_exp, | ||
"required_exp": required_exp, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from app.v2.teller_cards.dtos.teller_card_dto import TellerCardDTO | ||
from app.v2.teller_cards.models.teller_card import TellerCard | ||
|
||
|
||
class TellerCardService: | ||
@classmethod | ||
async def get_teller_card(cls, user_id: str) -> TellerCardDTO: | ||
teller_cards_raw = await TellerCard.get_teller_card_info_by_user_id( | ||
user_id=user_id | ||
) | ||
return TellerCardDTO.builder(teller_cards_raw) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
from pydantic import BaseModel | ||
|
||
from app.v2.teller_cards.dtos.teller_card_dto import TellerCardDTO | ||
|
||
|
||
class UserInfoDTO(BaseModel): | ||
nickname: str | ||
cheeseBalance: int | ||
tellerCard: TellerCardDTO | ||
|
||
@classmethod | ||
def builder( | ||
cls, user_raw: dict, cheeseBalance: int, tellerCard: TellerCardDTO | ||
) -> "UserInfoDTO": | ||
return cls( | ||
nickname=user_raw.get("nickname"), | ||
cheeseBalance=cheeseBalance, | ||
tellerCard=tellerCard, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from app.v2.cheese_managers.models.cheese_manager import CheeseManager | ||
from app.v2.users.models.user import User | ||
|
||
|
||
class UserService: | ||
@classmethod | ||
async def get_user_info(cls, user_id: str) -> dict: | ||
return await User.get_user_info_by_user_id(user_id=user_id) | ||
|
||
@classmethod | ||
async def get_cheese_balance(cls, cheese_manager_id: str) -> int: | ||
return await CheeseManager.get_total_cheese_amount_by_manager( | ||
cheese_manager_id=cheese_manager_id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters