Initial release

This commit is contained in:
Francesco Carmelo Capria 2025-06-21 18:15:33 +02:00
commit ae5e4b8873
52 changed files with 17572 additions and 0 deletions

82
backend/app/app.py Normal file
View file

@ -0,0 +1,82 @@
from contextlib import asynccontextmanager
from fastapi import Depends, FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.db import User, create_db_and_tables
from app.schemas import UserCreate, UserRead, UserUpdate
from app.users import auth_backend, current_active_user, fastapi_users
from app.upload import router as upload_router
from app.download import router as download_router
from app.publication_routes import router as publication_router
from app.debug_routes import router as debug_router
@asynccontextmanager
async def lifespan(app: FastAPI):
await create_db_and_tables()
yield
app = FastAPI(
title="Scientify API",
description="API for managing scientific publications",
version="1.0.0",
lifespan=lifespan
)
app.add_middleware(
CORSMiddleware,
allow_origins=["http://frontend:80"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Include routers for different parts of the application
app.include_router(upload_router)
app.include_router(download_router)
app.include_router(publication_router)
app.include_router(debug_router)
# Authentication and user management routes
app.include_router(
fastapi_users.get_auth_router(auth_backend), prefix="/auth/jwt", tags=["auth"]
)
app.include_router(
fastapi_users.get_register_router(UserRead, UserCreate),
prefix="/auth",
tags=["auth"],
)
app.include_router(
fastapi_users.get_reset_password_router(),
prefix="/auth",
tags=["auth"],
)
app.include_router(
fastapi_users.get_verify_router(UserRead),
prefix="/auth",
tags=["auth"],
)
app.include_router(
fastapi_users.get_users_router(UserRead, UserUpdate),
prefix="/users",
tags=["users"],
)
@app.get("/authenticated-route")
async def authenticated_route(user: User = Depends(current_active_user)):
return {"message": f"Hello {user.email}!"}
@app.get("/")
async def root():
"""
Root endpoint for the Scientify API
"""
return {
"message": "Welcome to Scientify API",
"description": "The intelligent platform to manage your scientific publications",
"documentation": "/docs"
}