from datetime import date, datetime from dataclasses import dataclass from typing import Optional, List, Any from models.artist_moment_type_group import ArtistMomentTypeGroup from models.artist_moment_category import ArtistMomentCategory from models.artist_moment_type import ArtistMomentType from models.artist_moment import ArtistMoment from shared.schemas import ArtistSchema, ShortUserModel from services.territory.territories_repository import TerritoryResponseModel @dataclass class ArtistMomentTypeResponseSchema: id: int name: str def __init__(self, type: ArtistMomentType): self.id = type.id self.name = type.name @dataclass class ArtistMomentsGropedTypesResponseSchema: id: int name: str types: List[ArtistMomentTypeResponseSchema] def __init__(self, group: ArtistMomentTypeGroup): self.id = group.id self.name = group.name self.types = [ArtistMomentTypeResponseSchema(type) for type in group.types] @dataclass class ArtistMomentCategoryResponseSchema: id: int name: str def __init__(self, type: ArtistMomentCategory): self.id = type.id self.name = type.name @dataclass class MomentEditableFields: name: bool = True date: bool = True artist: bool = True territories: bool = True link: bool = True notes: bool = True type: bool = True category: bool = True @dataclass class MomentMetadata: fields: MomentEditableFields @dataclass class ArtistMomentResponseSchema: id: int name: str date: date artist: ArtistSchema territories: List[TerritoryResponseModel] createUser: Optional[ShortUserModel] editUser: Optional[ShortUserModel] editDate: datetime link: Optional[str] notes: Optional[str] type: Optional[ArtistMomentTypeResponseSchema] category: Optional[ArtistMomentCategoryResponseSchema] metadata: Any def __init__(self, artist_moment: ArtistMoment): self.id = artist_moment.id self.projectId = artist_moment.project_id self.name = artist_moment.name self.date = artist_moment.date self.artist = ArtistSchema.from_db_model(artist_moment.artist) if artist_moment.type: self.type = ArtistMomentTypeResponseSchema(artist_moment.type) if artist_moment.category: self.category = ArtistMomentCategoryResponseSchema(artist_moment.category) self.territories = [TerritoryResponseModel(territory) for territory in artist_moment.territories] if artist_moment.create_user: self.createUser = ShortUserModel(artist_moment.create_user) if artist_moment.edit_user: self.editUser = ShortUserModel(artist_moment.edit_user) self.link = artist_moment.link self.notes = artist_moment.notes self.editDate = artist_moment.updated_at self.metadata = artist_moment.metainfo @dataclass class CreateArtistMomentRequestSchema: name: str date: date artistId: str territoriesIds: List[int] link: Optional[str] notes: Optional[str] typeId: Optional[int] categoryId: Optional[int]