From 6bba146eb287e98a15c52b7cde2b133beb1734db Mon Sep 17 00:00:00 2001 From: Will Astilla <77816687+wastilla@users.noreply.github.com> Date: Sun, 16 Apr 2023 15:12:25 -0400 Subject: [PATCH] Add documentation to post service class and methods (#52) --- backend/api/post.py | 11 +++++++++++ backend/api/user.py | 4 ++++ backend/entities/post_entity.py | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/api/post.py b/backend/api/post.py index b16f64a..077b72c 100644 --- a/backend/api/post.py +++ b/backend/api/post.py @@ -1,3 +1,7 @@ +"""Post API + +This API is used to create, retrieve, and delete posts for CSXL forum page""" + from fastapi import APIRouter, Depends, HTTPException from ..services import PostService, UserService from ..models import Post @@ -8,6 +12,10 @@ @api.post("", response_model=Post, tags=['Post']) def create(post: Post, post_svc: PostService = Depends(), usr_svc: UserService = Depends()): + """Create a new post + If post author is not registered in CSXL User database, throw 422 Error + Verify author is registered by calling findUser method form UserService""" + try: user_entity = usr_svc.findUser(post.user) except: @@ -16,10 +24,13 @@ def create(post: Post, post_svc: PostService = Depends(), usr_svc: UserService = @api.get("", response_model=list[Post], tags=['Post']) def getAll(post_svc: PostService = Depends()): + """Retrieve all forum posts to be displayed in viewForum""" return post_svc.getAll() @api.delete("/{id}", tags=['Post']) def delete(id: int, post_svc: PostService = Depends()) -> bool: + """Delete a specific forum post from database by id + If post with associated id does not exist, throw 422 error""" try: return post_svc.delete(id=id) except: diff --git a/backend/api/user.py b/backend/api/user.py index 8248aa4..3fba7ce 100644 --- a/backend/api/user.py +++ b/backend/api/user.py @@ -1,3 +1,7 @@ +"""User API + +This API is used to create, retrieve, and delete posts for CSXL forum page""" + from fastapi import APIRouter, Depends from ..services import UserService from ..models import User diff --git a/backend/entities/post_entity.py b/backend/entities/post_entity.py index 220cccb..ae1eca0 100644 --- a/backend/entities/post_entity.py +++ b/backend/entities/post_entity.py @@ -1,4 +1,4 @@ -'''User accounts for all registered users in the application.''' +'''Entity for all Posts in application''' from sqlalchemy import Integer, String, ForeignKey, Text