fix run
This commit is contained in:
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
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import RedirectResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from backend.routers.equipment_types import equipment_types
|
||||
@@ -28,6 +29,11 @@ def ping():
|
||||
return {"message": "pong"}
|
||||
|
||||
|
||||
@app.get("/")
|
||||
def root():
|
||||
return RedirectResponse(url="/docs")
|
||||
|
||||
|
||||
# Подключение роутов
|
||||
app.include_router(equipment_types)
|
||||
app.include_router(auditories)
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
from sqlalchemy import Column, Integer, String, ForeignKey, DateTime
|
||||
from sqlalchemy.orm import relationship, declarative_base
|
||||
import datetime
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
|
||||
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 .. import models, schemas, database
|
||||
|
||||
@@ -13,8 +14,11 @@ def create_oborud(item: schemas.OborudCreate, db: Session = Depends(database.get
|
||||
return obj
|
||||
|
||||
@oboruds.get("/", response_model=list[schemas.OborudRead])
|
||||
def list_oboruds(db: Session = Depends(database.get_db)):
|
||||
return db.query(models.Oboruds).all()
|
||||
def list_oboruds(aud_id: Optional[int] = None, db: Session = Depends(database.get_db)):
|
||||
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)
|
||||
def get_oborud(oborud_id: int, db: Session = Depends(database.get_db)):
|
||||
|
||||
Reference in New Issue
Block a user