From 1557fa9e537b4b6c5f1f188983ad5ef67f73067d Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 3 Nov 2025 09:34:32 -0300 Subject: Post measure --- api/routes/measures.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'api') diff --git a/api/routes/measures.py b/api/routes/measures.py index 195da9a..b435ae3 100644 --- a/api/routes/measures.py +++ b/api/routes/measures.py @@ -2,6 +2,7 @@ from fastapi import APIRouter from sqlalchemy import select from ..database import SessionLocal from ..models import Measure +from pydantic import BaseModel router = APIRouter( prefix='/measures', @@ -24,3 +25,16 @@ async def get_measures(): dc['size'] = len(dc['measures']) session.close() return dc + +class PostMeasure(BaseModel): + name: str + unit_code: str + +@router.post('/') +async def post_measure(measure: PostMeasure): + session = SessionLocal() + session.begin() + session.add(Measure(name=measure.name, unit_code=measure.unit_code)) + session.commit() + session.close() + return {'msg': 'Unidade adicionada com sucesso.'} -- cgit v1.2.3