-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschemas.py
More file actions
92 lines (74 loc) · 2.37 KB
/
Copy pathschemas.py
File metadata and controls
92 lines (74 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from __future__ import annotations
from pydantic import BaseModel
from pydantic import Field
from wacruit.src.apps.common.enums import ProjectType
from wacruit.src.apps.common.schemas import OrmModel
class ProjectLinkDto(BaseModel):
title: str
url: str
class ProjectCreateRequest(BaseModel):
name: str = Field(..., max_length=30)
summary: str | None = Field(None, max_length=50)
introduction: str | None = Field(None, max_length=255)
thumbnail_url: str | None = Field(None, max_length=255)
project_type: str
is_active: bool
images: list[str] | None
urls: list[ProjectLinkDto] | None
class ProjectUpdateRequest(BaseModel):
name: str | None = Field(None, max_length=30)
summary: str | None = Field(None, max_length=50)
introduction: str | None = Field(None, max_length=255)
thumbnail_url: str | None = Field(None, max_length=255)
project_type: str | None
is_active: bool | None
images: list[str] | None
urls: list[ProjectLinkDto] | None
class ProjectDetailResponse(OrmModel):
id: int
name: str
summary: str | None
introduction: str | None
thumbnail_url: str | None
project_type: str
is_active: bool
images: list[str] | None
urls: list[ProjectLinkDto] | None
@classmethod
def from_orm(cls, obj):
urls = None
if obj.urls:
urls = [ProjectLinkDto(title=url.title, url=url.url) for url in obj.urls]
images = None
if obj.image_urls:
images = [img.url for img in obj.image_urls]
return cls(
id=obj.id,
name=obj.name,
summary=obj.summary,
introduction=obj.introduction,
thumbnail_url=obj.thumbnail_url,
project_type=obj.project_type.name,
is_active=obj.is_active,
images=images,
urls=urls,
)
class ProjectBriefResponse(OrmModel):
id: int
name: str
summary: str | None
thumbnail_url: str | None
project_type: str
is_active: bool
@classmethod
def from_orm(cls, obj):
return cls(
id=obj.id,
name=obj.name,
summary=obj.summary,
thumbnail_url=obj.thumbnail_url,
project_type=obj.project_type.name,
is_active=obj.is_active,
)
class ProjectListResponse(OrmModel):
projects: list[ProjectBriefResponse]