노래 백그라운드 추가

This commit is contained in:
bluebamus committed 2025-12-24 15:13:46 +09:00
1 parent cafe6a894e
commit b7df726345
14 files changed
+1102 -715

No files matched your search

+24 -85
View File
@@ -8,23 +8,22 @@ Lyric API Schemas
LyricStatusResponse,
LyricDetailResponse,
LyricListItem,
PaginatedResponse,
)
from app.utils.pagination import PaginatedResponse
# 라우터에서 response_model로 사용
@router.get("/lyric/{task_id}", response_model=LyricDetailResponse)
async def get_lyric(task_id: str):
...
# 페이지네이션 응답 (다른 모델에서도 재사용 가능)
# 페이지네이션 응답 (공통 스키마 사용)
@router.get("/songs", response_model=PaginatedResponse[SongListItem])
async def list_songs(...):
...
"""
import math
from datetime import datetime
from typing import Generic, List, Optional, TypeVar
from typing import Optional
from pydantic import BaseModel, Field
@@ -72,22 +71,36 @@ class GenerateLyricResponse(BaseModel):
POST /lyric/generate
Returns the generated lyrics.
Example Response:
Note:
실패 조건:
- ChatGPT API 오류
- ChatGPT 거부 응답 (I'm sorry, I cannot, I can't, I apologize 등)
- 응답에 ERROR: 포함
Example Response (Success):
{
"success": true,
"task_id": "019123ab-cdef-7890-abcd-ef1234567890",
"lyric": "생성된 가사...",
"lyric": "인스타 감성의 스테이 머뭄...",
"language": "Korean",
"prompt_used": "..."
"error_message": null
}
Example Response (Failure):
{
"success": false,
"task_id": "019123ab-cdef-7890-abcd-ef1234567890",
"lyric": null,
"language": "Korean",
"error_message": "I'm sorry, I can't comply with that request."
}
"""
success: bool = Field(..., description="생성 성공 여부")
task_id: Optional[str] = Field(None, description="작업 고유 식별자")
lyric: Optional[str] = Field(None, description="생성된 가사")
task_id: Optional[str] = Field(None, description="작업 고유 식별자 (uuid7)")
lyric: Optional[str] = Field(None, description="생성된 가사 (성공 시)")
language: str = Field(..., description="가사 언어")
prompt_used: Optional[str] = Field(None, description="사용된 프롬프트")
error_message: Optional[str] = Field(None, description="에러 메시지 (실패 시)")
error_message: Optional[str] = Field(None, description="에러 메시지 (실패 시, ChatGPT 거부 응답 포함)")
class LyricStatusResponse(BaseModel):
@@ -150,77 +163,3 @@ class LyricListItem(BaseModel):
status: str = Field(..., description="처리 상태")
lyric_result: Optional[str] = Field(None, description="생성된 가사 (미리보기)")
created_at: Optional[datetime] = Field(None, description="생성 일시")
T = TypeVar("T")
class PaginatedResponse(BaseModel, Generic[T]):
"""페이지네이션 응답 스키마 (재사용 가능)
Usage:
다른 모델에서도 페이지네이션이 필요할 때 재사용 가능:
- PaginatedResponse[LyricListItem]
- PaginatedResponse[SongListItem]
- PaginatedResponse[VideoListItem]
Example:
from app.lyric.schemas.lyric import PaginatedResponse
@router.get("/items", response_model=PaginatedResponse[ItemModel])
async def get_items(page: int = 1, page_size: int = 20):
...
Example Response:
{
"items": [...],
"total": 100,
"page": 1,
"page_size": 20,
"total_pages": 5,
"has_next": true,
"has_prev": false
}
"""
items: List[T] = Field(..., description="데이터 목록")
total: int = Field(..., description="전체 데이터 수")
page: int = Field(..., description="현재 페이지 (1부터 시작)")
page_size: int = Field(..., description="페이지당 데이터 수")
total_pages: int = Field(..., description="전체 페이지 수")
has_next: bool = Field(..., description="다음 페이지 존재 여부")
has_prev: bool = Field(..., description="이전 페이지 존재 여부")
@classmethod
def create(
cls,
items: List[T],
total: int,
page: int,
page_size: int,
) -> "PaginatedResponse[T]":
"""페이지네이션 응답을 생성하는 헬퍼 메서드
Args:
items: 현재 페이지의 데이터 목록
total: 전체 데이터 수
page: 현재 페이지 번호
page_size: 페이지당 데이터 수
Returns:
PaginatedResponse: 완성된 페이지네이션 응답
Usage:
items = [LyricListItem(...) for lyric in lyrics]
return PaginatedResponse.create(items, total=100, page=1, page_size=20)
"""
total_pages = math.ceil(total / page_size) if total > 0 else 1
return cls(
items=items,
total=total,
page=page,
page_size=page_size,
total_pages=total_pages,
has_next=page < total_pages,
has_prev=page > 1,
)