Skip to content

Commit

Permalink
Characters: Added Route for get favorite lines
Browse files Browse the repository at this point in the history
  • Loading branch information
BertiRean committed Oct 25, 2023
1 parent c75f9c0 commit 0c64280
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 5 additions & 1 deletion app/models/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,8 @@ class UpdateCharacterLineFavorite(BaseModel):
favorite : bool

class UpdateCharacterLineFavoriteResponse(BaseModel):
status : str = "success"
status : str = "success"

class ExportCharacterLinesResponse(BaseModel):
status : str = "success"
lines : dict
28 changes: 27 additions & 1 deletion app/routes/character.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from fastapi.encoders import jsonable_encoder
from models.character import (Character, CharacterDataResponse,
CharacterResponse, DeleteCharacterBody,
DeleteCharacterResponse, UpdateCharacter, UpdateCharacterLineFavorite, UpdateCharacterLineFavoriteResponse,
DeleteCharacterResponse, ExportCharacterLinesResponse, UpdateCharacter, UpdateCharacterLineFavorite, UpdateCharacterLineFavoriteResponse,
UserCharactersResponse)
from models.user import User

Expand Down Expand Up @@ -198,4 +198,30 @@ async def mark_favorite_line(characterId : PydanticObjectId, payload : UpdateCha

return UpdateCharacterLineFavoriteResponse()


@router.get(
"/export-dialogues/{userId}",
response_description="Get a Json File with all dialogues of characters",
response_model=ExportCharacterLinesResponse,
)
async def export_character_lines(userId : PydanticObjectId):
user = await User.find_one(User.id == userId, fetch_links=True)

if not user:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"User with id {userId} not found",
)

lines = {}
for char in user.characters:
if len(char.favorite_dialogues) == 0:
continue
lines[char.name] = []
for line in char.favorite_dialogues:
lines[char.name].append(line)


return ExportCharacterLinesResponse(status="success", lines=lines)


0 comments on commit 0c64280

Please sign in to comment.