Skip to content

Commit

Permalink
fix(persona): get Persona API 인증 빼기, 응답리스트 PUT으로 변경 (#45)
Browse files Browse the repository at this point in the history
* fix(persona): get Persona API 인증 빼기, 응답리스트 PUT으로 변경

* chore: 불필요한 테스트 삭제

* chore: 코드리뷰 반영-query 이름 변경
  • Loading branch information
parkdaye committed Aug 15, 2020
1 parent fd81968 commit f7d89b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
28 changes: 18 additions & 10 deletions src/apps/persona/routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List

from fastapi import status
from fastapi.param_functions import Depends, Security
from fastapi.param_functions import Depends, Query, Security
from fastapi.routing import APIRouter
from sqlalchemy.orm import Session

Expand All @@ -24,7 +24,6 @@
response_model=PersonaQuestionsResponse,
)
async def get_questions(
current_user: UserInDB = Security(get_current_user),
session: Session = Depends(get_database_session),
) -> PersonaQuestionsResponse:
""" 페르소나 분석 질문 리스트 """
Expand All @@ -38,26 +37,39 @@ async def get_questions(
)


@router.post(
@router.put(
path="/answers",
name="페르소나 질문 응답 저장",
status_code=status.HTTP_201_CREATED,
response_model=List[ChoiceItemDto],
)
async def post_answers(
async def update_answers(
choices: List[int],
current_user: UserInDB = Security(get_current_user),
session: Session = Depends(get_database_session),
) -> List[ChoiceItemDto]:

answers = [
QuestionAnswer(user_id=current_user.uid, choice_id=choice_id)
for choice_id in choices
]

user_answers: QuestionAnswer = (
session.query(QuestionAnswer)
.filter(QuestionAnswer.user_id == current_user.uid)
.all()
)

if user_answers:
for user_answer in user_answers:
session.delete(user_answer)

for answer in answers:
session.add(answer)
session.flush()
session.refresh(answer)
session.commit()

return [ChoiceItemDto.from_orm(answer.choice) for answer in answers]


Expand All @@ -68,16 +80,12 @@ async def post_answers(
response_model=PersonaResponse,
)
async def get_persona(
current_user: UserInDB = Security(get_current_user),
session: Session = Depends(get_database_session),
check_answers: List[int] = Query(...),
) -> PersonaResponse:
""" 나의 페르소나
페르소나 분석 결과
"""
persona = services.get_persona(
answers=services.get_user_choices(
user_info=current_user, session=session
)
)
persona = services.get_persona(check_answers)
return PersonaResponse(title=persona.name, description=persona.value)
2 changes: 1 addition & 1 deletion src/apps/persona/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .models.entity import QuestionAnswer


def get_persona(answers: List[ChoiceItemDto]) -> Persona:
def get_persona(check_answers: List[int]) -> Persona:
""" 사용자 페르소나 분석 """
return Persona.핵인싸

Expand Down
23 changes: 0 additions & 23 deletions tests/unit/apps/persona/services/test_question.py

This file was deleted.

0 comments on commit f7d89b8

Please sign in to comment.