summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-11-03 09:34:32 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-11-03 09:34:32 -0300
commit1557fa9e537b4b6c5f1f188983ad5ef67f73067d (patch)
treec6ed9ca7f11379078c5791ed7a15981f64ecedb5
parent5db282c517f604b233668dc21d3a81de2d1857b4 (diff)
Post measure
-rw-r--r--api/routes/measures.py14
1 files changed, 14 insertions, 0 deletions
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.'}