From f3ced47fbe2556330056bce5bb91aef79bda98e5 Mon Sep 17 00:00:00 2001 From: dlwhsk0 Date: Mon, 22 Jul 2024 03:28:30 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=AA=A9=EC=86=8C=EB=A6=AC=20=EC=83=81?= =?UTF-8?q?=EC=84=B8=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20character?= =?UTF-8?q?=5Fimage=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/routers/voices.py | 6 ++---- app/schemas/voice.py | 18 ------------------ app/services/voice_service.py | 14 +++++++++++++- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/app/routers/voices.py b/app/routers/voices.py index efed9c0..1ca399b 100644 --- a/app/routers/voices.py +++ b/app/routers/voices.py @@ -7,7 +7,7 @@ from ..schemas.response import ResultResponseModel from app.config.aws.s3Client import upload_voice -from app.schemas.voice import VoiceBase, VoiceBaseList, VoiceDetailList +from app.schemas.voice import VoiceDetail, VoiceDetailList router = APIRouter( @@ -55,9 +55,7 @@ def read_voices_in_chat_room(chat_id: int, db: Session = Depends(get_db)): @router.get("/{voice_id}", response_model=ResultResponseModel, summary="저장한 목소리 상세 조회", description="특정 목소리의 상세 정보를 조회합니다.") def read_voice(voice_id: int, db: Session = Depends(get_db)): voice = voice_service.get_voice(db, voice_id=voice_id) - if not voice: - raise HTTPException(status_code=404, detail="목소리 정보를 불러오는데 실패했습니다.") - return ResultResponseModel(code=200, message="목소리 상세 정보를 조회했습니다.", data=VoiceBase.from_orm(voice)) + return ResultResponseModel(code=200, message="목소리 상세 정보를 조회했습니다.", data=voice) # 저장한 목소리 소프트 삭제 diff --git a/app/schemas/voice.py b/app/schemas/voice.py index e187992..7508b8a 100644 --- a/app/schemas/voice.py +++ b/app/schemas/voice.py @@ -4,24 +4,6 @@ from datetime import datetime -class VoiceBase(BaseModel): - id: int - bubble_id: int - audio_url: str - content: str - created_at: datetime - - class Config: - from_attributes = True - - -class VoiceBaseList(BaseModel): - voices: List[VoiceBase] - - class Config: - from_attributes = True - - class VoiceDetail(BaseModel): id: int chat_id: int diff --git a/app/services/voice_service.py b/app/services/voice_service.py index c928ee3..d5fc25e 100644 --- a/app/services/voice_service.py +++ b/app/services/voice_service.py @@ -42,7 +42,19 @@ def get_voices_by_chat_id(db: Session, chat_id: int): # 단일 목소리 상세 조회 def get_voice(db: Session, voice_id: int): - return db.query(Voice).filter(Voice.id == voice_id, Voice.is_deleted == False).first() + voice = db.query(Voice).filter(Voice.id == voice_id, Voice.is_deleted == False).first() + if not voice: + raise HTTPException(status_code=404, detail="목소리 정보를 불러오는데 실패했습니다.") + return VoiceDetail( + id=voice.id, + chat_id=voice.bubble.chat_id, + character=voice.bubble.chat.character.name, + character_image=voice.bubble.chat.character.image_url, + bubble_id=voice.bubble_id, + audio_url=voice.audio_url, + content=voice.content, + created_at=voice.created_at + ) # 저장한 목소리 하드 삭제