Welcome to AtlanticPhoto’s documentation!#

ATLANTICPHOTO API main#

async main.healthchecker(db: AsyncSession = Depends(get_db))#

The healthchecker function is a simple function that checks if the database connection is working. It does this by making a request to the database and checking if it returns any results. If there are no results, then we know something went wrong with our connection.

Parameters:

db – AsyncSession: Inject the database session into the function

Returns:

A dictionary with the message

Doc-author:

Trelent

main.read_root()#

The read_root function returns a dictionary with the key "message" and value "AtlanticPhoto Application".

Returns:

A dictionary with a message key

Doc-author:

Trelent

async main.startup()#

The startup function is called when the application starts up. It’s a good place to initialize things that are used by the app, such as databases or caches.

Returns:

The fastapilimiter instance

Doc-author:

Trelent

ATLANTICPHOTO repository Images#

async src.repository.images.create_image(file: str, body: ImageSchema, db: AsyncSession, user: User)#

The create_image function creates a new image in the database.

Parameters:
  • file – str: Pass the file name to the function

  • body – ImageSchema: Validate the request body

  • db – AsyncSession: Pass the database session to the function

  • user – User: Get the user id from the token

Returns:

A new image object

Doc-author:

Trelent

async src.repository.images.delete_image(image_id: int, db: AsyncSession, user: User)#

The delete_image function deletes an image from the database.

Parameters:
  • image_id – int: Specify the image that is to be deleted

  • db – AsyncSession: Pass the database session to the function

  • user:User – Check if the user is allowed to delete the image

Returns:

The image that was deleted

Doc-author:

Trelent

async src.repository.images.get_all_images(limit: int, offset: int, db: AsyncSession)#

The get_all_images function returns a list of all images in the database.

Parameters:
  • limit – int: Limit the number of images returned

  • offset – int: Specify the number of records to skip

  • db – AsyncSession: Pass in the database session

Returns:

A list of all images in the database

Doc-author:

Trelent

async src.repository.images.get_image(image_id: int, db: AsyncSession, user: User)#
The get_image function takes in an image_id and a user, and returns the image with that id if it exists.

If no such image exists, None is returned.

Parameters:
  • image_id – int: Specify the image id of the image we want to retrieve

  • db – AsyncSession: Pass the database session to the function

  • user – User: Get the user from the database

Returns:

An image object, which is the result of a sqlalchemy query

Doc-author:

Trelent

async src.repository.images.get_images(limit: int, offset: int, db: AsyncSession, user: User)#

The get_images function returns a list of images for the user.

Parameters:
  • limit – int: Limit the number of images returned

  • offset – int: Specify the number of images to skip

  • db – AsyncSession: Pass the database connection to the function

  • user – User: Filter the images by user

Returns:

A list of images for the user

Doc-author:

Trelent

async src.repository.images.get_others_image(image_id: int, db: AsyncSession, user: User)#
The get_others_image function takes in an image_id and a user, and returns the image with that id if it exists.

If no such image exists, None is returned.

Parameters:
  • image_id – int: Specify the image id of the image we want to retrieve

  • db – AsyncSession: Pass the database session to the function

  • user – User: Get the user from the database

Returns:

An image object, which is the result of a sqlalchemy query

Doc-author:

Trelent

src.repository.images.is_object_added(session: AsyncSession, obj)#

The is_object_added function checks if an object is already added to the session.

Parameters:
  • session – AsyncSession: Pass in the session object

  • obj – Check if the object is added to the session

Returns:

True if the object is added to the session, false otherwise

Doc-author:

Trelent

async src.repository.images.update_image(image_id: int, body: ImageUpdateSchema, db: AsyncSession, user: User)#

The update_image function updates the description of an image.

Parameters:
  • image_id – int: Specify the id of the image to be updated

  • body – ImageUpdateSchema: Validate the request body

  • db – AsyncSession: Pass the database session to the function

  • user:User – Ensure that the user is only able to update their own images

Returns:

A single image

Doc-author:

Trelent

ATLANTICPHOTO repository Tags#

async src.repository.tags.create_tag(body: str, db: AsyncSession, user: User) Tag#

The create_tag function creates a new tag in the database.

Parameters:
  • body – str: Validate the request body

  • db – AsyncSession: Pass the database session to the function

  • user – User: Get the user that created the tag

Returns:

A tag object

Doc-author:

Trelent

async src.repository.tags.get_tag(tag_id: int, db: AsyncSession, user: User)#

The get_tag function returns a single tag from the database.

Parameters:
  • tag_id – int: Specify the tag id

  • db – AsyncSession: Pass the database connection to the function

  • user – User: Specify the user who created the tag

Returns:

A single tag from the database

Doc-author:

Trelent

async src.repository.tags.get_tag_by_name(db: AsyncSession, name)#

The get_tag_by_name function returns a tag object from the database.

Parameters:
  • db – AsyncSession: Pass the database session to the function

  • name – Filter the tag by name

Returns:

A tag object from the database

Doc-author:

Trelent

async src.repository.tags.remove_tag(tag_id: int, db: AsyncSession, user: User) None#

The remove_tag function removes a tag from the database.

Parameters:
  • tag_id – int: Get the tag with that id from the database

  • db – AsyncSession: Pass the database connection to the function

  • user – User: Make sure that a user can only delete their own tags

Returns:

The tag object that was deleted

Doc-author:

Trelent

ATLANTICPHOTO repository Users#

async src.repository.users.confirmed_email(email: str, db: AsyncSession) None#

The confirmed_email function takes an email address and a database connection, and marks the user with that email as confirmed. It does not return anything.

Parameters:
  • email – str: Specify the email of the user to be confirmed

  • db – AsyncSession: Pass the database connection to the function

Returns:

None

Doc-author:

Trelent

async src.repository.users.create_user(body: UserSchema, db: AsyncSession = Depends(get_db))#

The create_user function creates a new user in the database.

Parameters:
  • body – UserSchema: Validate the incoming request body

  • db – AsyncSession: Pass in the database session

Returns:

A user object

Doc-author:

Trelent

async src.repository.users.delete_access_token(email: str, db: AsyncSession) None#

The delete_access_token function is used to delete the access token of a user. This function is called when a user logs out, or if an admin wants to logout another user.

Parameters:
  • email – str: Specify the email of the user

  • db – AsyncSession: Pass the database connection to the function

Returns:

None

Doc-author:

Trelent

async src.repository.users.get_picture_count(db: AsyncSession, user: User)#

The get_picture_count function retrieves the count of pictures associated with a user and updates the user instance.

Parameters:
  • db – AsyncSession: Inject the database session into the function

  • user – User: Pass the user instance to the function

Returns:

None

Doc-author:

Trelent

async src.repository.users.get_user_by_email(email: str, db: AsyncSession = Depends(get_db))#

The get_user_by_email function takes an email address and returns the user object associated with that email. If no such user exists, it returns None.

Parameters:
  • email – str: Pass the email of the user to be retrieved

  • db – AsyncSession: Pass the database session to the function

Returns:

The user object associated with the email address passed to it

Doc-author:

Trelent

async src.repository.users.update_avatar_url(email: str, url: str | None, db: AsyncSession) User#

The update_avatar_url function updates the avatar URL for a user.

Parameters:
  • email – str: Get the user from the database

  • url – str | None: Specify that the url parameter is either a string or none

  • db – AsyncSession: Pass the database session into the function

Returns:

A user object, which is the updated user

Doc-author:

Trelent

async src.repository.users.update_token(user: User, token: str | None, db: AsyncSession)#

The update_token function updates the refresh token for a user.

Parameters:
  • user – User: Specify the user object that will be updated

  • token – str | None: Update the user’s refresh token

  • db – AsyncSession: Pass the database session to the function

Returns:

The user object

Doc-author:

Trelent

ATLANTICPHOTO repository Transform#

class src.repository.transform.TransformClass(session: AsyncSession)#

Bases: object

check_access(pic_id: int, user: User, needed_class)#
The check_access function checks if the user has access to a certain picture.

It takes in three arguments: pic_id, user and needed_class. The pic_id is the id of the picture that we want to check access for. The user is an object of type User which contains information about who wants to see this image (the current logged-in user). And finally, needed class can be either Image or TransformedPic depending on what kind of image we are checking access for.

Parameters:
  • self – Represent the instance of a class

  • pic_id – int: Get the picture by id

  • user – User: Get the user id and role

  • needed_class – Check if the user is trying to access an original picture or a transformed one

Returns:

True or raises an exception

Doc-author:

Trelent

create_transformed_pic(user_id: int, original_pic_id: str, transformations: dict)#
The create_transformed_pic function creates a transformed picture from an original picture.
Args:

user_id (int): The id of the user who is creating the transformed pic. original_pic_id (str): The id of the original pic that will be used to create a new transformed pic. transformations (dict): A dictionary containing all transformation parameters for Cloudinary’s upload API call, including image format and crop mode.

Parameters:
  • self – Bind the method to an object

  • user_id – int: Identify the user who uploaded the picture

  • original_pic_id – str: Get the original picture from the database

  • transformations – dict: Pass in the transformations that will be applied to the image

Returns:

A transformed_pic object, which is an instance of the transformedpic class

Doc-author:

Trelent

delete_trans_pic(transformed_pic_id: int)#
The delete_trans_pic function deletes a transformed picture from the database and cloud storage.
Args:

transformed_pic_id (int): The id of the transformed picture to be deleted.

Returns:

str: A string indicating that the deletion was successful or not.

Parameters:
  • self – Represent the instance of the class

  • transformed_pic_id – int: Find the picture in the database by its id

Returns:

A string

Doc-author:

Trelent

generate_qr_code_for_trans(trans_pic_id)#
The generate_qr_code_for_trans function generates a QR-code for the given transaction picture.

The function takes in an integer representing the id of a transaction picture and returns an image object containing the generated QR-code.

Parameters:
  • self – Represent the instance of the class

  • trans_pic_id – Get the image from the database

Returns:

The qr_image

Doc-author:

Trelent

get_original_pic_by_id(needed_pic_id: int)#

The get_original_pic_by_id function takes in a picture id and returns the original image object.

Parameters:
  • self – Represent the instance of a class

  • needed_pic_id – int: Get the picture id from the database

Returns:

An object of the image class

Doc-author:

Trelent

async get_trans_pic_by_id(needed_pic_id: int)#
The get_trans_pic_by_id function takes in a needed_pic_id and returns the TransformedPic object with that id.

If no such TransformedPic exists, it returns None.

Parameters:
  • self – Represent the instance of a class

  • needed_pic_id – int: Specify the id of the picture that is needed

Returns:

A transformedpic object, which is a row in the database

Doc-author:

Trelent

get_users_transformed_pic(user_id: int)#

The get_users_transformed_pic function returns a list of all the transformed pictures for a given user.

Parameters:
  • self – Represent the instance of a class

  • user_id – int: Get the user_id of the user that is currently logged in

Returns:

A list of transformed pictures for a given user

Doc-author:

Trelent

update_transformed_pic(transformed_pic_id: int, transformations: dict)#
The update_transformed_pic function updates the transformed picture in the database.
Args:

self (object): The object that is calling this function. transformed_pic_id (int): The id of the picture to be updated. transformations (dict): A dictionary containing all of the transformations to be applied to

this image, as well as their values.

Parameters:
  • self – Refer to the current object

  • transformed_pic_id – int: Identify the transformed picture that needs to be updated

  • transformations – dict: Pass in a dictionary of transformations that will be applied to the image

Returns:

The transformed_pic object

Doc-author:

Trelent

ATLANTICPHOTO repository Comments#

async src.repository.comments.create_comment(body: CommentCreate, db: AsyncSession, existing_image: int, user: User) CommentResponse#

The create_comment function creates a new comment in the database.

Parameters:
  • body – CommentCreate: Pass the comment data to the function

  • db – AsyncSession: Pass the database connection to the function

  • existing_image – int: Pass the id of the image for which a comment is being created

  • user – User: Get the user id of the user who is creating a comment

Returns:

The created comment object

Doc-author:

Trelent

async src.repository.comments.delete_comment(db: AsyncSession, comment_id: int, user_role: Role) None#

The delete_comment function deletes a comment from the database.

Parameters:
  • db – AsyncSession: Pass the database connection to the function

  • comment_id – int: Specify the id of the comment to be deleted

  • user_role – Role: Check if the user has permission to delete a comment

Returns:

The deleted comment object if successful, none otherwise

Doc-author:

Trelent

async src.repository.comments.update_comment(db: AsyncSession, comment_id: int, user_id: int, content: CommentCreate) CommentResponse#

The update_comment function updates an existing comment in the database.

Parameters:
  • db – AsyncSession: Pass the database connection to the function

  • comment_id – int: Identify the comment to be updated

  • user_id – int: Ensure that the user who created the comment is the one updating it

  • content – CommentCreate: Pass the new content of the comment to be updated

Returns:

A comment object if the update was successful

Doc-author:

Trelent

ATLANTICPHOTO routes Images#

async src.routes.images.create_image(file: UploadFile = File(PydanticUndefined), body: ImageSchema = Depends(ImageSchema), db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user))#
The create_image function creates a new image in the database.

The function takes an ImageSchema object as input, and returns an ImageResponse object.

Parameters:
  • file – UploadFile: Upload a file to the cloudinary server

  • body – ImageSchema: Validate the request body

  • db – AsyncSession: Get the database session

  • current_user – User: Get the current user from the database

:param : Validate the request body :return: An imageresponse object :doc-author: Trelent

async src.routes.images.delete_image(image_id: int = Path(PydanticUndefined), db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user))#
The delete_image function deletes an image from the database.

The function takes in a Path parameter of image_id, which is the id of the image to be deleted. It also takes in a Depends parameter db, which is an AsyncSession object that allows us to access our database. Finally it takes in another Depends parameter current_user, which is a User object representing who made this request.

Parameters:
  • image_id – int: Get the image id from the path

  • db – AsyncSession: Access the database

  • current_user – User: Get the user that is currently logged in

:param : Get the image id from the path :return: A dict with the following keys: :doc-author: Trelent

async src.routes.images.get_all_images(limit: int = Query(10), offset: int = Query(0), db: AsyncSession = Depends(get_db), user: User = Depends(get_current_user))#
The get_all_images function returns a list of all images in the database.

The limit and offset parameters are used to paginate the results.

Parameters:
  • limit – int: Limit the number of images returned

  • ge – Set a minimum value for the limit parameter

  • le – Limit the number of images returned to 500

  • offset – int: Skip a number of images

  • ge – Set a minimum value for the limit parameter

  • db – AsyncSession: Access the database

  • user – User: Get the current user

:param : Paginate the results :return: A list of all images in the database :doc-author: Trelent

async src.routes.images.get_image(image_id: int = Path(PydanticUndefined), db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user))#

The get_image function returns a contact by ID.

Parameters:
  • image_id – int: Get the image id from the url

  • db – AsyncSession: Pass the database session to the function

  • current_user – User: Get the current user from the database

:param : Get the image id from the url :return: A contact by id :doc-author: Trelent

async src.routes.images.get_images(limit: int = Query(10), offset: int = Query(0), db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user))#

The get_images function returns a list of images.

Parameters:
  • limit – int: Limit the number of images returned

  • ge – Set a minimum value for the limit parameter

  • le – Limit the maximum number of images that can be returned

  • offset – int: Specify the offset of the images to be returned

  • ge – Set a minimum value for the limit parameter

  • db – AsyncSession: Get the database session

  • current_user – User: Get the current user from the database

:param : Specify the offset of the images to be returned :return: A list of images :doc-author: Trelent

async src.routes.images.update_image(body: ImageUpdateSchema, image_id: int = Path(PydanticUndefined), db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user))#
The update_image function updates an image in the database.

It takes a contact_id and body as input, and returns the updated image.

Parameters:
  • body – ImageUpdateSchema: Get the data from the request body

  • image_id – int: Specify the image id of the image that is to be updated

  • db – AsyncSession: Get the database connection

  • current_user – User: Get the current user from the auth_service

:param : Get the data from the request body :return: The updated image :doc-author: Trelent

ATLANTICPHOTO routes Tags#

async src.routes.tags.read_tag(tag_id: int, db: Session = Depends(get_db), user: User = Depends(get_current_user))#
The read_tag function returns a single tag from the database.

The function takes in an integer as its argument, which is the ID of the tag to be returned. If no such tag exists, then a 404 error is raised.

Parameters:
  • tag_id – int: Specify the id of the tag to be updated

  • db – Session: Pass the database session to the function

  • user – User: Pass the current user to the function

:param : Specify the id of the tag to be updated :return: A single tag from the database :doc-author: Trelent

async src.routes.tags.remove_tag(tag_id: int, db: Session = Depends(get_db), user: User = Depends(get_current_user))#
The remove_tag function removes a tag from the database.
Args:

tag_id (int): The id of the tag to be removed. db (Session, optional): SQLAlchemy Session. Defaults to Depends(get_db).

Parameters:
  • tag_id – int: Specify the id of the tag to be retrieved

  • db – Session: Pass the database session to the repository function

  • user – User: Get the current user from the database

:param : Specify the id of the tag to be retrieved :return: A tag object :doc-author: Trelent

ATLANTICPHOTO routes Users#

async src.routes.users.get_user_profile(email: str, db: AsyncSession = Depends(get_db))#
The get_user_profile function is used to get the user profile information.

This function will return a User object with all of the user’s information.

Parameters:
  • email – str: Get the email of the user that is logged in

  • db – AsyncSession: Pass the database session to the repository

Returns:

The user_info object, which is a user object

Doc-author:

Trelent

ATLANTICPHOTO routes Auth#

async src.routes.auth.login(body: OAuth2PasswordRequestForm = Depends(OAuth2PasswordRequestForm), db: AsyncSession = Depends(get_db))#
The login function is used to authenticate a user.

It takes in the email and password of the user, verifies that they are correct, and then returns an access token for future requests.

Parameters:
  • body – OAuth2PasswordRequestForm: Get the username and password from the request body

  • db – AsyncSession: Pass the database session to the function

Returns:

A dictionary with the access token, refresh token and the type of token

Doc-author:

Trelent

async src.routes.auth.logout(credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer), db: AsyncSession = Depends(get_db))#
The logout function is used to logout a user.

It takes in the refresh token as an authorization header and deletes it from the database. The function returns a message indicating that the user has been logged out successfully.

Parameters:
  • credentials – HTTPAuthorizationCredentials: Get the refresh token from the header

  • db – AsyncSession: Get the database session

:param : Get the user’s email from the token :return: The following: :doc-author: Trelent

async src.routes.auth.refresh_token(credentials: HTTPAuthorizationCredentials = Depends(HTTPBearer), db: AsyncSession = Depends(get_db))#
The refresh_token function is used to refresh the access token.

The function takes in a refresh token and returns an access_token, a new refresh_token, and the type of token (bearer).

Parameters:
  • credentials – HTTPAuthorizationCredentials: Get the access token from the header

  • db – AsyncSession: Get the database session

:param : Get the access token from the header :return: The following: :doc-author: Trelent

async src.routes.auth.signup(body: UserSchema, bt: BackgroundTasks, request: Request, db: AsyncSession = Depends(get_db))#
The signup function creates a new user in the database.

It takes a UserSchema object as input, and returns the newly created user. If an account with that email already exists, it raises an HTTPException.

Parameters:
  • body – UserSchema: Validate the request body

  • bt – BackgroundTasks: Add a task to the background queue

  • request – Request: Get the base_url of the application

  • db – AsyncSession: Pass the database session to the function

:param : Validate the request body :return: A user object :doc-author: Trelent

ATLANTICPHOTO routes Transform#

async src.routes.transform.create_transformed_pic(request: TransSchema, original_image_id: int, user: User = Depends(get_current_user), session: AsyncSession = Depends(get_db))#
The create_transformed_pic function is used to create a transformed picture.

It takes in the original image id, and the transformations that are desired. The user must be logged in to use this function.

Parameters:
  • request – TransSchema: Get the transformation parameters from the request

  • original_image_id – int: Get the original image from the database

  • user – User: Get the user id of the current user

  • session – AsyncSession: Get the database session, which is used to interact with the database

:param : Get the image id from the url :return: The transformed image :doc-author: Trelent

Available transformation params: - width: The width of the transformed image. 100-1920. - height: The height of the transformed image. 100-1080. - crop: The crop mode. fill, limit, scale, thumb, fit, crop - effect: grayscale, sepia, cartoonify, blur, brightness, contrast, saturation, sharpen - border: 1px_solid_black, 1px_solid_red, 2px_dashed_blue - angle: 0-360

async src.routes.transform.delete_transformed(transformed_pic_id: int, user: User = Depends(get_current_user), session: AsyncSession = Depends(get_db))#
The delete_transformed function deletes a transformed image from the database.

It takes in an integer representing the id of the transformed image to be deleted, and returns a JSON object with one key: "message", which contains a string describing what happened.

Parameters:
  • transformed_pic_id – int: Identify the image to be deleted

  • user – User: Check if the user is authenticated

  • session – AsyncSession: Pass the database session to the handler

:param : Pass the transformed_pic_id to the function :return: A boolean value :doc-author: Trelent

async src.routes.transform.get_transformed_pic(transformed_pic_id: int, user: User = Depends(get_current_user), session: AsyncSession = Depends(get_db))#
The get_transformed_pic function returns a transformed picture by its id.

The function checks if the user has access to the picture and then returns it.

Parameters:
  • transformed_pic_id – int: Identify the transformed picture in the database

  • user – User: Check if the user has access to the transformed picture

  • session – AsyncSession: Pass the database session to the handler

:param : Get the transformed picture by id :return: A transformed picture :doc-author: Trelent

async src.routes.transform.show_qr_code(transformed_pic_id: int, user: User = Depends(get_current_user), session: AsyncSession = Depends(get_db))#
The show_qr_code function is used to generate a QR code for the transformed picture.

The function takes in the transformed_pic_id and user as parameters, and returns a response object containing the generated QR code image.

Parameters:
  • transformed_pic_id – int: Get the transformed picture from the database

  • user – User: Get the user that is currently logged in

  • session – AsyncSession: Pass the database session to the function

:param : Get the id of the transformed picture :return: A response object :doc-author: Trelent

async src.routes.transform.show_users_transforms(user: User = Depends(get_current_user), session: AsyncSession = Depends(get_db))#
The show_users_transforms function returns a list of all the pictures that have been transformed by the user.
Args:

user (User): The current logged in User object. session (AsyncSession): The database connection to use for this request.

Parameters:
  • user – User: Get the user id from the token

  • session – AsyncSession: Get the database connection

:param : Get the current user from the database :return: A list of dictionaries :doc-author: Trelent

async src.routes.transform.update_transformed_pic(request: TransSchema, transformed_pic_id: int, user: User = Depends(get_current_user), session: AsyncSession = Depends(get_db))#
The update_transformed_pic function updates a transformed picture in the database.

It takes an id of the image to be updated, and a request body containing all fields that need updating. The function returns the updated image object.

Parameters:
  • request – TransSchema: Get the data from the request body

  • transformed_pic_id – int: Identify the transformed image in the database

  • user – User: Check if the user is logged in

  • session – AsyncSession: Pass the database session to the handler

:param : Get the id of the transformed image :return: The result of the handler :doc-author: Trelent

ATLANTICPHOTO routes Comments#

async src.routes.comments.create_comment(body: CommentCreate, image_id: int, db: AsyncSession = Depends(get_db), user: User = Depends(get_current_user))#

The create_comment function creates a new comment.

Parameters:
  • body – CommentCreate: Pass the comment data to the function

  • image_id – int: Get the image id from the url

  • db – AsyncSession: Pass the database session to the repository layer

  • user – User: Get the current user

:param : Get the image id from the url :return: A comment object :doc-author: Trelent

async src.routes.comments.delete_comment(comment_id: int, db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user))#
The delete_comment function deletes a comment from the database.

The function takes in an integer representing the id of the comment to be deleted, and returns a dictionary containing information about whether or not deletion was successful.

Parameters:
  • comment_id – int: Specify the comment id of the comment to be deleted

  • db – AsyncSession: Pass the database session to the function

  • current_user – User: Get the current user and check if they are an admin or not

:param : Get the comment id from the url :return: A comment object :doc-author: Trelent

async src.routes.comments.update_comment(comment_id: int, body: CommentCreate, db: AsyncSession = Depends(get_db), current_user: User = Depends(get_current_user))#

The update_comment function updates a comment in the database.

Parameters:
  • comment_id – int: Identify the comment to be updated

  • body – CommentCreate: Pass the new comment content to the update_comment function

  • db – AsyncSession: Pass the database session to the function

  • current_user – User: Get the current user

:param : Get the comment id from the url :return: The updated comment :doc-author: Trelent

ATLANTICPHOTO service Auth#

class src.services.auth.Auth#

Bases: object

ALGORITHM = 'HS256'#
SECRET_KEY = '1234567890'#
cache = Redis<ConnectionPool<Connection<host=redis,port=6379,db=0>>>#
async create_access_token(data: dict, expires_delta: float | None = None)#
The create_access_token function creates a new access token for the user.

The function takes in two parameters: data and expires_delta. Data is a dictionary that contains information about the user, such as their username and email address. Expires_delta is an optional parameter that specifies how long the access token will be valid for.

Parameters:
  • self – Access the class variables

  • data – dict: Store the data that will be encoded in the access token

  • expires_delta – Optional[float]: Set the expiration time of the token

Returns:

A jwt token that is encoded with the data provided and a secret key

Doc-author:

Trelent

async create_refresh_token(data: dict, expires_delta: float | None = None)#
The create_refresh_token function creates a refresh token for the user.

The function takes in two parameters: data and expires_delta. Data is a dictionary containing the user’s id, username, email address, and password hash. Expires_delta is an optional parameter that sets how long before the refresh token expires.

Parameters:
  • self – Represent the instance of the class

  • data – dict: Pass the user’s data to be encoded

  • expires_delta – Optional[float]: Set how long the refresh token will last

Returns:

The encoded refresh token

Doc-author:

Trelent

async decode_refresh_token(refresh_token: str)#
The decode_refresh_token function is used to decode the refresh token.

The function takes in a refresh_token as an argument and returns the email of the user if successful. If unsuccessful, it raises an HTTPException with status code 401 (Unauthorized) and detail message ‘Invalid scope for token’ or ‘Could not validate credentials’.

Parameters:
  • self – Represent the instance of the class

  • refresh_token – str: Pass in the refresh token that is sent to the server

Returns:

The email of the user who is trying to refresh their access token

Doc-author:

Trelent

async get_current_user(token: str = Depends(OAuth2PasswordBearer), db: AsyncSession = Depends(get_db))#
The get_current_user function is a dependency that will be used in the

get_current_active_user endpoint. It takes in a token and db session, decodes the JWT, checks if it’s an access token or refresh token, then returns the user object from cache or database.

Parameters:
  • self – Access the class attributes

  • token – str: Get the token from the header

  • db – AsyncSession: Get the database session

Returns:

The user object which is then used to check if the user has access to a certain route

Doc-author:

Trelent

get_password_hash(password: str)#

The get_password_hash function takes a password and returns the hashed version of it. The hashing algorithm is defined in the config file, which is imported into this module.

Parameters:
  • self – Represent the instance of the class

  • password – str: Pass in the password that is being hashed

Returns:

A hash of the password

Doc-author:

Trelent

oauth2_scheme = <fastapi.security.oauth2.OAuth2PasswordBearer object>#
pwd_context = <CryptContext>#
verify_password(plain_password, hashed_password)#

The verify_password function is used to verify a plain-text password against a hashed password. The function returns True if the passwords match, and False otherwise.

Parameters:
  • self – Represent the instance of the class

  • plain_password – Pass in the password that was entered by the user

  • hashed_password – Store the hashed password from the database

Returns:

A boolean value, true if the passwords match and false otherwise

Doc-author:

Trelent

ATLANTICPHOTO service Cloudconnect#

class src.services.cloudconnect.CloudConnect#

Bases: object

static delete_pic(pic_public_id: str)#
The delete_pic function deletes a picture from the cloudinary database.
Args:

pic_public_id (str): The public id of the picture to be deleted.

Parameters:

pic_public_id – str: Specify the public id of the picture that is to be deleted

Returns:

The response from the destroy method

Doc-author:

Trelent

static update_pic(public_id: int, transformations: dict)#

The update_pic function takes a public_id and transformations dict as arguments. The function then calls the Cloudinary API to update the image with the given public_id, using the transformations provided in the transformations dict. The function returns a url for the new image.

Parameters:
  • public_id – int: Specify the public id of the image to be updated

  • transformations – dict: Apply transformations to the image

Returns:

A url for the updated image

Doc-author:

Trelent

static upload_pic(user_id: int, image: UploadFile, folder: str = None)#

The upload_pic function uploads an image to Cloudinary and returns the url of the uploaded image.

Parameters:
  • user_id – int: Create a folder for the user to store their images in

  • image – UploadFile: Upload the image to cloudinary

  • folder – str: Create a folder for the user

Returns:

The url and public_id of the uploaded image

Doc-author:

Trelent

static upload_transformed_pic(user_id: int, original_url: str, transformations: dict, folder: str = None)#

The upload_transformed_pic function takes in a user_id, an original_url, transformations and a folder. It then creates the folder for the transformed images to be stored in. It then uploads the image with the given transformations to that folder and returns its url and public id.

Parameters:
  • user_id – int: Create a folder for the user

  • original_url – str: Specify the url of the image that is going to be transformed

  • transformations – dict: Specify the transformations we want to apply to the image

  • folder – str: Create a folder in the cloudinary account to store the transformed images

Returns:

The url and public_id of the transformed image

Doc-author:

Trelent

src.services.cloudconnect.create_folder(user_id: int, related_path: str, folder: str = None)#
The create_folder function creates a folder in the user’s Google Drive account.
Args:

user_id (int): The ID of the user whose Google Drive account will be used to create a folder. related_path (str): A string representing the path to which this new folder will be created relative to

AtlanticPhoto/user_{user_id}. For example, if you want your new folder created at AtlanticPhoto/user_{user_id}/photos, then related_path should equal &quot;photos&quot;. If you want your new folder created at AtlanticPhoto/user_{

Parameters:
  • user_id – int: Specify the user for whom a folder will be created

  • related_path – str: Create a folder path

  • folder – str: Specify the name of a folder that will be created

Returns:

A string

Doc-author:

Trelent

src.services.cloudconnect.input_error(func)#

The input_error function is a decorator that catches any exceptions thrown by the decorated function and raises an HTTPException with a status code of 500.

Parameters:

func – Pass in a function to the decorator

Returns:

A function

Doc-author:

Trelent

ATLANTICPHOTO service Roles#

class src.services.roles.RoleAccess(allowed_roles: list[Role])#

Bases: object

Indices and tables#