diff --git a/endpoints/movieapp.post.py b/endpoints/movieapp.post.py index e69de29..cbb16f1 100644 --- a/endpoints/movieapp.post.py +++ b/endpoints/movieapp.post.py @@ -0,0 +1,12 @@ +from fastapi import APIRouter, HTTPException +from helpers.movie_helpers import create_movie + +router = APIRouter() + +@router.post("/movieapp", status_code=201) +async def create_new_movie(movie_data: dict): + try: + new_movie = create_movie(movie_data) + return new_movie + except Exception as e: + raise HTTPException(status_code=400, detail=str(e)) \ No newline at end of file diff --git a/helpers/generic_helpers.py b/helpers/generic_helpers.py new file mode 100644 index 0000000..ba6b4b7 --- /dev/null +++ b/helpers/generic_helpers.py @@ -0,0 +1,25 @@ +from typing import Optional + +def fix_invalid_syntax_error(error_message: str) -> Optional[str]: + """ + Attempts to fix an invalid syntax error by removing the offending line. + + Args: + error_message (str): The error message containing the invalid syntax error. + + Returns: + Optional[str]: The modified code with the offending line removed, or None if the error message + does not contain a valid line number and code snippet. + """ + # Check if the error message follows the expected format + if "Code snippet near error:" in error_message: + lines = error_message.split("\n") + for i, line in enumerate(lines): + if line.startswith("Code snippet near error:"): + code_line_number = int(lines[i - 1].split(":")[0]) + code_snippet = "\n".join(lines[i + 1:]) + code_lines = code_snippet.split("\n") + if code_line_number <= len(code_lines): + modified_code = "\n".join(code_lines[:code_line_number - 1] + code_lines[code_line_number:]) + return modified_code + return None \ No newline at end of file