Add two endpoints
This commit is contained in:
parent
541d79c1e1
commit
d6d2325b07
@ -2,6 +2,7 @@ from fastapi import FastAPI
|
|||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
|
|
||||||
from .providers.db_provider import create_db_and_tables
|
from .providers.db_provider import create_db_and_tables
|
||||||
|
from .routers.houses import router as houses_router
|
||||||
|
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
|
|
||||||
@ -16,7 +17,6 @@ app = FastAPI(
|
|||||||
version="1.0.0"
|
version="1.0.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Add CORS middleware
|
|
||||||
app.add_middleware(
|
app.add_middleware(
|
||||||
CORSMiddleware,
|
CORSMiddleware,
|
||||||
allow_origins=["*"],
|
allow_origins=["*"],
|
||||||
@ -24,3 +24,5 @@ app.add_middleware(
|
|||||||
allow_methods=["*"],
|
allow_methods=["*"],
|
||||||
allow_headers=["*"],
|
allow_headers=["*"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
app.include_router(houses_router, prefix="/houses", tags=["houses"])
|
||||||
|
|||||||
@ -1,13 +0,0 @@
|
|||||||
from fastapi import APIRouter, Depends
|
|
||||||
from sqlalchemy.orm import Session
|
|
||||||
from typing import List
|
|
||||||
from .. import models, schemas, database, repositories
|
|
||||||
|
|
||||||
router = APIRouter()
|
|
||||||
|
|
||||||
|
|
||||||
@router.get("/houses", response_model=List[schemas.House])
|
|
||||||
def list_houses(db: Session = Depends(database.get_db)):
|
|
||||||
houses = repositories.house.get_all_houses(db)
|
|
||||||
return houses
|
|
||||||
|
|
||||||
11
backend/app/routers/houses.py
Normal file
11
backend/app/routers/houses.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from fastapi import APIRouter
|
||||||
|
|
||||||
|
router = APIRouter()
|
||||||
|
|
||||||
|
@router.post("")
|
||||||
|
async def create_house():
|
||||||
|
raise NotImplementedError("This endpoint is not implemented yet.")
|
||||||
|
|
||||||
|
@router.get("/all")
|
||||||
|
async def get_all_houses():
|
||||||
|
raise NotImplementedError("This endpoint is not implemented yet.")
|
||||||
@ -1,14 +0,0 @@
|
|||||||
from fastapi import APIRouter, HTTPException, Depends
|
|
||||||
from typing import List
|
|
||||||
from app.models import House # Assuming you have a House model
|
|
||||||
from app.dtos import HouseCreate # Assuming you have a HouseCreate DTO
|
|
||||||
from app.repositories.house_repository import HouseRepository # Assuming you have a HouseRepository
|
|
||||||
|
|
||||||
router = APIRouter()
|
|
||||||
|
|
||||||
@router.post("/houses", response_model=House)
|
|
||||||
async def create_house(house: HouseCreate, house_repo: HouseRepository = Depends()):
|
|
||||||
new_house = house_repo.create(house)
|
|
||||||
if not new_house:
|
|
||||||
raise HTTPException(status_code=400, detail="House creation failed")
|
|
||||||
return new_house
|
|
||||||
Loading…
x
Reference in New Issue
Block a user