Skip to content

Commit

Permalink
Update commentController.py
Browse files Browse the repository at this point in the history
  • Loading branch information
victorleaoo authored Jul 22, 2024
1 parent a0798f1 commit cd7967c
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions src/controller/commentController.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
from fastapi import APIRouter, HTTPException, Response, status, Depends
from database import get_db
from sqlalchemy.orm import Session
# from fastapi import APIRouter, HTTPException, Response, status, Depends
# from database import get_db
# from sqlalchemy.orm import Session

from domain import commentSchema
from repository import commentRepository
from constants import errorMessages
# from domain import commentSchema
# from repository import commentRepository
# from constants import errorMessages

comment = APIRouter(
prefix="/comments"
)
# comment = APIRouter(
# prefix="/comments"
# )

@comment.get("/{video_id}", response_model=list[commentSchema.Comment])
def read_comment(video_id: int, db: Session = Depends(get_db)):
comment = commentRepository.get_comments_by_video_id(db, video_id=video_id)
return comment
# @comment.get("/{video_id}", response_model=list[commentSchema.Comment])
# def read_comment(video_id: int, db: Session = Depends(get_db)):
# comment = commentRepository.get_comments_by_video_id(db, video_id=video_id)
# return comment

@comment.post("/", response_model=commentSchema.Comment)
def create_comment(comment: commentSchema.CommentCreate, db: Session = Depends(get_db)):
return commentRepository.create_comment(db=db, video_id=comment.video_id, user_id=comment.user_id, user_name= comment.user_name ,content=comment.content)
# @comment.post("/", response_model=commentSchema.Comment)
# def create_comment(comment: commentSchema.CommentCreate, db: Session = Depends(get_db)):
# return commentRepository.create_comment(db=db, video_id=comment.video_id, user_id=comment.user_id, user_name= comment.user_name ,content=comment.content)

@comment.delete("/{id}", response_model=commentSchema.Comment)
def delete_comment(id: int, db: Session = Depends(get_db)):
comment = commentRepository.get_comment_by_id(db, id)
if not comment:
raise HTTPException(status_code=404, detail=errorMessages.COMMENT_NOT_FOUND)
commentRepository.delete_comment(db,comment)
return comment
# @comment.delete("/{id}", response_model=commentSchema.Comment)
# def delete_comment(id: int, db: Session = Depends(get_db)):
# comment = commentRepository.get_comment_by_id(db, id)
# if not comment:
# raise HTTPException(status_code=404, detail=errorMessages.COMMENT_NOT_FOUND)
# commentRepository.delete_comment(db,comment)
# return comment

@comment.patch("/{id}", response_model=commentSchema.Comment)
def update_comment(id: int, data: commentSchema.CommentUpdate,db: Session = Depends(get_db)):
comment = commentRepository.get_comment_by_id(db, id)
if not comment:
raise HTTPException(status_code=404, detail=errorMessages.COMMENT_NOT_FOUND)
updated_comment = commentRepository.update_comment(db,comment,data)
return updated_comment
# @comment.patch("/{id}", response_model=commentSchema.Comment)
# def update_comment(id: int, data: commentSchema.CommentUpdate,db: Session = Depends(get_db)):
# comment = commentRepository.get_comment_by_id(db, id)
# if not comment:
# raise HTTPException(status_code=404, detail=errorMessages.COMMENT_NOT_FOUND)
# updated_comment = commentRepository.update_comment(db,comment,data)
# return updated_comment

0 comments on commit cd7967c

Please sign in to comment.