App

class app.App[source]

Bases: object

Manages al the app functions.

static create_post(name: str, location: str, review: str, rating: float, imageUrl: str, creator: Dict[str, Any]) str[source]

Creates a new post.

Parameters:
  • name (str) – The new post’s name.

  • location (str) – The new post’s location.

  • review (str) – The new post’s review.

  • rating (float) – The new post’s rating.

  • imageUrl (str) – The new post’s imageUrl.

  • creator (Dict[str, Any]) – The new post’s creator.

Raises:
  • ValueError – If the rating isn’t valid.

  • ValueError – If the imange isn’t valid.

  • GeneralError – General errors.

Returns:

The created post’s ID.

Return type:

str

static delete_comment(post_id: str, comment_id: str, request_user: Dict[str, Any]) bool[source]

Delete a comment.

Parameters:
  • post_id (str) – Post’s ID.

  • comment_id (str) – Comment’s ID.

  • request_user (Dict[str, Any]) – User that makes the request.

Raises:
Returns:

True if the comment was deleted.

Return type:

bool

static delete_post(post_id: str, request_user: Dict[str, Any]) bool[source]

Delete a post.

Parameters:
  • post_id (str) – Post’s ID.

  • request_user (Dict[str, Any]) – User that makes the request.

Raises:
Returns:

True if was deleted.

Return type:

bool

static edit_post(post_id: str, name: str, location: str, review: str, rating: float, imageUrl: str, request_user: Dict[str, Any]) bool[source]

Edit a post.

Parameters:
  • post_id (str) – Edited post’s ID.

  • name (str) – Edited post’s name.

  • location (str) – Edited post’s location.

  • review (str) – Edited post’s review.

  • rating (float) – Edited post’s rating.

  • imageUrl (str) – Edited post’s imageUrl.

  • request_user (Dict[str, Any]) – User that makes the request..

Raises:
  • ValueError – If the rating isn’t valid.

  • ValueError – If the imange isn’t valid.

  • Unauthorized – If the request user isn’t is authorized to edit.

  • NotFound – If post isn’t founded.

  • GeneralError – General error.

Returns:

True id was edited.

Return type:

bool

static follownt(following_username: str, request_user: Dict[str, Any]) bool[source]

Follows or unfollows an user.

Parameters:
  • following_username (str) – User’s username that will be followed or unfollowed.

  • request_user (Dict[str, Any]) – User that makes the request.

Raises:
Returns:

True if the operation was sucessfull.

Return type:

bool

static get_post(post_id: str, request_user: Dict[str, Any]) Dict[str, Any][source]

Fetch an specific post,

Parameters:
  • post_id (str) – The post’s ID.

  • request_user (Dict[str, Any]) – The user that makes the request.

Raises:
Returns:

The post data.

Return type:

Dict[str, Any]

static get_posts(request_user: Dict[str, Any]) List[Dict[str, Any]][source]

Fetch all posts.

Parameters:

request_user (Dict[str, Any]) – User that makes the request.

Raises:

GeneralError – General errors.

Returns:

All posts.

Return type:

List[Dict[str, Any]]

static get_user(username: str, request_user: Dict[str, Any]) Dict[str, Any][source]

Fetch an user.

Parameters:
  • username (str) – The user’s username to fetch.

  • request_user (Dict[str, Any]) – The user that makes the request.

Raises:
Returns:

The fetched user data.

Return type:

Dict[str, Any]

static login(username_or_email: str, password: str) Dict[str, Any][source]

Log an user into the app.

Parameters:
  • username_or_email (str) – User’s username or email.

  • password (str) – User’s password.

Raises:
Returns:

The username and the token in a dict: {“username”: username, “token”: token}.

Return type:

Dict[str, Any]

static new_comment(post_id: str, content: str, rating: int, request_user: Dict[str, Any]) bool[source]

Makes a new comment.

Parameters:
  • post_id (str) – Post’s ID.

  • content (str) – Comment content.

  • rating (int) – Comment rating.

  • request_user (Dict[str, Any]) – User that makes the request.

Raises:
  • ValueError – If the comment rating isn’t valid.

  • NotFound – If post isn’t found.

  • GeneralError – General errors.

Returns:

True if the comment was added.

Return type:

bool

static register(username: str, email: str, password: str) Dict[str, Any][source]

Register a user into the app.

Parameters:
  • username (str) – The new’s user username.

  • email (str) – The new’s user email.

  • password (str) – The new’s user password.

Raises:
Returns:

The username and the token in a dict: {“username”: username, “token”: token}.

Return type:

Dict[str, Any]

static verify_token(request_token: str) Dict[str, Any][source]

Verify a JWT.

Parameters:

request_token (str) – The token to verify

Raises:

GeneralError – General error

Returns:

{“verify”: True, “user”: (token info)} or {“verify”: False, “error”: (error)}

Return type:

Dict[str, Any]