1- from fastapi import APIRouter , Depends , HTTPException , status
2- from sqlalchemy .orm import Session
31from typing import List
42
5- from src .utils .security import get_current_user
3+ from sqlalchemy .orm import Session
4+ from fastapi import APIRouter , Depends , HTTPException , status
5+
6+ from src .utils .utils import get_db
67from src .models .user_model import User
78from src .models .project_model import Project
8- from src .utils .utils import get_db
9+ from src .utils .security import get_current_user
910from src .schemas .projects .projects_schema import ProjectCreate , ProjectResponse
1011
1112project_router = APIRouter (prefix = "/projects" , tags = ["projects" ])
@@ -19,6 +20,27 @@ def create_project(
1920 db : Session = Depends (get_db ),
2021 current_user : User = Depends (get_current_user ),
2122):
23+ """
24+ Create a new project for the authenticated user.
25+
26+ This endpoint allows the current authenticated user to create a new project
27+ by providing the required project data. The project will be associated with
28+ the user who is currently authenticated.
29+
30+ Args:
31+ project (ProjectCreate): The project data to be created, including title and description.
32+ db (Session): SQLAlchemy database session dependency.
33+ current_user (User): The currently authenticated user, injected by dependency.
34+
35+ Returns:
36+ ProjectResponse: The newly created project data.
37+
38+ Raises:
39+ HTTPException: If the user is not authenticated or if there is a database error.
40+
41+ Status Codes:
42+ 201 CREATED: Project was successfully created.
43+ """
2244 new_project = Project (
2345 user_id = current_user .id , title = project .title , description = project .description
2446 )
@@ -32,6 +54,25 @@ def create_project(
3254def list_projects (
3355 db : Session = Depends (get_db ), current_user : User = Depends (get_current_user )
3456):
57+ """
58+ List all projects for the authenticated user.
59+
60+ This endpoint allows the current authenticated user to retrieve a list of all
61+ projects associated with their account.
62+
63+ Args:
64+ db (Session): SQLAlchemy database session dependency.
65+ current_user (User): The currently authenticated user, injected by dependency.
66+
67+ Returns:
68+ List[ProjectResponse]: A list of projects associated with the authenticated user.
69+
70+ Raises:
71+ HTTPException: If the user is not authenticated.
72+
73+ Status Codes:
74+ 200 OK: Projects were successfully retrieved.
75+ """
3576 return db .query (Project ).filter (Project .user_id == current_user .id ).all ()
3677
3778
@@ -41,6 +82,27 @@ def get_project(
4182 db : Session = Depends (get_db ),
4283 current_user : User = Depends (get_current_user ),
4384):
85+ """
86+ Get a specific project for the authenticated user.
87+
88+ This endpoint allows the current authenticated user to retrieve a specific
89+ project associated with their account by providing the project ID.
90+
91+ Args:
92+ project_id (int): The ID of the project to retrieve.
93+ db (Session): SQLAlchemy database session dependency.
94+ current_user (User): The currently authenticated user, injected by dependency.
95+
96+ Returns:
97+ ProjectResponse: The project data for the specified project ID.
98+
99+ Raises:
100+ HTTPException: If the user is not authenticated or if the project is not found.
101+
102+ Status Codes:
103+ 200 OK: Project was successfully retrieved.
104+ 404 NOT FOUND: Project was not found.
105+ """
44106 project = (
45107 db .query (Project )
46108 .filter (Project .id == project_id , Project .user_id == current_user .id )
@@ -58,6 +120,29 @@ def update_project(
58120 db : Session = Depends (get_db ),
59121 current_user : User = Depends (get_current_user ),
60122):
123+ """
124+ Update a specific project for the authenticated user.
125+
126+ This endpoint allows the current authenticated user to update a specific
127+ project associated with their account by providing the project ID and the
128+ updated project data.
129+
130+ Args:
131+ project_id (int): The ID of the project to update.
132+ updated (ProjectCreate): The updated project data, including title and description.
133+ db (Session): SQLAlchemy database session dependency.
134+ current_user (User): The currently authenticated user, injected by dependency.
135+
136+ Returns:
137+ ProjectResponse: The updated project data.
138+
139+ Raises:
140+ HTTPException: If the user is not authenticated or if the project is not found.
141+
142+ Status Codes:
143+ 200 OK: Project was successfully updated.
144+ 404 NOT FOUND: Project was not found.
145+ """
61146 project = (
62147 db .query (Project )
63148 .filter (Project .id == project_id , Project .user_id == current_user .id )
@@ -78,6 +163,22 @@ def delete_project(
78163 db : Session = Depends (get_db ),
79164 current_user : User = Depends (get_current_user ),
80165):
166+ """
167+ Delete a specific project for the authenticated user.
168+ This endpoint allows the current authenticated user to delete a specific
169+ project associated with their account by providing the project ID.
170+
171+ Args:
172+ project_id (int): The ID of the project to delete.
173+ db (Session): SQLAlchemy database session dependency.
174+ current_user (User): The currently authenticated user, injected by dependency.
175+
176+ Raises:
177+ HTTPException: If the user is not authenticated or if the project is not found.
178+
179+ Status Codes:
180+ 204 NO CONTENT: Project was successfully deleted.
181+ """
81182 project = (
82183 db .query (Project )
83184 .filter (Project .id == project_id , Project .user_id == current_user .id )
0 commit comments