Deploy to Staging / deploy (push) Waiting to run
Lint Backend / lint-backend (push) Waiting to run
Playwright Tests / changes (push) Waiting to run
Playwright Tests / test-playwright (1, 4) (push) Blocked by required conditions
Playwright Tests / test-playwright (2, 4) (push) Blocked by required conditions
Playwright Tests / test-playwright (3, 4) (push) Blocked by required conditions
Playwright Tests / test-playwright (4, 4) (push) Blocked by required conditions
Playwright Tests / merge-playwright-reports (push) Blocked by required conditions
Playwright Tests / alls-green-playwright (push) Blocked by required conditions
Test Backend / test-backend (push) Waiting to run
Test Docker Compose / test-docker-compose (push) Waiting to run
75 lines
1.7 KiB
Python
75 lines
1.7 KiB
Python
from typing import List
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.api import deps
|
|
from app.schemas.todo import Todo, TodoCreate, TodoUpdate
|
|
from app.models.todo import Todo as TodoModel
|
|
from app.crud.todo import todo
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/", response_model=List[Todo])
|
|
def read_todos(
|
|
db: Session = Depends(deps.get_db),
|
|
skip: int = 0,
|
|
limit: int = 100,
|
|
):
|
|
"""
|
|
Retrieve todos.
|
|
"""
|
|
return todo.get_multi(db, skip=skip, limit=limit)
|
|
|
|
@router.post("/", response_model=Todo)
|
|
def create_todo(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
todo_in: TodoCreate,
|
|
):
|
|
"""
|
|
Create new todo.
|
|
"""
|
|
return todo.create(db=db, obj_in=todo_in)
|
|
|
|
@router.put("/{id}", response_model=Todo)
|
|
def update_todo(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
id: int,
|
|
todo_in: TodoUpdate,
|
|
):
|
|
"""
|
|
Update a todo.
|
|
"""
|
|
todo_current = todo.get(db=db, id=id)
|
|
if not todo_current:
|
|
raise HTTPException(status_code=404, detail="Todo not found")
|
|
return todo.update(db=db, db_obj=todo_current, obj_in=todo_in)
|
|
|
|
@router.get("/{id}", response_model=Todo)
|
|
def read_todo(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
id: int,
|
|
):
|
|
"""
|
|
Get todo by ID.
|
|
"""
|
|
todo_current = todo.get(db=db, id=id)
|
|
if not todo_current:
|
|
raise HTTPException(status_code=404, detail="Todo not found")
|
|
return todo_current
|
|
|
|
@router.delete("/{id}", response_model=Todo)
|
|
def delete_todo(
|
|
*,
|
|
db: Session = Depends(deps.get_db),
|
|
id: int,
|
|
):
|
|
"""
|
|
Delete todo.
|
|
"""
|
|
todo_current = todo.get(db=db, id=id)
|
|
if not todo_current:
|
|
raise HTTPException(status_code=404, detail="Todo not found")
|
|
return todo.remove(db=db, id=id) |