Skip to content

Commit 478da2f

Browse files
committed
Format files
1 parent fcdff12 commit 478da2f

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

api/projects/main.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class CreateProjectRequest(BaseModel):
2525
repo: HttpUrl
2626
preview_image: HttpUrl
2727

28+
2829
class UpdateProjectRequest(BaseModel):
2930
"""Update project request from client"""
3031

@@ -99,12 +100,21 @@ async def update_project(
99100

100101
# Validate preview image if being updated
101102
if project_request.preview_image is not None:
102-
if project_request.preview_image.host != 'hc-cdn.hel1.your-objectstorage.com':
103-
raise HTTPException(status_code=400, detail='image must be hosted on hc cdn')
103+
if project_request.preview_image.host != "hc-cdn.hel1.your-objectstorage.com":
104+
raise HTTPException(
105+
status_code=400, detail="image must be hosted on hc cdn"
106+
)
104107

105-
update_data = project_request.model_dump(exclude_unset=True, exclude={"project_id"}, mode='python')
108+
update_data = project_request.model_dump(
109+
exclude_unset=True, exclude={"project_id"}, mode="python"
110+
)
106111

107-
allowed_update_fields = {"project_name", "hackatime_projects", "repo", "preview_image"}
112+
allowed_update_fields = {
113+
"project_name",
114+
"hackatime_projects",
115+
"repo",
116+
"preview_image",
117+
}
108118
for field, value in update_data.items():
109119
if field in allowed_update_fields:
110120
model_field = "name" if field == "project_name" else field
@@ -119,7 +129,9 @@ async def update_project(
119129
return JSONResponse(
120130
{
121131
"success": True,
122-
"project_info": ProjectResponse.from_model(project).model_dump(mode='json'),
132+
"project_info": ProjectResponse.from_model(project).model_dump(
133+
mode="json"
134+
),
123135
}
124136
)
125137
except Exception: # type: ignore # pylint: disable=broad-exception-caught
@@ -206,8 +218,11 @@ async def create_project(
206218
) # if the user hasn't been created yet they shouldn't be authed
207219

208220
# Validate preview image
209-
if project_create_request.preview_image.host != 'hc-cdn.hel1.your-objectstorage.com':
210-
raise HTTPException(status_code=400, detail='image must be hosted on hc cdn')
221+
if (
222+
project_create_request.preview_image.host
223+
!= "hc-cdn.hel1.your-objectstorage.com"
224+
):
225+
raise HTTPException(status_code=400, detail="image must be hosted on hc cdn")
211226

212227
new_project = UserProject(
213228
name=project_create_request.project_name,
@@ -227,7 +242,9 @@ async def create_project(
227242
return JSONResponse(
228243
{
229244
"success": True,
230-
"project_info": ProjectResponse.from_model(new_project).model_dump(mode='json'),
245+
"project_info": ProjectResponse.from_model(new_project).model_dump(
246+
mode="json"
247+
),
231248
}
232249
)
233250
except Exception as e: # type: ignore # pylint: disable=broad-exception-caught

models/user.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,8 @@ class UserProject(Base):
6767
default=lambda: datetime.now(timezone.utc),
6868
onupdate=lambda: datetime.now(timezone.utc),
6969
)
70-
repo: Mapped[str] = MappedColumn(
71-
String, nullable=True, default=''
72-
)
73-
preview_image: Mapped[str] = MappedColumn(
74-
String, nullable=True, default=''
75-
)
70+
repo: Mapped[str] = MappedColumn(String, nullable=True, default="")
71+
preview_image: Mapped[str] = MappedColumn(String, nullable=True, default="")
7672

7773
# Relationship back to user
7874
user: Mapped["User"] = relationship("User", back_populates="projects")

0 commit comments

Comments
 (0)