diff --git a/app/model/user_type.py b/app/model/user_type.py index dc3957e..21dfab8 100644 --- a/app/model/user_type.py +++ b/app/model/user_type.py @@ -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 @@ -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 diff --git a/app/router/user_type_router.py b/app/router/user_type_router.py index 8dcafaf..215c0ca 100644 --- a/app/router/user_type_router.py +++ b/app/router/user_type_router.py @@ -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 @@ -28,7 +29,8 @@ class ArticleResponseDTO(BaseModel): class UserTypeResponseDTO(BaseModel): - userType: Dict + percent: UserTypePercent + userType: str recommendNews: List[ArticleResponseDTO] @@ -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,