From b1e0693131d9ee33d4a658c31122c4bbadacc5c3 Mon Sep 17 00:00:00 2001 From: Danamir Date: Mon, 10 Nov 2025 08:25:56 +0300 Subject: [PATCH] fix run --- backend/__init__.py | 2 ++ backend/main.py | 8 +++++++- backend/models.py | 2 -- backend/routers/__init__.py | 2 ++ backend/routers/oboruds.py | 12 ++++++++---- 5 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 backend/__init__.py create mode 100644 backend/routers/__init__.py diff --git a/backend/__init__.py b/backend/__init__.py new file mode 100644 index 0000000..e4179e8 --- /dev/null +++ b/backend/__init__.py @@ -0,0 +1,2 @@ +"""Backend package initializer.""" + diff --git a/backend/main.py b/backend/main.py index a1e2ac4..b18280c 100644 --- a/backend/main.py +++ b/backend/main.py @@ -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,10 +29,15 @@ def ping(): return {"message": "pong"} +@app.get("/") +def root(): + return RedirectResponse(url="/docs") + + # Подключение роутов app.include_router(equipment_types) app.include_router(auditories) app.include_router(oboruds) app.include_router(components) app.include_router(consumables) -app.include_router(zametki) \ No newline at end of file +app.include_router(zametki) diff --git a/backend/models.py b/backend/models.py index 2a2d12b..de24b3f 100644 --- a/backend/models.py +++ b/backend/models.py @@ -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() diff --git a/backend/routers/__init__.py b/backend/routers/__init__.py new file mode 100644 index 0000000..3d27349 --- /dev/null +++ b/backend/routers/__init__.py @@ -0,0 +1,2 @@ +"""Routers package initializer.""" + diff --git a/backend/routers/oboruds.py b/backend/routers/oboruds.py index b017c05..a7d5285 100644 --- a/backend/routers/oboruds.py +++ b/backend/routers/oboruds.py @@ -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,12 +14,15 @@ 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)): obj = db.query(models.Oboruds).filter(models.Oboruds.id == oborud_id).first() if not obj: raise HTTPException(status_code=404, detail="Oborud not found") - return obj \ No newline at end of file + return obj