This commit is contained in:
commit
46af290db3
100 files changed
+16663
No files matched your search
@@ -0,0 +1,83 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from models.bible import Character, Event, Location, StoryBible, StoryThread
|
||||
from models.user import User
|
||||
from services.bible_service import bible_service
|
||||
|
||||
from routers.auth import get_current_user
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def _get_user_project(project_id: str, current_user: User) -> None:
|
||||
"""Проверить что проект принадлежит пользователю"""
|
||||
from services.project_service import project_service
|
||||
|
||||
project = project_service.get_project(project_id)
|
||||
if not project:
|
||||
raise HTTPException(status_code=404, detail="Project not found")
|
||||
if project.user_id != current_user.id:
|
||||
raise HTTPException(status_code=403, detail="Access denied")
|
||||
|
||||
|
||||
@router.get("/projects/{project_id}/bible", response_model=StoryBible)
|
||||
async def get_story_bible(
|
||||
project_id: str, current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Получить Story Bible проекта"""
|
||||
_get_user_project(project_id, current_user)
|
||||
return bible_service.get_bible(project_id, current_user.id)
|
||||
|
||||
|
||||
@router.put("/projects/{project_id}/bible", response_model=StoryBible)
|
||||
async def update_story_bible(
|
||||
project_id: str,
|
||||
bible: StoryBible,
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Обновить всю Story Bible проекта"""
|
||||
_get_user_project(project_id, current_user)
|
||||
return bible_service.update_bible(project_id, bible, current_user.id)
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/bible/characters", response_model=Character)
|
||||
async def add_character(
|
||||
project_id: str,
|
||||
character: Character,
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Добавить нового персонажа в проект"""
|
||||
_get_user_project(project_id, current_user)
|
||||
return bible_service.add_character(project_id, character, current_user.id)
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/bible/locations", response_model=Location)
|
||||
async def add_location(
|
||||
project_id: str,
|
||||
location: Location,
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Добавить новую локацию в проект"""
|
||||
_get_user_project(project_id, current_user)
|
||||
return bible_service.add_location(project_id, location, current_user.id)
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/bible/events", response_model=Event)
|
||||
async def add_event(
|
||||
project_id: str,
|
||||
event: Event,
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Добавить новое событие в проект"""
|
||||
_get_user_project(project_id, current_user)
|
||||
return bible_service.add_event(project_id, event, current_user.id)
|
||||
|
||||
|
||||
@router.post("/projects/{project_id}/bible/threads", response_model=StoryThread)
|
||||
async def add_thread(
|
||||
project_id: str,
|
||||
thread: StoryThread,
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Добавить новую сюжетную нить в проект"""
|
||||
_get_user_project(project_id, current_user)
|
||||
return bible_service.add_thread(project_id, thread, current_user.id)
|
||||
Reference in new issue
Block a user