project
create_project(token, project_data, db=Depends(get_db_session))
async
¶
Creates a new project and stores it in the database. The function checks the authentication token, decodes it, retrieves the authenticated user's details, and associates the project data with the user. The new project is saved to the database, and a success response is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Annotated[str, Depends(oauth2_scheme)]
|
Authentication token obtained from the user. Used to validate user identity and permission. |
required |
project_data
|
EnProject
|
Project data containing information required to create a new project in the database. |
required |
db
|
Session
|
Database session dependency. Used for interacting with the database. Dependency injection. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
MessageResponse
|
An object containing a success message indicating the project has been created. |
Raises:
Type | Description |
---|---|
HTTPException
|
Raised with a 401 status code if the user is not authenticated due to a missing or invalid token. |
Source code in backend/app/project/router.py
delete_project(token, project_id, db=Depends(get_db_session))
async
¶
Deletes a project and all associated scenarios from the database.
This endpoint allows the authenticated user to delete a specified project and its associated scenarios, provided they have the necessary authorization and ownership. The function validates the user's token and ownership of the specified project before deleting it and committing the changes to the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Annotated[str, Depends(oauth2_scheme)]
|
A string representing the user's authentication token. |
required |
project_id
|
int
|
Integer representing the ID of the project to be deleted. |
required |
db
|
Session
|
The session instance for interacting with the database. Dependency injection. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
MessageResponse
|
A MessageResponse object containing a confirmation message and the success status of the operation. |
Raises:
Type | Description |
---|---|
HTTPException
|
If the user is not authenticated or if they are not authorized to delete the project. |
HTTPException
|
If the project is not found in the database. |
HTTPException
|
If the project is not owned by the user. |
HTTPException
|
If there are associated scenarios in the project. |
Source code in backend/app/project/router.py
read_project(project_id, token, db=Depends(get_db_session))
async
¶
Retrieves project details by the given project ID. This endpoint fetches details about a project from the database after validating the provided authentication token and confirming ownership of the project by the authenticated user.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_id
|
int
|
The unique identifier of the project to retrieve. |
required |
token
|
Annotated[str, Depends(oauth2_scheme)]
|
Authentication token provided by the user for accessing the endpoint. |
required |
db
|
Session
|
Database session used for accessing stored data. Dependency injection. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
DataResponse
|
The response containing project data wrapped in a structured response model. |
Raises:
Type | Description |
---|---|
HTTPException
|
If authentication fails or if the user is not authorized to access the specified project. |
Source code in backend/app/project/router.py
read_projects(token, db=Depends(get_db_session))
async
¶
Fetches and returns a list of projects associated with the authenticated user. The function validates the provided token, retrieves the associated user details, and fetches all projects corresponding to the user. The result includes details of all retrieved projects wrapped in a standardized response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Annotated[str, Depends(oauth2_scheme)]
|
The authentication token is extracted from the request. |
required |
db
|
Session
|
The database session dependency used to execute queries. Dependency injection. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
DataResponse
|
A standardized response containing a list of projects for the authenticated user, along with the total count of projects. |
Raises:
Type | Description |
---|---|
HTTPException
|
If the provided token is missing or invalid. |
Source code in backend/app/project/router.py
update_project(token, project_id, project_data, db=Depends(get_db_session))
async
¶
Updates the details of an existing project. This endpoint allows authenticated and authorized users to modify the properties of a given project. The function fetches the project by its ID, validates the user's ownership of the project, and updates the provided information in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
token
|
Annotated[str, Depends(oauth2_scheme)]
|
The authentication token of the user making the request. |
required |
project_id
|
int
|
The unique identifier of the project to be updated. |
required |
project_data
|
EnProjectUpdate
|
The new data to update the project with. |
required |
db
|
Session
|
The database session used for querying and updating project details. Dependency injection. |
Depends(get_db_session)
|
Returns:
Type | Description |
---|---|
MessageResponse
|
A |
Source code in backend/app/project/router.py
validate_project_owner(project_id, token, db)
¶
Validates whether the user associated with a given token is the owner of a project identified by the provided project_id. Verifies the token's authenticity, fetches the project from the database, and compares its ownership details to ensure the user has the necessary permissions to access or modify the project.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
project_id
|
int
|
ID of the project whose ownership is being validated |
required |
token
|
str
|
JWT token provided for authentication and identifying the user |
required |
db
|
Session
|
Database session object used to query project and user information. Dependency injection. |
required |
Returns:
Type | Description |
---|---|
bool
|
Returns True if the token user is the owner of the project, otherwise raises an exception |
Raises:
Type | Description |
---|---|
HTTPException
|
If the project is not found in the database (404) |
HTTPException
|
If the user associated with the token does not own the project (403) |