Skip to content

Commit

Permalink
Add documentation to post service class and methods (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
wastilla authored Apr 16, 2023
1 parent b3f6d5b commit 6bba146
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions backend/api/post.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions backend/api/user.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend/entities/post_entity.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6bba146

Please sign in to comment.