From ba8f7f8c4509659f18543d0ac6aa916b5320fae3 Mon Sep 17 00:00:00 2001 From: dlwhsk0 Date: Tue, 30 Jul 2024 16:02:05 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=20=EC=84=A0?= =?UTF-8?q?=ED=83=9D=20=EB=B3=B4=EC=9D=B4=EC=8A=A4=20=EC=A0=80=EC=9E=A5=20?= =?UTF-8?q?=EC=8B=9C=20=EC=A4=91=EB=B3=B5=20=EA=B2=80=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/voice_service.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/services/voice_service.py b/app/services/voice_service.py index 1fbde24..392bb58 100644 --- a/app/services/voice_service.py +++ b/app/services/voice_service.py @@ -85,6 +85,9 @@ def create_voice(db: Session, bubble_id: int, audio_url: str): bubble = bubble_service.get_bubble(db, bubble_id=bubble_id) if not bubble: raise HTTPException(status_code=404, detail="대화를 불러오는데 실패했습니다.") + voice_exist = get_voice_by_bubble(db, bubble_id=bubble_id) + if voice_exist: + raise HTTPException(status_code=409, detail="이미 저장된 목소리 입니다.") voice = Voice(bubble_id=bubble_id, content=bubble.content, audio_url=audio_url) db.add(voice) db.commit() @@ -101,11 +104,16 @@ def create_voice(db: Session, bubble_id: int, audio_url: str): ) -# 목소리 모델 가져오기 +# 목소리 가져오기 def get_voice(db: Session, voice_id: int): return db.query(Voice).filter(Voice.id == voice_id, Voice.is_deleted == False).first() +# 버블 별 목소리 가져오기 +def get_voice_by_bubble(db: Session, bubble_id: int): + return db.query(Voice).filter(Voice.bubble_id == bubble_id, Voice.is_deleted == False).first() + + # 목소리 카운트 증가시키기 def get_voice_count(db: Session, voice_id: int): voice = db.query(Voice).filter(Voice.id == voice_id, Voice.is_deleted == False).first()