Afegir temes coocurrents
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import dataclasses
|
||||
from typing import Annotated
|
||||
|
||||
from fastapi import HTTPException, Request
|
||||
@@ -5,6 +6,7 @@ from fastapi.params import Form
|
||||
from fastapi.responses import HTMLResponse
|
||||
from folkugat_web.api.router import get_router
|
||||
from folkugat_web.fragments import tema, temes
|
||||
from folkugat_web.model.temes import Tema
|
||||
from folkugat_web.services import auth
|
||||
from folkugat_web.services import files as files_service
|
||||
from folkugat_web.services.temes import links as links_service
|
||||
@@ -32,6 +34,21 @@ def page(request: Request, logged_in: auth.LoggedIn, tema_id: int):
|
||||
)
|
||||
|
||||
|
||||
def augment_played_with(tema: Tema) -> Tema:
|
||||
if tema.played_with:
|
||||
tema.played_with = [
|
||||
dataclasses.replace(
|
||||
co_tema,
|
||||
tema=(
|
||||
FnChain.transform(co_tema.tema) |
|
||||
scores_service.add_scores_to_tema |
|
||||
properties_service.add_properties_to_tema
|
||||
).result()
|
||||
) for co_tema in tema.played_with
|
||||
]
|
||||
return tema
|
||||
|
||||
|
||||
@router.get("/api/tema/{tema_id}")
|
||||
def contingut(request: Request, logged_in: auth.LoggedIn, tema_id: int):
|
||||
tema = temes_q.get_tema_by_id(tema_id)
|
||||
@@ -40,6 +57,8 @@ def contingut(request: Request, logged_in: auth.LoggedIn, tema_id: int):
|
||||
tema = (
|
||||
FnChain.transform(tema) |
|
||||
temes_q.tema_compute_stats |
|
||||
temes_q.tema_compute_played_with |
|
||||
augment_played_with |
|
||||
links_service.add_links_to_tema |
|
||||
lyrics_service.add_lyrics_to_tema |
|
||||
scores_service.add_scores_to_tema |
|
||||
|
||||
Reference in New Issue
Block a user