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 + ) # 저장한 목소리 하드 삭제