Add POST endpoint for /projects

This commit is contained in:
Backend IM Bot 2025-03-27 18:04:48 +00:00
parent 808de0bdd8
commit 044aea353a

View File

@ -1,19 +1,26 @@
# Entity: Project
# Entity: Migration
```python
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from core.database import get_db
from models.project import Project
from schemas.project import ProjectSchema, ProjectCreate
from helpers.project_helpers import create_project
from models.migration import Migration
from schemas.migration import MigrationSchema, MigrationFix
from helpers.migration_helpers import fix_migration
router = APIRouter()
@router.post("/projects", status_code=status.HTTP_201_CREATED, response_model=ProjectSchema)
async def add_project(
project: ProjectCreate,
@router.post("/migrations/fix", status_code=200, response_model=MigrationSchema)
async def fix_migration_endpoint(
migration_data: MigrationFix,
db: Session = Depends(get_db)
):
"""Add a new final year project"""
new_project = create_project(db=db, project=project)
return new_project
"""Fix a database migration"""
fixed_migration = fix_migration(db, migration_data)
if not fixed_migration:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail="Failed to fix migration"
)
return fixed_migration
```