Compare commits
1 Commits
fastapi-mi
...
dev_fix_ru
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b1e0693131 |
2
backend/__init__.py
Normal file
2
backend/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
"""Backend package initializer."""
|
||||||
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
# backend/main.py
|
# backend/main.py
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from fastapi.responses import RedirectResponse
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from backend.routers.equipment_types import equipment_types
|
from backend.routers.equipment_types import equipment_types
|
||||||
@@ -28,6 +29,11 @@ def ping():
|
|||||||
return {"message": "pong"}
|
return {"message": "pong"}
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/")
|
||||||
|
def root():
|
||||||
|
return RedirectResponse(url="/docs")
|
||||||
|
|
||||||
|
|
||||||
# Подключение роутов
|
# Подключение роутов
|
||||||
app.include_router(equipment_types)
|
app.include_router(equipment_types)
|
||||||
app.include_router(auditories)
|
app.include_router(auditories)
|
||||||
|
|||||||
@@ -3,11 +3,9 @@
|
|||||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||||
from sqlalchemy.orm import relationship, declarative_base
|
from sqlalchemy.orm import relationship, declarative_base
|
||||||
import datetime
|
import datetime
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
|
||||||
|
|
||||||
Base = declarative_base()
|
Base = declarative_base()
|
||||||
|
|
||||||
db = SQLAlchemy()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
2
backend/routers/__init__.py
Normal file
2
backend/routers/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
"""Routers package initializer."""
|
||||||
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
from fastapi import APIRouter, Depends
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
|
from typing import Optional
|
||||||
from sqlalchemy.orm import Session
|
from sqlalchemy.orm import Session
|
||||||
from .. import models, schemas, database
|
from .. import models, schemas, database
|
||||||
|
|
||||||
@@ -13,8 +14,11 @@ def create_oborud(item: schemas.OborudCreate, db: Session = Depends(database.get
|
|||||||
return obj
|
return obj
|
||||||
|
|
||||||
@oboruds.get("/", response_model=list[schemas.OborudRead])
|
@oboruds.get("/", response_model=list[schemas.OborudRead])
|
||||||
def list_oboruds(db: Session = Depends(database.get_db)):
|
def list_oboruds(aud_id: Optional[int] = None, db: Session = Depends(database.get_db)):
|
||||||
return db.query(models.Oboruds).all()
|
query = db.query(models.Oboruds)
|
||||||
|
if aud_id is not None:
|
||||||
|
query = query.filter(models.Oboruds.aud_id == aud_id)
|
||||||
|
return query.all()
|
||||||
|
|
||||||
@oboruds.get("/{oborud_id}", response_model=schemas.OborudRead)
|
@oboruds.get("/{oborud_id}", response_model=schemas.OborudRead)
|
||||||
def get_oborud(oborud_id: int, db: Session = Depends(database.get_db)):
|
def get_oborud(oborud_id: int, db: Session = Depends(database.get_db)):
|
||||||
|
|||||||
Reference in New Issue
Block a user