Skip to content

Commit 420a9aa

Browse files
refact(projects-routes): Ajustment in projects route
Ajustment in projects routes due to new atribute in projects table.
1 parent 025877e commit 420a9aa

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/models/project_model.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ class Project(Base):
1212
user_id (int): Foreign key referencing the user who owns the project.
1313
title (str): Title of the project.
1414
description (str): Detailed description of the project.
15+
color (str): Hex color associated with the project (e.g. "#FF5733").
1516
created_at (datetime): Timestamp when the project was created.
1617
updated_at (datetime): Timestamp when the project was last updated.
1718
user (User): Relationship to the User model, representing the owner of the project.
19+
tasks (List[Task]): Relationship to the Task model, representing tasks in this project.
1820
"""
1921

2022
__tablename__ = "projects"
@@ -25,6 +27,7 @@ class Project(Base):
2527
)
2628
title = Column(String(255), nullable=False)
2729
description = Column(Text)
30+
color = Column(String(7), nullable=False, server_default="#FFFFFF")
2831
created_at = Column(TIMESTAMP, server_default=func.now())
2932
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
3033

src/routes/project_routes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ def create_project(
4242
201 CREATED: Project was successfully created.
4343
"""
4444
new_project = Project(
45-
user_id=current_user.id, title=project.title, description=project.description
45+
user_id=current_user.id,
46+
title=project.title,
47+
description=project.description,
48+
color=project.color,
4649
)
4750
db.add(new_project)
4851
db.commit()
@@ -69,7 +72,7 @@ def list_projects(
6972
7073
Raises:
7174
HTTPException: If the user is not authenticated.
72-
75+
7376
Status Codes:
7477
200 OK: Projects were successfully retrieved.
7578
"""
@@ -150,8 +153,11 @@ def update_project(
150153
)
151154
if not project:
152155
raise HTTPException(status_code=404, detail="Projeto não encontrado.")
156+
153157
project.title = updated.title
154158
project.description = updated.description
159+
project.color = updated.color
160+
155161
db.commit()
156162
db.refresh(project)
157163
return project

src/schemas/projects/projects_schema.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Optional
22
from datetime import datetime
3-
from pydantic import BaseModel
3+
from pydantic import BaseModel, Field
4+
45

56
class ProjectCreate(BaseModel):
67
"""
@@ -9,24 +10,25 @@ class ProjectCreate(BaseModel):
910
Attributes:
1011
title (str): Title of the project.
1112
description (Optional[str]): Description of the project.
13+
color (str): Hexadecimal color (e.g. "#FF5733") for UI display.
1214
"""
1315
title: str
1416
description: Optional[str] = None
17+
color: str = Field(
18+
default="#FFFFFF",
19+
description="Hex color code (e.g. #FF5733)",
20+
pattern=r"^#[0-9A-Fa-f]{6}$",
21+
)
22+
1523

1624
class ProjectResponse(ProjectCreate):
1725
"""
1826
ProjectResponse schema for API responses.
1927
20-
Inherits from ProjectCreate and adds additional fields for the project ID,
21-
creation timestamp, and last update timestamp.
22-
23-
Attributes:
28+
Inherits from ProjectCreate and adds:
2429
id (int): Unique identifier for the project.
25-
created_at (datetime): Timestamp when the project was created.
26-
updated_at (datetime): Timestamp when the project was last updated.
27-
28-
Config:
29-
from_attributes (bool): Enables population of the model from ORM objects.
30+
created_at (datetime): Timestamp when created.
31+
updated_at (datetime): Timestamp when updated.
3032
"""
3133
id: int
3234
created_at: datetime

0 commit comments

Comments
 (0)