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