81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
from ninja import NinjaAPI
|
|
from submissions.api import router as submissions_router
|
|
from submissions.schemas import UserInfoOut
|
|
from animations.api import router as results_router
|
|
|
|
# Create the main API instance
|
|
api = NinjaAPI(
|
|
title="Opus Magnum Submission API",
|
|
version="1.0.0",
|
|
description="""API for managing Opus Magnum puzzle submissions.
|
|
|
|
The Opus Magnum Submission API allows clients to upload, manage, validate, and review puzzle solution submissions for the Opus Magnum puzzle game community.
|
|
It provides features for user authentication, puzzle listing, submission uploads, automated and manual OCR validation, and administrative workflows.
|
|
""",
|
|
openapi_extra={
|
|
"info": {
|
|
"contact": {
|
|
"name": "Legrems",
|
|
"email": "loic.gremaud@polylan.ch",
|
|
},
|
|
}
|
|
},
|
|
)
|
|
|
|
# Add authentication for protected endpoints
|
|
# api.auth = django_auth # Uncomment if you want global auth
|
|
|
|
# Include the submissions router
|
|
api.add_router("/submissions/", submissions_router, tags=["submissions"])
|
|
api.add_router("/results/", results_router, tags=["results"])
|
|
|
|
|
|
# Health check endpoint
|
|
@api.get("/health")
|
|
def health_check(request):
|
|
"""Health check endpoint"""
|
|
return {"status": "healthy", "service": "opus-magnum-api"}
|
|
|
|
|
|
# API info endpoint
|
|
@api.get("/info")
|
|
def api_info(request):
|
|
"""Get API information"""
|
|
return {
|
|
"name": "Opus Magnum Submission API",
|
|
"version": "1.0.0",
|
|
"description": "API for managing puzzle submissions with OCR validation",
|
|
"features": [
|
|
"Multi-puzzle submissions",
|
|
"OCR validation",
|
|
"Manual validation workflow",
|
|
"Admin validation tools",
|
|
],
|
|
}
|
|
|
|
|
|
# User info endpoint
|
|
@api.get("/user", response=UserInfoOut)
|
|
def get_user_info(request):
|
|
"""Get current user information"""
|
|
user = request.user
|
|
|
|
if user.is_authenticated:
|
|
return {
|
|
"id": user.id,
|
|
"username": user.username,
|
|
"first_name": user.first_name,
|
|
"last_name": user.last_name,
|
|
"email": user.email,
|
|
"is_authenticated": True,
|
|
"is_staff": user.is_staff,
|
|
"is_superuser": user.is_superuser,
|
|
"cas_groups": getattr(user, "cas_groups", []),
|
|
}
|
|
else:
|
|
return {
|
|
"is_authenticated": False,
|
|
"is_staff": False,
|
|
"is_superuser": False,
|
|
}
|