Skip to content

Commit

Permalink
return dto 수정 (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
stopmin authored Jul 19, 2024
1 parent 68f798f commit a0f893c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
41 changes: 27 additions & 14 deletions app/model/user_type.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum

from sqlalchemy import BigInteger, Column, Integer, CHAR
from pydantic import BaseModel
from sqlalchemy import CHAR, BigInteger, Column, Integer

from app.database.repository import Base

Expand All @@ -19,16 +20,28 @@ class UserType(Base):


class UserTypes(Enum):
NONE= {'id':-1,
'name':'NONE'
}
ISSUE_FINDER= {'id':0,
'name':'ISSUE_FINDER'}
LIFESTYLE_CONSUMER= {'id':1,
'name':'LIFESTYLE_CONSUMER'}
ENTERTAINER= {'id':2,
'name':'ENTERTAINER'}
TECH_SPECIALIST= {'id':3,
'name':'TECH_SPECIALIST'}
PROFESSIONALS= {'id':4,
'name':'PROFESSIONALS'}
NONE = {"id": -1, "name": "NONE"}
ISSUE_FINDER = {"id": 0, "name": "ISSUE_FINDER"}
LIFESTYLE_CONSUMER = {"id": 1, "name": "LIFESTYLE_CONSUMER"}
ENTERTAINER = {"id": 2, "name": "ENTERTAINER"}
TECH_SPECIALIST = {"id": 3, "name": "TECH_SPECIALIST"}
PROFESSIONALS = {"id": 4, "name": "PROFESSIONALS"}


class UserTypePercent(BaseModel):
issueFinder: int
lifestyleConsumer: int
entertainer: int
techSpecialist: int
professionals: int

def get_dominant_type(self) -> str:
max_value = max(self.dict().values())
for key, value in self.dict().items():
if value == max_value:
for user_type in UserTypes:
if user_type.name.lower() == key.lower():
return user_type.name
return UserTypes.NONE.name

return UserTypes.NONE.name
23 changes: 14 additions & 9 deletions app/router/user_type_router.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import Dict, List
from typing import List

from fastapi import APIRouter, Depends
from groq import BaseModel
from sqlalchemy.ext.asyncio import AsyncSession

from app.database.session import get_db_session
from app.model.user_type import UserTypePercent
from app.recommend.recommend_service import user_type_to_classification_id
from app.repository.crawled_article_crud import CrawledArticleRepository
from app.repository.recommend_crud import RecommendRepository
Expand All @@ -28,7 +29,8 @@ class ArticleResponseDTO(BaseModel):


class UserTypeResponseDTO(BaseModel):
userType: Dict
percent: UserTypePercent
userType: str
recommendNews: List[ArticleResponseDTO]


Expand Down Expand Up @@ -69,16 +71,19 @@ async def create_user_type_by_answers(
)
)

percent = UserTypePercent(
issueFinder=userType[0],
lifestyleConsumer=userType[1],
entertainer=userType[2],
techSpecialist=userType[3],
professionals=userType[4],
)

return GenericResponseDTO[UserTypeResponseDTO](
data=UserTypeResponseDTO(
userType={
"ISSUE_FINDER": userType[0],
"LIFESTYLE_CONSUMER": userType[1],
"ENTERTAINER": userType[2],
"TECH_SPECIALIST": userType[3],
"PROFESSIONALS": userType[4],
},
percent=percent,
recommendNews=recommendNews,
userType=percent.get_dominant_type(),
),
message="유형검사 결과가 성공",
result=True,
Expand Down

0 comments on commit a0f893c

Please sign in to comment.