added issue works on artist details

This commit is contained in:
Thomas Peetz
2025-09-23 17:08:46 +02:00
parent 2534c67a5e
commit 0db55e9ba7
6 changed files with 75 additions and 30 deletions
@@ -4,8 +4,11 @@
grid-gap: 20px; grid-gap: 20px;
} }
section { section {
margin-left: 10px; margin-left: 10px;
padding: 10px; padding: 10px;
background-color: darkgrey;
border-radius: 10px;
margin-bottom: 10px;
} }
article { article {
margin-left: 10px; margin-left: 10px;
@@ -5,18 +5,30 @@
</div> </div>
<div> <div>
@if (artist()) { @if (artist()) {
<h2>{{ artist().name }}</h2> <section>
<a href="{{ artist().weblink }}">{{ artist().name }}</a> <h2>{{ artist().name }}</h2>
@for (work of artist().works; track work.worktype.id) { <a href="{{ artist().weblink }}" style="background-color: green;">{{ artist().name }}</a>
<section> </section>
<app-comic-worktype [worktype]="work.worktype"/> @for (work of artist().comic_works; track work.worktype.id) {
@for (comic of work.comics; track comic.id) { <section>
<article> <app-comic-worktype [worktype]="work.worktype"/>
<app-comic-comic [comic]="comic"/> @for (comic of work.comics; track comic.id) {
</article> <article>
} <app-comic-comic [comic]="comic"/>
</section> </article>
} }
</section>
}
@for (work of artist().issue_works; track work.worktype.id) {
<section>
<app-comic-worktype [worktype]="work.worktype"/>
@for (issue of work.issues; track issue.id) {
<article>
<app-comic-comic [comic]="issue.comic"/>
</article>
}
</section>
}
} @else { } @else {
<h2>Artist Details</h2> <h2>Artist Details</h2>
} }
@@ -16,6 +16,20 @@ export interface Comic {
completed: boolean; completed: boolean;
} }
export interface Volume {
id: string;
name: string;
}
export interface Issue {
id: string;
issue_number: string;
in_stock: boolean;
is_read: boolean;
comic: Comic;
volume: Volume | undefined
}
export interface ComicWork { export interface ComicWork {
worktype: string; worktype: string;
@@ -38,9 +52,14 @@ export interface ArtistWorktypeComics {
comics: Comic[]; comics: Comic[];
} }
export interface ArtistWorktypeIssues {
worktype: Worktype;
issues: Issue[];
}
export interface ArtistDetails { export interface ArtistDetails {
id: string; id: string;
name: string; name: string;
weblink: string; weblink: string;
works: ArtistWorktypeComics[]; comic_works: ArtistWorktypeComics[];
issue_works: ArtistWorktypeIssues[];
} }
+13 -11
View File
@@ -1,29 +1,31 @@
from typing import List from typing import List
from src.db.models.comic import Artist from src.db.models.comic import Artist
from src.schema.comics.artist_details import ArtistDetailResponse, ArtistWorktypeComicResponse from src.schema.comics.artist_details import ArtistDetailResponse, ArtistWorktypeComicResponse, ArtistWorktypeIssueResponse
from src.schema.comics.comic import ComicResponse from src.schema.comics.comic import ComicResponse
from src.schema.comics.worktype import WorktypeResponse from src.schema.comics.worktype import WorktypeResponse
def get_artist_details(artist: Artist) -> ArtistDetailResponse: def get_artist_details(artist: Artist) -> ArtistDetailResponse:
works: List[ArtistWorktypeComicResponse] = [] comic_works: List[ArtistWorktypeComicResponse] = []
works_map = {} comic_works_map = {}
for work in artist.comic_works: for work in artist.comic_works:
worktype_id = work.work_type.id worktype_id = work.work_type.id
if worktype_id in works_map: if worktype_id in comic_works_map:
comic = ComicResponse(id=work.comic.id, title=work.comic.title, completed=work.comic.completed) comic = ComicResponse(id=work.comic.id, title=work.comic.title, completed=work.comic.completed)
works_map[worktype_id].comics.append(comic) comic_works_map[worktype_id].comics.append(comic)
else: else:
works_map[worktype_id] = ArtistWorktypeComicResponse( comic_works_map[worktype_id] = ArtistWorktypeComicResponse(
worktype=WorktypeResponse(id=worktype_id, name=work.work_type.name), worktype=WorktypeResponse(id=worktype_id, name=work.work_type.name),
comics=[ComicResponse(id=work.comic.id, title=work.comic.title, completed=work.comic.completed)] comics=[ComicResponse(id=work.comic.id, title=work.comic.title, completed=work.comic.completed)]
) )
for value in works_map.values(): for value in comic_works_map.values():
works.append(value) comic_works.append(value)
issue_works: List[ArtistWorktypeIssueResponse] = []
response = ArtistDetailResponse( response = ArtistDetailResponse(
id=artist.id, id=artist.id,
name=artist.name, name=str(artist.name),
weblink=artist.weblink, weblink=str(artist.weblink),
works=works comic_works=comic_works,
issue_works=issue_works,
) )
return response return response
@@ -2,6 +2,7 @@ from typing import List
from pydantic import BaseModel from pydantic import BaseModel
from src.schema.comics.comic import ComicResponse from src.schema.comics.comic import ComicResponse
from src.schema.comics.issue import IssueDetailsResponse
from src.schema.comics.worktype import WorktypeResponse from src.schema.comics.worktype import WorktypeResponse
@@ -9,8 +10,13 @@ class ArtistWorktypeComicResponse(BaseModel):
worktype: WorktypeResponse worktype: WorktypeResponse
comics: List[ComicResponse] comics: List[ComicResponse]
class ArtistWorktypeIssueResponse(BaseModel):
worktype: WorktypeResponse
issues: List[IssueDetailsResponse]
class ArtistDetailResponse(BaseModel): class ArtistDetailResponse(BaseModel):
id: str id: str
name: str name: str
weblink: str weblink: str
works: List[ArtistWorktypeComicResponse] comic_works: List[ArtistWorktypeComicResponse]
issue_works: List[ArtistWorktypeIssueResponse]
+5 -2
View File
@@ -1,10 +1,13 @@
from pydantic import BaseModel from pydantic import BaseModel
from src.schema.comics.comic import ComicResponse
from src.schema.comics.volume import VolumeResponse
class IssueDetailsResponse(BaseModel): class IssueDetailsResponse(BaseModel):
id: str id: str
issue_number: str issue_number: str
in_stock: bool in_stock: bool
is_read: bool is_read: bool
comic_id: str comic: ComicResponse
volume_id: str | None volume: VolumeResponse | None