Spaces:
Build error
Build error
Commit ·
b90e2c0
1
Parent(s): 725ae54
modificacion de tablas
Browse files- .gitignore +2 -0
- Dockerfile +15 -0
- app.py +1706 -0
- optica.db +0 -0
- requirements.txt +3 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.venv
|
| 2 |
+
__pycache__
|
Dockerfile
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Usa una imagen base de Python
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
# Establece el directorio de trabajo
|
| 4 |
+
WORKDIR /code
|
| 5 |
+
|
| 6 |
+
# Copia los archivos necesarios al contenedor
|
| 7 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 8 |
+
RUN pip install --no-cache-dir -r /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
COPY . .
|
| 11 |
+
|
| 12 |
+
RUN chmod -R 777 /code
|
| 13 |
+
|
| 14 |
+
# Comando para ejecutar la aplicación
|
| 15 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,1706 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# uvicorn app:app --host localhost --port 7860 --reload
|
| 2 |
+
|
| 3 |
+
from fastapi import Request
|
| 4 |
+
from urllib.parse import quote
|
| 5 |
+
from fastapi.staticfiles import StaticFiles
|
| 6 |
+
from reportlab.lib.units import cm
|
| 7 |
+
from fastapi import FastAPI, HTTPException
|
| 8 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 9 |
+
from fastapi.responses import JSONResponse
|
| 10 |
+
from pydantic import BaseModel
|
| 11 |
+
from io import BytesIO
|
| 12 |
+
from reportlab.lib.pagesizes import A4
|
| 13 |
+
from reportlab.pdfgen import canvas
|
| 14 |
+
from typing import List
|
| 15 |
+
import os
|
| 16 |
+
import sqlite3
|
| 17 |
+
import threading
|
| 18 |
+
from queue import Queue
|
| 19 |
+
|
| 20 |
+
app = FastAPI()
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
app.add_middleware(
|
| 24 |
+
CORSMiddleware,
|
| 25 |
+
allow_origins=["*"],
|
| 26 |
+
allow_credentials=True,
|
| 27 |
+
allow_methods=["*"],
|
| 28 |
+
allow_headers=["*"],
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class DatabaseConnection:
|
| 33 |
+
"""
|
| 34 |
+
Clase para gestionar las conexiones a la base de datos con un pool.
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
_instance = None
|
| 38 |
+
_lock = threading.Lock()
|
| 39 |
+
_connection_pool = Queue(maxsize=5)
|
| 40 |
+
|
| 41 |
+
def __new__(cls):
|
| 42 |
+
"""
|
| 43 |
+
Crea una nueva instancia de la clase si no existe.
|
| 44 |
+
"""
|
| 45 |
+
with cls._lock:
|
| 46 |
+
if cls._instance is None:
|
| 47 |
+
cls._instance = super().__new__(cls)
|
| 48 |
+
cls._instance.conn = cls._instance._create_connection()
|
| 49 |
+
return cls._instance
|
| 50 |
+
|
| 51 |
+
def _create_connection(self):
|
| 52 |
+
"""
|
| 53 |
+
Crea una conexión a la base de datos.
|
| 54 |
+
"""
|
| 55 |
+
if not self._connection_pool.empty():
|
| 56 |
+
return self._connection_pool.get()
|
| 57 |
+
else:
|
| 58 |
+
connection = sqlite3.connect("optica.db")
|
| 59 |
+
connection.row_factory = sqlite3.Row
|
| 60 |
+
return connection
|
| 61 |
+
|
| 62 |
+
def get_connection(self):
|
| 63 |
+
"""
|
| 64 |
+
Obtener el objeto de conexión de la base de datos.
|
| 65 |
+
"""
|
| 66 |
+
return self._instance._create_connection()
|
| 67 |
+
|
| 68 |
+
def release_connection(self):
|
| 69 |
+
"""
|
| 70 |
+
Liberar la conexión de nuevo al pool.
|
| 71 |
+
"""
|
| 72 |
+
if self._instance is not None:
|
| 73 |
+
self._connection_pool.put(self._instance.conn)
|
| 74 |
+
self._instance.conn = None # Marcar la instancia como sin conexión
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# saludo
|
| 78 |
+
@app.get("/")
|
| 79 |
+
def read_root():
|
| 80 |
+
return {"mensaje": "Bienvenido a la API de Optica"}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
"""
|
| 84 |
+
CREATE TABLE Roles (
|
| 85 |
+
id_rol INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 86 |
+
rol VARCHAR
|
| 87 |
+
);
|
| 88 |
+
"""
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# metodo get de roles con manejo de errores
|
| 92 |
+
@app.get("/roles")
|
| 93 |
+
def get_roles():
|
| 94 |
+
try:
|
| 95 |
+
conn = DatabaseConnection().get_connection()
|
| 96 |
+
cursor = conn.cursor()
|
| 97 |
+
cursor.execute("SELECT * FROM Roles")
|
| 98 |
+
roles = cursor.fetchall()
|
| 99 |
+
return roles
|
| 100 |
+
except Exception as e:
|
| 101 |
+
print(e)
|
| 102 |
+
return []
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
# get de roles por id
|
| 106 |
+
@app.get("/roles/{id_rol}")
|
| 107 |
+
def get_rol(id_rol: int):
|
| 108 |
+
try:
|
| 109 |
+
conn = DatabaseConnection().get_connection()
|
| 110 |
+
cursor = conn.cursor()
|
| 111 |
+
cursor.execute("SELECT * FROM Roles WHERE id_rol = ?", [id_rol])
|
| 112 |
+
rol = cursor.fetchone()
|
| 113 |
+
if rol:
|
| 114 |
+
return rol
|
| 115 |
+
else:
|
| 116 |
+
raise HTTPException(status_code=404, detail="Rol no encontrado")
|
| 117 |
+
except Exception as e:
|
| 118 |
+
print(e)
|
| 119 |
+
return []
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
# busqueda por nombre de rol con like con manejo de errores y con metodo get
|
| 123 |
+
@app.get("/roles/busqueda/{rol}")
|
| 124 |
+
def get_rol_busqueda(rol: str):
|
| 125 |
+
try:
|
| 126 |
+
conn = DatabaseConnection().get_connection()
|
| 127 |
+
cursor = conn.cursor()
|
| 128 |
+
cursor.execute("SELECT * FROM Roles WHERE rol LIKE ?", ["%" + rol + "%"])
|
| 129 |
+
rol = cursor.fetchall()
|
| 130 |
+
if rol:
|
| 131 |
+
return rol
|
| 132 |
+
else:
|
| 133 |
+
raise HTTPException(status_code=404, detail="Rol no encontrado")
|
| 134 |
+
except Exception as e:
|
| 135 |
+
print(e)
|
| 136 |
+
return []
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
# clase y metodo post para buscar rol
|
| 140 |
+
class RolBusqueda(BaseModel):
|
| 141 |
+
rol: str
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
@app.post("/roles/busqueda")
|
| 145 |
+
def get_rol_busqueda(rol: RolBusqueda):
|
| 146 |
+
try:
|
| 147 |
+
conn = DatabaseConnection().get_connection()
|
| 148 |
+
cursor = conn.cursor()
|
| 149 |
+
cursor.execute("SELECT * FROM Roles WHERE rol LIKE ?", ["%" + rol.rol + "%"])
|
| 150 |
+
rol = cursor.fetchall()
|
| 151 |
+
if rol:
|
| 152 |
+
return rol
|
| 153 |
+
else:
|
| 154 |
+
raise HTTPException(status_code=404, detail="Rol no encontrado")
|
| 155 |
+
except Exception as e:
|
| 156 |
+
print(e)
|
| 157 |
+
return []
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
# clase rol para el metodo post
|
| 161 |
+
class Rol(BaseModel):
|
| 162 |
+
rol: str
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
# metodo post de roles con manejo de errores
|
| 166 |
+
@app.post("/roles")
|
| 167 |
+
def create_rol(rol: Rol):
|
| 168 |
+
try:
|
| 169 |
+
conn = DatabaseConnection().get_connection()
|
| 170 |
+
cursor = conn.cursor()
|
| 171 |
+
cursor.execute("INSERT INTO Roles (rol) VALUES (?)", [rol.rol])
|
| 172 |
+
conn.commit()
|
| 173 |
+
return {"mensaje": "Rol creado correctamente"}
|
| 174 |
+
except Exception as e:
|
| 175 |
+
print(e)
|
| 176 |
+
return {"mensaje": "Error al crear el rol"}
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
# clase rol para el metodo put
|
| 180 |
+
class RolPut(BaseModel):
|
| 181 |
+
id_rol: int
|
| 182 |
+
rol: str
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
# metodo put de roles con manejo de errores
|
| 186 |
+
@app.put("/roles")
|
| 187 |
+
def update_rol(rol: RolPut):
|
| 188 |
+
try:
|
| 189 |
+
conn = DatabaseConnection().get_connection()
|
| 190 |
+
cursor = conn.cursor()
|
| 191 |
+
cursor.execute(
|
| 192 |
+
"UPDATE Roles SET rol = ? WHERE id_rol = ?", [rol.rol, rol.id_rol]
|
| 193 |
+
)
|
| 194 |
+
conn.commit()
|
| 195 |
+
return {"mensaje": "Rol actualizado correctamente"}
|
| 196 |
+
except Exception as e:
|
| 197 |
+
print(e)
|
| 198 |
+
return {"mensaje": "Error al actualizar el rol"}
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
# metodo delete de roles con manejo de errores
|
| 202 |
+
@app.delete("/roles/{id_rol}")
|
| 203 |
+
def delete_rol(id_rol: int):
|
| 204 |
+
try:
|
| 205 |
+
conn = DatabaseConnection().get_connection()
|
| 206 |
+
cursor = conn.cursor()
|
| 207 |
+
cursor.execute("DELETE FROM Roles WHERE id_rol = ?", [id_rol])
|
| 208 |
+
conn.commit()
|
| 209 |
+
return {"mensaje": "Rol eliminado correctamente"}
|
| 210 |
+
except Exception as e:
|
| 211 |
+
print(e)
|
| 212 |
+
return {"mensaje": "Error al eliminar el rol"}
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
"""
|
| 216 |
+
CREATE TABLE Usuario (
|
| 217 |
+
id_usuario INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 218 |
+
nombre_usuario VARCHAR,
|
| 219 |
+
dni VARCHAR,
|
| 220 |
+
clave VARCHAR,
|
| 221 |
+
id_rol INTEGER REFERENCES Roles(id_rol),
|
| 222 |
+
estado VARCHAR
|
| 223 |
+
);
|
| 224 |
+
"""
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
# metodo get de usuarios
|
| 228 |
+
@app.get("/usuarios")
|
| 229 |
+
def get_usuarios():
|
| 230 |
+
try:
|
| 231 |
+
conn = DatabaseConnection().get_connection()
|
| 232 |
+
cursor = conn.cursor()
|
| 233 |
+
cursor.execute("SELECT * FROM Usuario")
|
| 234 |
+
usuarios = cursor.fetchall()
|
| 235 |
+
return usuarios
|
| 236 |
+
except Exception as e:
|
| 237 |
+
print(e)
|
| 238 |
+
return []
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
# get de usuarios por id
|
| 242 |
+
@app.get("/usuarios/{id_usuario}")
|
| 243 |
+
def get_usuario(id_usuario: int):
|
| 244 |
+
try:
|
| 245 |
+
conn = DatabaseConnection().get_connection()
|
| 246 |
+
cursor = conn.cursor()
|
| 247 |
+
cursor.execute("SELECT * FROM Usuario WHERE id_usuario = ?", [id_usuario])
|
| 248 |
+
usuario = cursor.fetchone()
|
| 249 |
+
if usuario:
|
| 250 |
+
return usuario
|
| 251 |
+
else:
|
| 252 |
+
raise HTTPException(status_code=404, detail="Usuario no encontrado")
|
| 253 |
+
except Exception as e:
|
| 254 |
+
print(e)
|
| 255 |
+
return []
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
# busqueda por nombre de usuario con like con manejo de errores y con metodo get
|
| 259 |
+
@app.get("/usuarios/busqueda/{nombre_usuario}")
|
| 260 |
+
def get_usuario_busqueda(nombre_usuario: str):
|
| 261 |
+
try:
|
| 262 |
+
conn = DatabaseConnection().get_connection()
|
| 263 |
+
cursor = conn.cursor()
|
| 264 |
+
cursor.execute(
|
| 265 |
+
"SELECT * FROM Usuario WHERE nombre_usuario LIKE ?",
|
| 266 |
+
["%" + nombre_usuario + "%"],
|
| 267 |
+
)
|
| 268 |
+
usuario = cursor.fetchall()
|
| 269 |
+
if usuario:
|
| 270 |
+
return usuario
|
| 271 |
+
else:
|
| 272 |
+
raise HTTPException(status_code=404, detail="Usuario no encontrado")
|
| 273 |
+
except Exception as e:
|
| 274 |
+
print(e)
|
| 275 |
+
return []
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
# busqueda por nombre de usuario con like con manejo de errores y con metodo post y clase
|
| 279 |
+
class UsuarioBusqueda(BaseModel):
|
| 280 |
+
nombre_usuario: str
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
# metodo post
|
| 284 |
+
@app.post("/usuarios/busqueda")
|
| 285 |
+
def get_usuario_busqueda(usuario: UsuarioBusqueda):
|
| 286 |
+
try:
|
| 287 |
+
conn = DatabaseConnection().get_connection()
|
| 288 |
+
cursor = conn.cursor()
|
| 289 |
+
cursor.execute(
|
| 290 |
+
"SELECT * FROM Usuario WHERE nombre_usuario LIKE ?",
|
| 291 |
+
["%" + usuario.nombre_usuario + "%"],
|
| 292 |
+
)
|
| 293 |
+
usuario = cursor.fetchall()
|
| 294 |
+
if usuario:
|
| 295 |
+
return usuario
|
| 296 |
+
else:
|
| 297 |
+
raise HTTPException(status_code=404, detail="Usuario no encontrado")
|
| 298 |
+
except Exception as e:
|
| 299 |
+
print(e)
|
| 300 |
+
return []
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
# clase usuario para el metodo post
|
| 304 |
+
class Usuario(BaseModel):
|
| 305 |
+
nombre_usuario: str
|
| 306 |
+
dni: str
|
| 307 |
+
clave: str
|
| 308 |
+
id_rol: int
|
| 309 |
+
estado: str
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
# metodo post de usuarios con manejo de errores
|
| 313 |
+
@app.post("/usuarios")
|
| 314 |
+
def create_usuario(usuario: Usuario):
|
| 315 |
+
try:
|
| 316 |
+
conn = DatabaseConnection().get_connection()
|
| 317 |
+
cursor = conn.cursor()
|
| 318 |
+
cursor.execute(
|
| 319 |
+
"INSERT INTO Usuario (nombre_usuario, dni, clave, id_rol, estado) VALUES (?, ?, ?, ?, ?)",
|
| 320 |
+
[
|
| 321 |
+
usuario.nombre_usuario,
|
| 322 |
+
usuario.dni,
|
| 323 |
+
usuario.clave,
|
| 324 |
+
usuario.id_rol,
|
| 325 |
+
usuario.estado,
|
| 326 |
+
],
|
| 327 |
+
)
|
| 328 |
+
conn.commit()
|
| 329 |
+
return {"mensaje": "Usuario creado correctamente"}
|
| 330 |
+
except Exception as e:
|
| 331 |
+
print(e)
|
| 332 |
+
return {"mensaje": "Error al crear el usuario"}
|
| 333 |
+
|
| 334 |
+
|
| 335 |
+
# clase usuario para el metodo put
|
| 336 |
+
class UsuarioPut(BaseModel):
|
| 337 |
+
id_usuario: int
|
| 338 |
+
nombre_usuario: str
|
| 339 |
+
dni: str
|
| 340 |
+
clave: str
|
| 341 |
+
id_rol: int
|
| 342 |
+
estado: str
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
# metodo put de usuarios con manejo de errores
|
| 346 |
+
@app.put("/usuarios")
|
| 347 |
+
def update_usuario(usuario: UsuarioPut):
|
| 348 |
+
try:
|
| 349 |
+
conn = DatabaseConnection().get_connection()
|
| 350 |
+
cursor = conn.cursor()
|
| 351 |
+
cursor.execute(
|
| 352 |
+
"UPDATE Usuario SET nombre_usuario = ?, dni = ?, clave = ?, id_rol = ?, estado = ? WHERE id_usuario = ?",
|
| 353 |
+
[
|
| 354 |
+
usuario.nombre_usuario,
|
| 355 |
+
usuario.dni,
|
| 356 |
+
usuario.clave,
|
| 357 |
+
usuario.id_rol,
|
| 358 |
+
usuario.estado,
|
| 359 |
+
usuario.id_usuario,
|
| 360 |
+
],
|
| 361 |
+
)
|
| 362 |
+
conn.commit()
|
| 363 |
+
return {"mensaje": "Usuario actualizado correctamente"}
|
| 364 |
+
except Exception as e:
|
| 365 |
+
print(e)
|
| 366 |
+
return {"mensaje": "Error al actualizar el usuario"}
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
# metodo delete de usuarios con manejo de errores
|
| 370 |
+
@app.delete("/usuarios/{id_usuario}")
|
| 371 |
+
def delete_usuario(id_usuario: int):
|
| 372 |
+
try:
|
| 373 |
+
conn = DatabaseConnection().get_connection()
|
| 374 |
+
cursor = conn.cursor()
|
| 375 |
+
cursor.execute("DELETE FROM Usuario WHERE id_usuario = ?", [id_usuario])
|
| 376 |
+
conn.commit()
|
| 377 |
+
return {"mensaje": "Usuario eliminado correctamente"}
|
| 378 |
+
except Exception as e:
|
| 379 |
+
print(e)
|
| 380 |
+
return {"mensaje": "Error al eliminar el usuario"}
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
"""
|
| 384 |
+
CREATE TABLE Cliente (
|
| 385 |
+
id_cliente INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 386 |
+
nombres_y_apellidos VARCHAR,
|
| 387 |
+
edad INTEGER,
|
| 388 |
+
telefono INTEGER,
|
| 389 |
+
direccion VARCHAR
|
| 390 |
+
);
|
| 391 |
+
"""
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
# metodo get de clientes
|
| 395 |
+
@app.get("/clientes")
|
| 396 |
+
def get_clientes():
|
| 397 |
+
try:
|
| 398 |
+
conn = DatabaseConnection().get_connection()
|
| 399 |
+
cursor = conn.cursor()
|
| 400 |
+
cursor.execute("SELECT * FROM Cliente")
|
| 401 |
+
clientes = cursor.fetchall()
|
| 402 |
+
return clientes
|
| 403 |
+
except Exception as e:
|
| 404 |
+
print(e)
|
| 405 |
+
return []
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
# get de clientes por id
|
| 409 |
+
@app.get("/clientes/{id_cliente}")
|
| 410 |
+
def get_cliente(id_cliente: int):
|
| 411 |
+
try:
|
| 412 |
+
conn = DatabaseConnection().get_connection()
|
| 413 |
+
cursor = conn.cursor()
|
| 414 |
+
cursor.execute("SELECT * FROM Cliente WHERE id_cliente = ?", [id_cliente])
|
| 415 |
+
cliente = cursor.fetchone()
|
| 416 |
+
if cliente:
|
| 417 |
+
return cliente
|
| 418 |
+
else:
|
| 419 |
+
raise HTTPException(status_code=404, detail="Cliente no encontrado")
|
| 420 |
+
except Exception as e:
|
| 421 |
+
print(e)
|
| 422 |
+
return []
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
# busqueda por nombre y apellido de cliente con like con manejo de errores y con metodo get
|
| 426 |
+
@app.get("/clientes/busqueda/{nombres_y_apellidos}")
|
| 427 |
+
def get_cliente_busqueda(nombres_y_apellidos: str):
|
| 428 |
+
try:
|
| 429 |
+
conn = DatabaseConnection().get_connection()
|
| 430 |
+
cursor = conn.cursor()
|
| 431 |
+
cursor.execute(
|
| 432 |
+
"SELECT * FROM Cliente WHERE nombres_y_apellidos LIKE ?",
|
| 433 |
+
["%" + nombres_y_apellidos + "%"],
|
| 434 |
+
)
|
| 435 |
+
cliente = cursor.fetchall()
|
| 436 |
+
if cliente:
|
| 437 |
+
return cliente
|
| 438 |
+
else:
|
| 439 |
+
raise HTTPException(status_code=404, detail="Cliente no encontrado")
|
| 440 |
+
except Exception as e:
|
| 441 |
+
print(e)
|
| 442 |
+
return []
|
| 443 |
+
|
| 444 |
+
|
| 445 |
+
# busqueda por nombre y apellido de cliente con like con manejo de errores y con metodo post y clase
|
| 446 |
+
class ClienteBusqueda(BaseModel):
|
| 447 |
+
nombres_y_apellidos: str
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
# metodo post
|
| 451 |
+
@app.post("/clientes/busqueda")
|
| 452 |
+
def get_cliente_busqueda(cliente: ClienteBusqueda):
|
| 453 |
+
try:
|
| 454 |
+
conn = DatabaseConnection().get_connection()
|
| 455 |
+
cursor = conn.cursor()
|
| 456 |
+
cursor.execute(
|
| 457 |
+
"SELECT * FROM Cliente WHERE nombres_y_apellidos LIKE ?",
|
| 458 |
+
["%" + cliente.nombres_y_apellidos + "%"],
|
| 459 |
+
)
|
| 460 |
+
cliente = cursor.fetchall()
|
| 461 |
+
if cliente:
|
| 462 |
+
return cliente
|
| 463 |
+
else:
|
| 464 |
+
raise HTTPException(status_code=404, detail="Cliente no encontrado")
|
| 465 |
+
except Exception as e:
|
| 466 |
+
print(e)
|
| 467 |
+
return []
|
| 468 |
+
|
| 469 |
+
|
| 470 |
+
# clase cliente para el metodo post
|
| 471 |
+
class Cliente(BaseModel):
|
| 472 |
+
nombres_y_apellidos: str
|
| 473 |
+
edad: int
|
| 474 |
+
telefono: int
|
| 475 |
+
direccion: str
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
# metodo post de clientes con manejo de errores
|
| 479 |
+
@app.post("/clientes")
|
| 480 |
+
def create_cliente(cliente: Cliente):
|
| 481 |
+
try:
|
| 482 |
+
conn = DatabaseConnection().get_connection()
|
| 483 |
+
cursor = conn.cursor()
|
| 484 |
+
cursor.execute(
|
| 485 |
+
"INSERT INTO Cliente (nombres_y_apellidos, edad, telefono, direccion) VALUES (?, ?, ?, ?)",
|
| 486 |
+
[
|
| 487 |
+
cliente.nombres_y_apellidos,
|
| 488 |
+
cliente.edad,
|
| 489 |
+
cliente.telefono,
|
| 490 |
+
cliente.direccion,
|
| 491 |
+
],
|
| 492 |
+
)
|
| 493 |
+
conn.commit()
|
| 494 |
+
return {"mensaje": "Cliente creado correctamente"}
|
| 495 |
+
except Exception as e:
|
| 496 |
+
print(e)
|
| 497 |
+
return {"mensaje": "Error al crear el cliente"}
|
| 498 |
+
|
| 499 |
+
|
| 500 |
+
# clase cliente para el metodo put
|
| 501 |
+
class ClientePut(BaseModel):
|
| 502 |
+
id_cliente: int
|
| 503 |
+
nombres_y_apellidos: str
|
| 504 |
+
edad: int
|
| 505 |
+
telefono: int
|
| 506 |
+
direccion: str
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
# metodo put de clientes con manejo de errores
|
| 510 |
+
@app.put("/clientes")
|
| 511 |
+
def update_cliente(cliente: ClientePut):
|
| 512 |
+
try:
|
| 513 |
+
conn = DatabaseConnection().get_connection()
|
| 514 |
+
cursor = conn.cursor()
|
| 515 |
+
cursor.execute(
|
| 516 |
+
"UPDATE Cliente SET nombres_y_apellidos = ?, edad = ?, telefono = ?, direccion = ? WHERE id_cliente = ?",
|
| 517 |
+
[
|
| 518 |
+
cliente.nombres_y_apellidos,
|
| 519 |
+
cliente.edad,
|
| 520 |
+
cliente.telefono,
|
| 521 |
+
cliente.direccion,
|
| 522 |
+
cliente.id_cliente,
|
| 523 |
+
],
|
| 524 |
+
)
|
| 525 |
+
conn.commit()
|
| 526 |
+
return {"mensaje": "Cliente actualizado correctamente"}
|
| 527 |
+
except Exception as e:
|
| 528 |
+
print(e)
|
| 529 |
+
return {"mensaje": "Error al actualizar el cliente"}
|
| 530 |
+
|
| 531 |
+
|
| 532 |
+
# metodo delete de clientes con manejo de errores
|
| 533 |
+
@app.delete("/clientes/{id_cliente}")
|
| 534 |
+
def delete_cliente(id_cliente: int):
|
| 535 |
+
try:
|
| 536 |
+
conn = DatabaseConnection().get_connection()
|
| 537 |
+
cursor = conn.cursor()
|
| 538 |
+
cursor.execute("DELETE FROM Cliente WHERE id_cliente = ?", [id_cliente])
|
| 539 |
+
conn.commit()
|
| 540 |
+
return {"mensaje": "Cliente eliminado correctamente"}
|
| 541 |
+
except Exception as e:
|
| 542 |
+
print(e)
|
| 543 |
+
return {"mensaje": "Error al eliminar el cliente"}
|
| 544 |
+
|
| 545 |
+
|
| 546 |
+
"""
|
| 547 |
+
CREATE TABLE Medidas (
|
| 548 |
+
id_medidas INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 549 |
+
Esfera_OD_lejos FLOAT,
|
| 550 |
+
Cilindro_OD_lejos FLOAT,
|
| 551 |
+
Eje_OD_lejos FLOAT,
|
| 552 |
+
Agudeza_visual_OD_lejos FLOAT,
|
| 553 |
+
Esfera_OI_lejos FLOAT,
|
| 554 |
+
Cilindro_OI_lejos FLOAT,
|
| 555 |
+
Eje_OI_lejos FLOAT,
|
| 556 |
+
Agudeza_visual_OI_lejos FLOAT,
|
| 557 |
+
Esfera_OD_cerca FLOAT,
|
| 558 |
+
Cilindro_OD_cerca FLOAT,
|
| 559 |
+
Eje_OD_cerca FLOAT,
|
| 560 |
+
Agudeza_visual_OD_cerca FLOAT,
|
| 561 |
+
Esfera_OI_cerca FLOAT,
|
| 562 |
+
Cilindro_OI_cerca FLOAT,
|
| 563 |
+
Eje_OI_cerca FLOAT,
|
| 564 |
+
Agudeza_visual_OI_cerca FLOAT,
|
| 565 |
+
id_cliente INTEGER REFERENCES Cliente(id_cliente)
|
| 566 |
+
);
|
| 567 |
+
"""
|
| 568 |
+
|
| 569 |
+
|
| 570 |
+
# metodo get de medidas
|
| 571 |
+
@app.get("/medidas")
|
| 572 |
+
def get_medidas():
|
| 573 |
+
try:
|
| 574 |
+
conn = DatabaseConnection().get_connection()
|
| 575 |
+
cursor = conn.cursor()
|
| 576 |
+
cursor.execute("SELECT * FROM Medidas")
|
| 577 |
+
medidas = cursor.fetchall()
|
| 578 |
+
return medidas
|
| 579 |
+
except Exception as e:
|
| 580 |
+
print(e)
|
| 581 |
+
return []
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
# get de medidas por id
|
| 585 |
+
@app.get("/medidas/{id_medidas}")
|
| 586 |
+
def get_medida(id_medidas: int):
|
| 587 |
+
try:
|
| 588 |
+
conn = DatabaseConnection().get_connection()
|
| 589 |
+
cursor = conn.cursor()
|
| 590 |
+
cursor.execute("SELECT * FROM Medidas WHERE id_medidas = ?", [id_medidas])
|
| 591 |
+
medida = cursor.fetchone()
|
| 592 |
+
if medida:
|
| 593 |
+
return medida
|
| 594 |
+
else:
|
| 595 |
+
raise HTTPException(status_code=404, detail="Medida no encontrada")
|
| 596 |
+
except Exception as e:
|
| 597 |
+
print(e)
|
| 598 |
+
return []
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
# metodo de busqueda que sea por id_cliente y retorne las medidas asociadas a ese cliente con clase y metodo post
|
| 602 |
+
class MedidaBusqueda(BaseModel):
|
| 603 |
+
id_cliente: int
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
@app.post("/medidas/busqueda")
|
| 607 |
+
def post_medida_busqueda(medida: MedidaBusqueda):
|
| 608 |
+
try:
|
| 609 |
+
conn = DatabaseConnection().get_connection()
|
| 610 |
+
cursor = conn.cursor()
|
| 611 |
+
cursor.execute(
|
| 612 |
+
"SELECT * FROM Medidas WHERE id_cliente = ?", [medida.id_cliente]
|
| 613 |
+
)
|
| 614 |
+
medida = cursor.fetchall()
|
| 615 |
+
if medida:
|
| 616 |
+
return medida
|
| 617 |
+
else:
|
| 618 |
+
raise HTTPException(status_code=404, detail="Medida no encontrada")
|
| 619 |
+
except Exception as e:
|
| 620 |
+
print(e)
|
| 621 |
+
return []
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
# clase medida para el metodo post
|
| 625 |
+
class Medida(BaseModel):
|
| 626 |
+
Esfera_OD_lejos: float
|
| 627 |
+
Cilindro_OD_lejos: float
|
| 628 |
+
Eje_OD_lejos: float
|
| 629 |
+
Agudeza_visual_OD_lejos: float
|
| 630 |
+
Esfera_OI_lejos: float
|
| 631 |
+
Cilindro_OI_lejos: float
|
| 632 |
+
Eje_OI_lejos: float
|
| 633 |
+
Agudeza_visual_OI_lejos: float
|
| 634 |
+
Esfera_OD_cerca: float
|
| 635 |
+
Cilindro_OD_cerca: float
|
| 636 |
+
Eje_OD_cerca: float
|
| 637 |
+
Agudeza_visual_OD_cerca: float
|
| 638 |
+
Esfera_OI_cerca: float
|
| 639 |
+
Cilindro_OI_cerca: float
|
| 640 |
+
Eje_OI_cerca: float
|
| 641 |
+
Agudeza_visual_OI_cerca: float
|
| 642 |
+
id_cliente: int
|
| 643 |
+
|
| 644 |
+
|
| 645 |
+
# metodo post de medidas con manejo de errores
|
| 646 |
+
@app.post("/medidas")
|
| 647 |
+
def create_medida(medida: Medida):
|
| 648 |
+
try:
|
| 649 |
+
conn = DatabaseConnection().get_connection()
|
| 650 |
+
cursor = conn.cursor()
|
| 651 |
+
cursor.execute(
|
| 652 |
+
"INSERT INTO Medidas (Esfera_OD_lejos, Cilindro_OD_lejos, Eje_OD_lejos, Agudeza_visual_OD_lejos, Esfera_OI_lejos, Cilindro_OI_lejos, Eje_OI_lejos, Agudeza_visual_OI_lejos, Esfera_OD_cerca, Cilindro_OD_cerca, Eje_OD_cerca, Agudeza_visual_OD_cerca, Esfera_OI_cerca, Cilindro_OI_cerca, Eje_OI_cerca, Agudeza_visual_OI_cerca, id_cliente) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
|
| 653 |
+
[
|
| 654 |
+
medida.Esfera_OD_lejos,
|
| 655 |
+
medida.Cilindro_OD_lejos,
|
| 656 |
+
medida.Eje_OD_lejos,
|
| 657 |
+
medida.Agudeza_visual_OD_lejos,
|
| 658 |
+
medida.Esfera_OI_lejos,
|
| 659 |
+
medida.Cilindro_OI_lejos,
|
| 660 |
+
medida.Eje_OI_lejos,
|
| 661 |
+
medida.Agudeza_visual_OI_lejos,
|
| 662 |
+
medida.Esfera_OD_cerca,
|
| 663 |
+
medida.Cilindro_OD_cerca,
|
| 664 |
+
medida.Eje_OD_cerca,
|
| 665 |
+
medida.Agudeza_visual_OD_cerca,
|
| 666 |
+
medida.Esfera_OI_cerca,
|
| 667 |
+
medida.Cilindro_OI_cerca,
|
| 668 |
+
medida.Eje_OI_cerca,
|
| 669 |
+
medida.Agudeza_visual_OI_cerca,
|
| 670 |
+
medida.id_cliente,
|
| 671 |
+
],
|
| 672 |
+
)
|
| 673 |
+
conn.commit()
|
| 674 |
+
return {"mensaje": "Medida creada correctamente"}
|
| 675 |
+
except Exception as e:
|
| 676 |
+
print(e)
|
| 677 |
+
return {"mensaje": "Error al crear la medida"}
|
| 678 |
+
|
| 679 |
+
|
| 680 |
+
# clase medida para el metodo put
|
| 681 |
+
class MedidaPut(BaseModel):
|
| 682 |
+
id_medidas: int
|
| 683 |
+
Esfera_OD_lejos: float
|
| 684 |
+
Cilindro_OD_lejos: float
|
| 685 |
+
Eje_OD_lejos: float
|
| 686 |
+
Agudeza_visual_OD_lejos: float
|
| 687 |
+
Esfera_OI_lejos: float
|
| 688 |
+
Cilindro_OI_lejos: float
|
| 689 |
+
Eje_OI_lejos: float
|
| 690 |
+
Agudeza_visual_OI_lejos: float
|
| 691 |
+
Esfera_OD_cerca: float
|
| 692 |
+
Cilindro_OD_cerca: float
|
| 693 |
+
Eje_OD_cerca: float
|
| 694 |
+
Agudeza_visual_OD_cerca: float
|
| 695 |
+
Esfera_OI_cerca: float
|
| 696 |
+
Cilindro_OI_cerca: float
|
| 697 |
+
Eje_OI_cerca: float
|
| 698 |
+
Agudeza_visual_OI_cerca: float
|
| 699 |
+
id_cliente: int
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
# metodo put de medidas con manejo de errores
|
| 703 |
+
@app.put("/medidas")
|
| 704 |
+
def update_medida(medida: MedidaPut):
|
| 705 |
+
try:
|
| 706 |
+
conn = DatabaseConnection().get_connection()
|
| 707 |
+
cursor = conn.cursor()
|
| 708 |
+
cursor.execute(
|
| 709 |
+
"UPDATE Medidas SET Esfera_OD_lejos = ?, Cilindro_OD_lejos = ?, Eje_OD_lejos = ?, Agudeza_visual_OD_lejos = ?, Esfera_OI_lejos = ?, Cilindro_OI_lejos = ?, Eje_OI_lejos = ?, Agudeza_visual_OI_lejos = ?, Esfera_OD_cerca = ?, Cilindro_OD_cerca = ?, Eje_OD_cerca = ?, Agudeza_visual_OD_cerca = ?, Esfera_OI_cerca = ?, Cilindro_OI_cerca = ?, Eje_OI_cerca = ?, Agudeza_visual_OI_cerca = ?, id_cliente = ? WHERE id_medidas = ?",
|
| 710 |
+
[
|
| 711 |
+
medida.Esfera_OD_lejos,
|
| 712 |
+
medida.Cilindro_OD_lejos,
|
| 713 |
+
medida.Eje_OD_lejos,
|
| 714 |
+
medida.Agudeza_visual_OD_lejos,
|
| 715 |
+
medida.Esfera_OI_lejos,
|
| 716 |
+
medida.Cilindro_OI_lejos,
|
| 717 |
+
medida.Eje_OI_lejos,
|
| 718 |
+
medida.Agudeza_visual_OI_lejos,
|
| 719 |
+
medida.Esfera_OD_cerca,
|
| 720 |
+
medida.Cilindro_OD_cerca,
|
| 721 |
+
medida.Eje_OD_cerca,
|
| 722 |
+
medida.Agudeza_visual_OD_cerca,
|
| 723 |
+
medida.Esfera_OI_cerca,
|
| 724 |
+
medida.Cilindro_OI_cerca,
|
| 725 |
+
medida.Eje_OI_cerca,
|
| 726 |
+
medida.Agudeza_visual_OI_cerca,
|
| 727 |
+
medida.id_cliente,
|
| 728 |
+
medida.id_medidas,
|
| 729 |
+
],
|
| 730 |
+
)
|
| 731 |
+
conn.commit()
|
| 732 |
+
return {"mensaje": "Medida actualizada correctamente"}
|
| 733 |
+
except Exception as e:
|
| 734 |
+
print(e)
|
| 735 |
+
return {"mensaje": "Error al actualizar la medida"}
|
| 736 |
+
|
| 737 |
+
|
| 738 |
+
# metodo delete de medidas con manejo de errores
|
| 739 |
+
@app.delete("/medidas/{id_medidas}")
|
| 740 |
+
def delete_medida(id_medidas: int):
|
| 741 |
+
try:
|
| 742 |
+
conn = DatabaseConnection().get_connection()
|
| 743 |
+
cursor = conn.cursor()
|
| 744 |
+
cursor.execute("DELETE FROM Medidas WHERE id_medidas = ?", [id_medidas])
|
| 745 |
+
conn.commit()
|
| 746 |
+
return {"mensaje": "Medida eliminada correctamente"}
|
| 747 |
+
except Exception as e:
|
| 748 |
+
print(e)
|
| 749 |
+
return {"mensaje": "Error al eliminar la medida"}
|
| 750 |
+
|
| 751 |
+
|
| 752 |
+
"""
|
| 753 |
+
CREATE TABLE Prescripcion (
|
| 754 |
+
id_prescripcion INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 755 |
+
id_medidas INTEGER REFERENCES Medidas(id_medidas),
|
| 756 |
+
detalle_lunas VARCHAR,
|
| 757 |
+
fecha VARCHAR
|
| 758 |
+
);
|
| 759 |
+
"""
|
| 760 |
+
|
| 761 |
+
|
| 762 |
+
# metodo get de prescripciones
|
| 763 |
+
@app.get("/prescripciones")
|
| 764 |
+
def get_prescripciones():
|
| 765 |
+
try:
|
| 766 |
+
conn = DatabaseConnection().get_connection()
|
| 767 |
+
cursor = conn.cursor()
|
| 768 |
+
cursor.execute("SELECT * FROM Prescripcion")
|
| 769 |
+
prescripciones = cursor.fetchall()
|
| 770 |
+
return prescripciones
|
| 771 |
+
except Exception as e:
|
| 772 |
+
print(e)
|
| 773 |
+
return []
|
| 774 |
+
|
| 775 |
+
|
| 776 |
+
# get de prescripciones por id
|
| 777 |
+
@app.get("/prescripciones/{id_prescripcion}")
|
| 778 |
+
def get_prescripcion(id_prescripcion: int):
|
| 779 |
+
try:
|
| 780 |
+
conn = DatabaseConnection().get_connection()
|
| 781 |
+
cursor = conn.cursor()
|
| 782 |
+
cursor.execute(
|
| 783 |
+
"SELECT * FROM Prescripcion WHERE id_prescripcion = ?", [id_prescripcion]
|
| 784 |
+
)
|
| 785 |
+
prescripcion = cursor.fetchone()
|
| 786 |
+
if prescripcion:
|
| 787 |
+
return prescripcion
|
| 788 |
+
else:
|
| 789 |
+
raise HTTPException(status_code=404, detail="Prescripcion no encontrada")
|
| 790 |
+
except Exception as e:
|
| 791 |
+
print(e)
|
| 792 |
+
return []
|
| 793 |
+
|
| 794 |
+
|
| 795 |
+
"""
|
| 796 |
+
CREATE TABLE Prescripcion (
|
| 797 |
+
id_prescripcion INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 798 |
+
id_medidas INTEGER REFERENCES Medidas(id_medidas),
|
| 799 |
+
detalle_lunas VARCHAR,
|
| 800 |
+
fecha VARCHAR
|
| 801 |
+
);
|
| 802 |
+
"""
|
| 803 |
+
|
| 804 |
+
# clase prescripcion para el metodo post
|
| 805 |
+
|
| 806 |
+
|
| 807 |
+
class Prescripcion(BaseModel):
|
| 808 |
+
id_medidas: int
|
| 809 |
+
detalle_lunas: str
|
| 810 |
+
fecha: str
|
| 811 |
+
|
| 812 |
+
|
| 813 |
+
# metodo post de prescripciones con manejo de errores
|
| 814 |
+
@app.post("/prescripciones")
|
| 815 |
+
def create_prescripcion(prescripcion: Prescripcion):
|
| 816 |
+
try:
|
| 817 |
+
conn = DatabaseConnection().get_connection()
|
| 818 |
+
cursor = conn.cursor()
|
| 819 |
+
cursor.execute(
|
| 820 |
+
"INSERT INTO Prescripcion (id_medidas, detalle_lunas, fecha) VALUES (?, ?, ?, ?)",
|
| 821 |
+
[
|
| 822 |
+
prescripcion.id_medidas,
|
| 823 |
+
prescripcion.detalle_lunas,
|
| 824 |
+
prescripcion.fecha,
|
| 825 |
+
],
|
| 826 |
+
)
|
| 827 |
+
conn.commit()
|
| 828 |
+
return {"mensaje": "Prescripcion creada correctamente"}
|
| 829 |
+
except Exception as e:
|
| 830 |
+
print(e)
|
| 831 |
+
return {"mensaje": "Error al crear la prescripcion"}
|
| 832 |
+
|
| 833 |
+
|
| 834 |
+
# clase prescripcion para el metodo put
|
| 835 |
+
class PrescripcionPut(BaseModel):
|
| 836 |
+
id_prescripcion: int
|
| 837 |
+
id_medidas: int
|
| 838 |
+
detalle_lunas: str
|
| 839 |
+
fecha: str
|
| 840 |
+
|
| 841 |
+
|
| 842 |
+
# metodo put de prescripciones con manejo de errores
|
| 843 |
+
@app.put("/prescripciones")
|
| 844 |
+
def update_prescripcion(prescripcion: PrescripcionPut):
|
| 845 |
+
try:
|
| 846 |
+
conn = DatabaseConnection().get_connection()
|
| 847 |
+
cursor = conn.cursor()
|
| 848 |
+
cursor.execute(
|
| 849 |
+
"UPDATE Prescripcion SET id_medidas = ?, detalle_lunas = ?, fecha = ? WHERE id_prescripcion = ?",
|
| 850 |
+
[
|
| 851 |
+
prescripcion.id_medidas,
|
| 852 |
+
prescripcion.detalle_lunas,
|
| 853 |
+
prescripcion.fecha,
|
| 854 |
+
prescripcion.id_prescripcion,
|
| 855 |
+
],
|
| 856 |
+
)
|
| 857 |
+
conn.commit()
|
| 858 |
+
return {"mensaje": "Prescripcion actualizada correctamente"}
|
| 859 |
+
except Exception as e:
|
| 860 |
+
print(e)
|
| 861 |
+
return {"mensaje": "Error al actualizar la prescripcion"}
|
| 862 |
+
|
| 863 |
+
|
| 864 |
+
# metodo delete de prescripciones con manejo de errores
|
| 865 |
+
@app.delete("/prescripciones/{id_prescripcion}")
|
| 866 |
+
def delete_prescripcion(id_prescripcion: int):
|
| 867 |
+
try:
|
| 868 |
+
conn = DatabaseConnection().get_connection()
|
| 869 |
+
cursor = conn.cursor()
|
| 870 |
+
cursor.execute(
|
| 871 |
+
"DELETE FROM Prescripcion WHERE id_prescripcion = ?", [id_prescripcion]
|
| 872 |
+
)
|
| 873 |
+
conn.commit()
|
| 874 |
+
return {"mensaje": "Prescripcion eliminada correctamente"}
|
| 875 |
+
except Exception as e:
|
| 876 |
+
print(e)
|
| 877 |
+
return {"mensaje": "Error al eliminar la prescripcion"}
|
| 878 |
+
|
| 879 |
+
|
| 880 |
+
"""
|
| 881 |
+
CREATE TABLE Gama (
|
| 882 |
+
id_gama INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 883 |
+
gama VARCHAR
|
| 884 |
+
);
|
| 885 |
+
"""
|
| 886 |
+
|
| 887 |
+
|
| 888 |
+
# metodo get de gamas
|
| 889 |
+
@app.get("/gamas")
|
| 890 |
+
def get_gamas():
|
| 891 |
+
try:
|
| 892 |
+
conn = DatabaseConnection().get_connection()
|
| 893 |
+
cursor = conn.cursor()
|
| 894 |
+
cursor.execute("SELECT * FROM Gama")
|
| 895 |
+
gamas = cursor.fetchall()
|
| 896 |
+
return gamas
|
| 897 |
+
except Exception as e:
|
| 898 |
+
print(e)
|
| 899 |
+
return []
|
| 900 |
+
|
| 901 |
+
|
| 902 |
+
# get de gamas por id
|
| 903 |
+
@app.get("/gamas/{id_gama}")
|
| 904 |
+
def get_gama(id_gama: int):
|
| 905 |
+
try:
|
| 906 |
+
conn = DatabaseConnection().get_connection()
|
| 907 |
+
cursor = conn.cursor()
|
| 908 |
+
cursor.execute("SELECT * FROM Gama WHERE id_gama = ?", [id_gama])
|
| 909 |
+
gama = cursor.fetchone()
|
| 910 |
+
if gama:
|
| 911 |
+
return gama
|
| 912 |
+
else:
|
| 913 |
+
raise HTTPException(status_code=404, detail="Gama no encontrada")
|
| 914 |
+
except Exception as e:
|
| 915 |
+
print(e)
|
| 916 |
+
return []
|
| 917 |
+
|
| 918 |
+
|
| 919 |
+
# busqueda por nombre de gama con like con manejo de errores y con metodo get
|
| 920 |
+
@app.get("/gamas/busqueda/{gama}")
|
| 921 |
+
def get_gama_busqueda(gama: str):
|
| 922 |
+
try:
|
| 923 |
+
conn = DatabaseConnection().get_connection()
|
| 924 |
+
cursor = conn.cursor()
|
| 925 |
+
cursor.execute("SELECT * FROM Gama WHERE gama LIKE ?", ["%" + gama + "%"])
|
| 926 |
+
gama = cursor.fetchall()
|
| 927 |
+
if gama:
|
| 928 |
+
return gama
|
| 929 |
+
else:
|
| 930 |
+
raise HTTPException(status_code=404, detail="Gama no encontrada")
|
| 931 |
+
except Exception as e:
|
| 932 |
+
print(e)
|
| 933 |
+
return []
|
| 934 |
+
|
| 935 |
+
|
| 936 |
+
# busqueda por nombre de gama con like con manejo de errores y con metodo post y clase
|
| 937 |
+
class GamaBusqueda(BaseModel):
|
| 938 |
+
gama: str
|
| 939 |
+
|
| 940 |
+
|
| 941 |
+
# metodo post
|
| 942 |
+
@app.post("/gamas/busqueda")
|
| 943 |
+
def get_gama_busqueda(gama: GamaBusqueda):
|
| 944 |
+
try:
|
| 945 |
+
conn = DatabaseConnection().get_connection()
|
| 946 |
+
cursor = conn.cursor()
|
| 947 |
+
cursor.execute("SELECT * FROM Gama WHERE gama LIKE ?", ["%" + gama.gama + "%"])
|
| 948 |
+
gama = cursor.fetchall()
|
| 949 |
+
if gama:
|
| 950 |
+
return gama
|
| 951 |
+
else:
|
| 952 |
+
raise HTTPException(status_code=404, detail="Gama no encontrada")
|
| 953 |
+
except Exception as e:
|
| 954 |
+
print(e)
|
| 955 |
+
return []
|
| 956 |
+
|
| 957 |
+
|
| 958 |
+
# clase gama para el metodo post
|
| 959 |
+
class Gama(BaseModel):
|
| 960 |
+
gama: str
|
| 961 |
+
|
| 962 |
+
|
| 963 |
+
# metodo post de gamas con manejo de errores
|
| 964 |
+
@app.post("/gamas")
|
| 965 |
+
def create_gama(gama: Gama):
|
| 966 |
+
try:
|
| 967 |
+
conn = DatabaseConnection().get_connection()
|
| 968 |
+
cursor = conn.cursor()
|
| 969 |
+
cursor.execute(
|
| 970 |
+
"INSERT INTO Gama (gama) VALUES (?)",
|
| 971 |
+
[
|
| 972 |
+
gama.gama,
|
| 973 |
+
],
|
| 974 |
+
)
|
| 975 |
+
conn.commit()
|
| 976 |
+
return {"mensaje": "Gama creada correctamente"}
|
| 977 |
+
except Exception as e:
|
| 978 |
+
print(e)
|
| 979 |
+
return {"mensaje": "Error al crear la gama"}
|
| 980 |
+
|
| 981 |
+
|
| 982 |
+
# clase gama para el metodo put
|
| 983 |
+
class GamaPut(BaseModel):
|
| 984 |
+
id_gama: int
|
| 985 |
+
gama: str
|
| 986 |
+
|
| 987 |
+
|
| 988 |
+
# metodo put de gamas con manejo de errores
|
| 989 |
+
@app.put("/gamas")
|
| 990 |
+
def update_gama(gama: GamaPut):
|
| 991 |
+
try:
|
| 992 |
+
conn = DatabaseConnection().get_connection()
|
| 993 |
+
cursor = conn.cursor()
|
| 994 |
+
cursor.execute(
|
| 995 |
+
"UPDATE Gama SET gama = ? WHERE id_gama = ?",
|
| 996 |
+
[
|
| 997 |
+
gama.gama,
|
| 998 |
+
gama.id_gama,
|
| 999 |
+
],
|
| 1000 |
+
)
|
| 1001 |
+
conn.commit()
|
| 1002 |
+
return {"mensaje": "Gama actualizada correctamente"}
|
| 1003 |
+
except Exception as e:
|
| 1004 |
+
print(e)
|
| 1005 |
+
return {"mensaje": "Error al actualizar la gama"}
|
| 1006 |
+
|
| 1007 |
+
|
| 1008 |
+
# metodo delete de gamas con manejo de errores
|
| 1009 |
+
@app.delete("/gamas/{id_gama}")
|
| 1010 |
+
def delete_gama(id_gama: int):
|
| 1011 |
+
try:
|
| 1012 |
+
conn = DatabaseConnection().get_connection()
|
| 1013 |
+
cursor = conn.cursor()
|
| 1014 |
+
cursor.execute("DELETE FROM Gama WHERE id_gama = ?", [id_gama])
|
| 1015 |
+
conn.commit()
|
| 1016 |
+
return {"mensaje": "Gama eliminada correctamente"}
|
| 1017 |
+
except Exception as e:
|
| 1018 |
+
print(e)
|
| 1019 |
+
return {"mensaje": "Error al eliminar la gama"}
|
| 1020 |
+
|
| 1021 |
+
|
| 1022 |
+
"""
|
| 1023 |
+
CREATE TABLE Montura (
|
| 1024 |
+
id_montura INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1025 |
+
nombre_montura VARCHAR,
|
| 1026 |
+
id_gama INTEGER REFERENCES Gama(id_gama),
|
| 1027 |
+
imagen VARCHAR
|
| 1028 |
+
);
|
| 1029 |
+
"""
|
| 1030 |
+
|
| 1031 |
+
|
| 1032 |
+
# metodo get de monturas
|
| 1033 |
+
@app.get("/monturas")
|
| 1034 |
+
def get_monturas():
|
| 1035 |
+
try:
|
| 1036 |
+
conn = DatabaseConnection().get_connection()
|
| 1037 |
+
cursor = conn.cursor()
|
| 1038 |
+
cursor.execute("SELECT * FROM Montura")
|
| 1039 |
+
monturas = cursor.fetchall()
|
| 1040 |
+
return monturas
|
| 1041 |
+
except Exception as e:
|
| 1042 |
+
print(e)
|
| 1043 |
+
return []
|
| 1044 |
+
|
| 1045 |
+
|
| 1046 |
+
# get de monturas por id
|
| 1047 |
+
@app.get("/monturas/{id_montura}")
|
| 1048 |
+
def get_montura(id_montura: int):
|
| 1049 |
+
try:
|
| 1050 |
+
conn = DatabaseConnection().get_connection()
|
| 1051 |
+
cursor = conn.cursor()
|
| 1052 |
+
cursor.execute("SELECT * FROM Montura WHERE id_montura = ?", [id_montura])
|
| 1053 |
+
montura = cursor.fetchone()
|
| 1054 |
+
if montura:
|
| 1055 |
+
return montura
|
| 1056 |
+
else:
|
| 1057 |
+
raise HTTPException(status_code=404, detail="Montura no encontrada")
|
| 1058 |
+
except Exception as e:
|
| 1059 |
+
print(e)
|
| 1060 |
+
return []
|
| 1061 |
+
|
| 1062 |
+
|
| 1063 |
+
# busqueda por nombre de montura con like con manejo de errores y con metodo get
|
| 1064 |
+
@app.get("/monturas/busqueda/{nombre_montura}")
|
| 1065 |
+
def get_montura_busqueda(nombre_montura: str):
|
| 1066 |
+
try:
|
| 1067 |
+
conn = DatabaseConnection().get_connection()
|
| 1068 |
+
cursor = conn.cursor()
|
| 1069 |
+
cursor.execute(
|
| 1070 |
+
"SELECT * FROM Montura WHERE nombre_montura LIKE ?",
|
| 1071 |
+
["%" + nombre_montura + "%"],
|
| 1072 |
+
)
|
| 1073 |
+
montura = cursor.fetchall()
|
| 1074 |
+
if montura:
|
| 1075 |
+
return montura
|
| 1076 |
+
else:
|
| 1077 |
+
raise HTTPException(status_code=404, detail="Montura no encontrada")
|
| 1078 |
+
except Exception as e:
|
| 1079 |
+
print(e)
|
| 1080 |
+
return []
|
| 1081 |
+
|
| 1082 |
+
|
| 1083 |
+
# busqueda por nombre de montura con like con manejo de errores y con metodo post y clase
|
| 1084 |
+
class MonturaBusqueda(BaseModel):
|
| 1085 |
+
nombre_montura: str
|
| 1086 |
+
|
| 1087 |
+
|
| 1088 |
+
# metodo post
|
| 1089 |
+
@app.post("/monturas/busqueda")
|
| 1090 |
+
def get_montura_busqueda(montura: MonturaBusqueda):
|
| 1091 |
+
try:
|
| 1092 |
+
conn = DatabaseConnection().get_connection()
|
| 1093 |
+
cursor = conn.cursor()
|
| 1094 |
+
cursor.execute(
|
| 1095 |
+
"SELECT * FROM Montura WHERE nombre_montura LIKE ?",
|
| 1096 |
+
["%" + montura.nombre_montura + "%"],
|
| 1097 |
+
)
|
| 1098 |
+
montura = cursor.fetchall()
|
| 1099 |
+
if montura:
|
| 1100 |
+
return montura
|
| 1101 |
+
else:
|
| 1102 |
+
raise HTTPException(status_code=404, detail="Montura no encontrada")
|
| 1103 |
+
except Exception as e:
|
| 1104 |
+
print(e)
|
| 1105 |
+
return []
|
| 1106 |
+
|
| 1107 |
+
|
| 1108 |
+
# clase montura para el metodo post
|
| 1109 |
+
class Montura(BaseModel):
|
| 1110 |
+
nombre_montura: str
|
| 1111 |
+
id_gama: int
|
| 1112 |
+
imagen: str
|
| 1113 |
+
|
| 1114 |
+
|
| 1115 |
+
# metodo post de monturas con manejo de errores
|
| 1116 |
+
@app.post("/monturas")
|
| 1117 |
+
def create_montura(montura: Montura):
|
| 1118 |
+
try:
|
| 1119 |
+
conn = DatabaseConnection().get_connection()
|
| 1120 |
+
cursor = conn.cursor()
|
| 1121 |
+
cursor.execute(
|
| 1122 |
+
"INSERT INTO Montura (nombre_montura, id_gama, imagen) VALUES (?, ?, ?)",
|
| 1123 |
+
[
|
| 1124 |
+
montura.nombre_montura,
|
| 1125 |
+
montura.id_gama,
|
| 1126 |
+
montura.imagen,
|
| 1127 |
+
],
|
| 1128 |
+
)
|
| 1129 |
+
conn.commit()
|
| 1130 |
+
return {"mensaje": "Montura creada correctamente"}
|
| 1131 |
+
except Exception as e:
|
| 1132 |
+
print(e)
|
| 1133 |
+
return {"mensaje": "Error al crear la montura"}
|
| 1134 |
+
|
| 1135 |
+
|
| 1136 |
+
# clase montura para el metodo put
|
| 1137 |
+
class MonturaPut(BaseModel):
|
| 1138 |
+
id_montura: int
|
| 1139 |
+
nombre_montura: str
|
| 1140 |
+
id_gama: int
|
| 1141 |
+
imagen: str
|
| 1142 |
+
|
| 1143 |
+
|
| 1144 |
+
# metodo put de monturas con manejo de errores
|
| 1145 |
+
@app.put("/monturas")
|
| 1146 |
+
def update_montura(montura: MonturaPut):
|
| 1147 |
+
try:
|
| 1148 |
+
conn = DatabaseConnection().get_connection()
|
| 1149 |
+
cursor = conn.cursor()
|
| 1150 |
+
cursor.execute(
|
| 1151 |
+
"UPDATE Montura SET nombre_montura = ?, id_gama = ?, imagen = ? WHERE id_montura = ?",
|
| 1152 |
+
[
|
| 1153 |
+
montura.nombre_montura,
|
| 1154 |
+
montura.id_gama,
|
| 1155 |
+
montura.imagen,
|
| 1156 |
+
montura.id_montura,
|
| 1157 |
+
],
|
| 1158 |
+
)
|
| 1159 |
+
conn.commit()
|
| 1160 |
+
return {"mensaje": "Montura actualizada correctamente"}
|
| 1161 |
+
except Exception as e:
|
| 1162 |
+
print(e)
|
| 1163 |
+
return {"mensaje": "Error al actualizar la montura"}
|
| 1164 |
+
|
| 1165 |
+
|
| 1166 |
+
# metodo delete de monturas con manejo de errores
|
| 1167 |
+
@app.delete("/monturas/{id_montura}")
|
| 1168 |
+
def delete_montura(id_montura: int):
|
| 1169 |
+
try:
|
| 1170 |
+
conn = DatabaseConnection().get_connection()
|
| 1171 |
+
cursor = conn.cursor()
|
| 1172 |
+
cursor.execute("DELETE FROM Montura WHERE id_montura = ?", [id_montura])
|
| 1173 |
+
conn.commit()
|
| 1174 |
+
return {"mensaje": "Montura eliminada correctamente"}
|
| 1175 |
+
except Exception as e:
|
| 1176 |
+
print(e)
|
| 1177 |
+
return {"mensaje": "Error al eliminar la montura"}
|
| 1178 |
+
|
| 1179 |
+
|
| 1180 |
+
"""
|
| 1181 |
+
CREATE TABLE Montura_inventario (
|
| 1182 |
+
id_montura_inventario INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1183 |
+
id_montura INTEGER REFERENCES Montura(id_montura),
|
| 1184 |
+
precio_unit FLOAT,
|
| 1185 |
+
stock INTEGER,
|
| 1186 |
+
codigo VARCHAR
|
| 1187 |
+
);
|
| 1188 |
+
"""
|
| 1189 |
+
|
| 1190 |
+
|
| 1191 |
+
# metodo get de monturas_inventario
|
| 1192 |
+
@app.get("/monturas_inventario")
|
| 1193 |
+
def get_monturas_inventario():
|
| 1194 |
+
try:
|
| 1195 |
+
conn = DatabaseConnection().get_connection()
|
| 1196 |
+
cursor = conn.cursor()
|
| 1197 |
+
cursor.execute("SELECT * FROM Montura_inventario")
|
| 1198 |
+
monturas_inventario = cursor.fetchall()
|
| 1199 |
+
return monturas_inventario
|
| 1200 |
+
except Exception as e:
|
| 1201 |
+
print(e)
|
| 1202 |
+
return []
|
| 1203 |
+
|
| 1204 |
+
|
| 1205 |
+
# get de monturas_inventario por id
|
| 1206 |
+
@app.get("/monturas_inventario/{id_montura_inventario}")
|
| 1207 |
+
def get_montura_inventario(id_montura_inventario: int):
|
| 1208 |
+
try:
|
| 1209 |
+
conn = DatabaseConnection().get_connection()
|
| 1210 |
+
cursor = conn.cursor()
|
| 1211 |
+
cursor.execute(
|
| 1212 |
+
"SELECT * FROM Montura_inventario WHERE id_montura_inventario = ?",
|
| 1213 |
+
[id_montura_inventario],
|
| 1214 |
+
)
|
| 1215 |
+
montura_inventario = cursor.fetchone()
|
| 1216 |
+
if montura_inventario:
|
| 1217 |
+
return montura_inventario
|
| 1218 |
+
else:
|
| 1219 |
+
raise HTTPException(
|
| 1220 |
+
status_code=404, detail="Montura_inventario no encontrada"
|
| 1221 |
+
)
|
| 1222 |
+
except Exception as e:
|
| 1223 |
+
print(e)
|
| 1224 |
+
return []
|
| 1225 |
+
|
| 1226 |
+
|
| 1227 |
+
# busqueda por codigo de montura con like con manejo de errores y con metodo get
|
| 1228 |
+
@app.get("/monturas_inventario/busqueda/{codigo}")
|
| 1229 |
+
def get_montura_inventario_busqueda(codigo: str):
|
| 1230 |
+
try:
|
| 1231 |
+
conn = DatabaseConnection().get_connection()
|
| 1232 |
+
cursor = conn.cursor()
|
| 1233 |
+
cursor.execute(
|
| 1234 |
+
"SELECT * FROM Montura_inventario WHERE codigo LIKE ?",
|
| 1235 |
+
["%" + codigo + "%"],
|
| 1236 |
+
)
|
| 1237 |
+
montura_inventario = cursor.fetchall()
|
| 1238 |
+
if montura_inventario:
|
| 1239 |
+
return montura_inventario
|
| 1240 |
+
else:
|
| 1241 |
+
raise HTTPException(
|
| 1242 |
+
status_code=404, detail="Montura_inventario no encontrada"
|
| 1243 |
+
)
|
| 1244 |
+
except Exception as e:
|
| 1245 |
+
print(e)
|
| 1246 |
+
return []
|
| 1247 |
+
|
| 1248 |
+
|
| 1249 |
+
# busqueda por codigo de montura con like con manejo de errores y con metodo post y clase
|
| 1250 |
+
class Montura_inventarioBusqueda(BaseModel):
|
| 1251 |
+
codigo: str
|
| 1252 |
+
|
| 1253 |
+
|
| 1254 |
+
# metodo post
|
| 1255 |
+
@app.post("/monturas_inventario/busqueda")
|
| 1256 |
+
def get_montura_inventario_busqueda(montura_inventario: Montura_inventarioBusqueda):
|
| 1257 |
+
try:
|
| 1258 |
+
conn = DatabaseConnection().get_connection()
|
| 1259 |
+
cursor = conn.cursor()
|
| 1260 |
+
cursor.execute(
|
| 1261 |
+
"SELECT * FROM Montura_inventario WHERE codigo LIKE ?",
|
| 1262 |
+
["%" + montura_inventario.codigo + "%"],
|
| 1263 |
+
)
|
| 1264 |
+
montura_inventario = cursor.fetchall()
|
| 1265 |
+
if montura_inventario:
|
| 1266 |
+
return montura_inventario
|
| 1267 |
+
else:
|
| 1268 |
+
raise HTTPException(
|
| 1269 |
+
status_code=404, detail="Montura_inventario no encontrada"
|
| 1270 |
+
)
|
| 1271 |
+
except Exception as e:
|
| 1272 |
+
print(e)
|
| 1273 |
+
return []
|
| 1274 |
+
|
| 1275 |
+
|
| 1276 |
+
# clase montura_inventario para el metodo post
|
| 1277 |
+
class Montura_inventario(BaseModel):
|
| 1278 |
+
id_montura: int
|
| 1279 |
+
precio_unit: float
|
| 1280 |
+
stock: int
|
| 1281 |
+
codigo: str
|
| 1282 |
+
|
| 1283 |
+
|
| 1284 |
+
# metodo post de monturas_inventario con manejo de errores
|
| 1285 |
+
@app.post("/monturas_inventario")
|
| 1286 |
+
def create_montura_inventario(montura_inventario: Montura_inventario):
|
| 1287 |
+
try:
|
| 1288 |
+
conn = DatabaseConnection().get_connection()
|
| 1289 |
+
cursor = conn.cursor()
|
| 1290 |
+
cursor.execute(
|
| 1291 |
+
"INSERT INTO Montura_inventario (id_montura, precio_unit, stock, codigo) VALUES (?, ?, ?, ?)",
|
| 1292 |
+
[
|
| 1293 |
+
montura_inventario.id_montura,
|
| 1294 |
+
montura_inventario.precio_unit,
|
| 1295 |
+
montura_inventario.stock,
|
| 1296 |
+
montura_inventario.codigo,
|
| 1297 |
+
],
|
| 1298 |
+
)
|
| 1299 |
+
conn.commit()
|
| 1300 |
+
return {"mensaje": "Montura_inventario creada correctamente"}
|
| 1301 |
+
except Exception as e:
|
| 1302 |
+
print(e)
|
| 1303 |
+
return {"mensaje": "Error al crear la montura_inventario"}
|
| 1304 |
+
|
| 1305 |
+
|
| 1306 |
+
# clase montura_inventario para el metodo put
|
| 1307 |
+
class Montura_inventarioPut(BaseModel):
|
| 1308 |
+
id_montura_inventario: int
|
| 1309 |
+
id_montura: int
|
| 1310 |
+
precio_unit: float
|
| 1311 |
+
stock: int
|
| 1312 |
+
codigo: str
|
| 1313 |
+
|
| 1314 |
+
|
| 1315 |
+
# metodo put de monturas_inventario con manejo de errores
|
| 1316 |
+
@app.put("/monturas_inventario")
|
| 1317 |
+
def update_montura_inventario(montura_inventario: Montura_inventarioPut):
|
| 1318 |
+
try:
|
| 1319 |
+
conn = DatabaseConnection().get_connection()
|
| 1320 |
+
cursor = conn.cursor()
|
| 1321 |
+
cursor.execute(
|
| 1322 |
+
"UPDATE Montura_inventario SET id_montura = ?, precio_unit = ?, stock = ?, codigo = ? WHERE id_montura_inventario = ?",
|
| 1323 |
+
[
|
| 1324 |
+
montura_inventario.id_montura,
|
| 1325 |
+
montura_inventario.precio_unit,
|
| 1326 |
+
montura_inventario.stock,
|
| 1327 |
+
montura_inventario.codigo,
|
| 1328 |
+
montura_inventario.id_montura_inventario,
|
| 1329 |
+
],
|
| 1330 |
+
)
|
| 1331 |
+
conn.commit()
|
| 1332 |
+
return {"mensaje": "Montura_inventario actualizada correctamente"}
|
| 1333 |
+
except Exception as e:
|
| 1334 |
+
print(e)
|
| 1335 |
+
return {"mensaje": "Error al actualizar la montura_inventario"}
|
| 1336 |
+
|
| 1337 |
+
|
| 1338 |
+
# metodo delete de monturas_inventario con manejo de errores
|
| 1339 |
+
@app.delete("/monturas_inventario/{id_montura_inventario}")
|
| 1340 |
+
def delete_montura_inventario(id_montura_inventario: int):
|
| 1341 |
+
try:
|
| 1342 |
+
conn = DatabaseConnection().get_connection()
|
| 1343 |
+
cursor = conn.cursor()
|
| 1344 |
+
cursor.execute(
|
| 1345 |
+
"DELETE FROM Montura_inventario WHERE id_montura_inventario = ?",
|
| 1346 |
+
[id_montura_inventario],
|
| 1347 |
+
)
|
| 1348 |
+
conn.commit()
|
| 1349 |
+
return {"mensaje": "Montura_inventario eliminada correctamente"}
|
| 1350 |
+
except Exception as e:
|
| 1351 |
+
print(e)
|
| 1352 |
+
return {"mensaje": "Error al eliminar la montura_inventario"}
|
| 1353 |
+
|
| 1354 |
+
|
| 1355 |
+
"""
|
| 1356 |
+
CREATE TABLE boleta (
|
| 1357 |
+
id_boleta INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1358 |
+
precio_total FLOAT,
|
| 1359 |
+
estado_recojo VARCHAR
|
| 1360 |
+
);
|
| 1361 |
+
"""
|
| 1362 |
+
|
| 1363 |
+
|
| 1364 |
+
# metodo get de boletas
|
| 1365 |
+
@app.get("/boletas")
|
| 1366 |
+
def get_boletas():
|
| 1367 |
+
try:
|
| 1368 |
+
conn = DatabaseConnection().get_connection()
|
| 1369 |
+
cursor = conn.cursor()
|
| 1370 |
+
cursor.execute("SELECT * FROM boleta")
|
| 1371 |
+
boletas = cursor.fetchall()
|
| 1372 |
+
return boletas
|
| 1373 |
+
except Exception as e:
|
| 1374 |
+
print(e)
|
| 1375 |
+
return []
|
| 1376 |
+
|
| 1377 |
+
|
| 1378 |
+
# get de boletas por id
|
| 1379 |
+
@app.get("/boletas/{id_boleta}")
|
| 1380 |
+
def get_boleta(id_boleta: int):
|
| 1381 |
+
try:
|
| 1382 |
+
conn = DatabaseConnection().get_connection()
|
| 1383 |
+
cursor = conn.cursor()
|
| 1384 |
+
cursor.execute("SELECT * FROM boleta WHERE id_boleta = ?", [id_boleta])
|
| 1385 |
+
boleta = cursor.fetchone()
|
| 1386 |
+
if boleta:
|
| 1387 |
+
return boleta
|
| 1388 |
+
else:
|
| 1389 |
+
raise HTTPException(status_code=404, detail="Boleta no encontrada")
|
| 1390 |
+
except Exception as e:
|
| 1391 |
+
print(e)
|
| 1392 |
+
return []
|
| 1393 |
+
|
| 1394 |
+
|
| 1395 |
+
# clase boleta para el metodo post
|
| 1396 |
+
class Boleta(BaseModel):
|
| 1397 |
+
precio_total: float
|
| 1398 |
+
estado_recojo: str
|
| 1399 |
+
|
| 1400 |
+
|
| 1401 |
+
# metodo post de boletas con manejo de errores
|
| 1402 |
+
@app.post("/boletas")
|
| 1403 |
+
def create_boleta(boleta: Boleta):
|
| 1404 |
+
try:
|
| 1405 |
+
conn = DatabaseConnection().get_connection()
|
| 1406 |
+
cursor = conn.cursor()
|
| 1407 |
+
cursor.execute(
|
| 1408 |
+
"INSERT INTO boleta (precio_total, estado_recojo) VALUES (?, ?)",
|
| 1409 |
+
[
|
| 1410 |
+
boleta.precio_total,
|
| 1411 |
+
boleta.estado_recojo,
|
| 1412 |
+
],
|
| 1413 |
+
)
|
| 1414 |
+
conn.commit()
|
| 1415 |
+
return {"mensaje": "Boleta creada correctamente"}
|
| 1416 |
+
except Exception as e:
|
| 1417 |
+
print(e)
|
| 1418 |
+
return {"mensaje": "Error al crear la boleta"}
|
| 1419 |
+
|
| 1420 |
+
|
| 1421 |
+
# clase boleta para el metodo put
|
| 1422 |
+
class BoletaPut(BaseModel):
|
| 1423 |
+
id_boleta: int
|
| 1424 |
+
precio_total: float
|
| 1425 |
+
estado_recojo: str
|
| 1426 |
+
|
| 1427 |
+
|
| 1428 |
+
# metodo put de boletas con manejo de errores
|
| 1429 |
+
@app.put("/boletas")
|
| 1430 |
+
def update_boleta(boleta: BoletaPut):
|
| 1431 |
+
try:
|
| 1432 |
+
conn = DatabaseConnection().get_connection()
|
| 1433 |
+
cursor = conn.cursor()
|
| 1434 |
+
cursor.execute(
|
| 1435 |
+
"UPDATE boleta SET precio_total = ?, estado_recojo = ? WHERE id_boleta = ?",
|
| 1436 |
+
[
|
| 1437 |
+
boleta.precio_total,
|
| 1438 |
+
boleta.estado_recojo,
|
| 1439 |
+
boleta.id_boleta,
|
| 1440 |
+
],
|
| 1441 |
+
)
|
| 1442 |
+
conn.commit()
|
| 1443 |
+
return {"mensaje": "Boleta actualizada correctamente"}
|
| 1444 |
+
except Exception as e:
|
| 1445 |
+
print(e)
|
| 1446 |
+
return {"mensaje": "Error al actualizar la boleta"}
|
| 1447 |
+
|
| 1448 |
+
|
| 1449 |
+
# metodo delete de boletas con manejo de errores
|
| 1450 |
+
@app.delete("/boletas/{id_boleta}")
|
| 1451 |
+
def delete_boleta(id_boleta: int):
|
| 1452 |
+
try:
|
| 1453 |
+
conn = DatabaseConnection().get_connection()
|
| 1454 |
+
cursor = conn.cursor()
|
| 1455 |
+
cursor.execute("DELETE FROM boleta WHERE id_boleta = ?", [id_boleta])
|
| 1456 |
+
conn.commit()
|
| 1457 |
+
return {"mensaje": "Boleta eliminada correctamente"}
|
| 1458 |
+
except Exception as e:
|
| 1459 |
+
print(e)
|
| 1460 |
+
return {"mensaje": "Error al eliminar la boleta"}
|
| 1461 |
+
|
| 1462 |
+
|
| 1463 |
+
"""
|
| 1464 |
+
CREATE TABLE montura_pedido (
|
| 1465 |
+
id_montura_pedido INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1466 |
+
id_montura_inventario INTEGER REFERENCES Montura_inventario(id_montura_inventario),
|
| 1467 |
+
cantidad INTEGER,
|
| 1468 |
+
precio FLOAT,
|
| 1469 |
+
id_boleta INTEGER REFERENCES boleta(id_boleta)
|
| 1470 |
+
);
|
| 1471 |
+
"""
|
| 1472 |
+
|
| 1473 |
+
|
| 1474 |
+
# metodo get de monturas_pedido
|
| 1475 |
+
@app.get("/monturas_pedido")
|
| 1476 |
+
def get_monturas_pedido():
|
| 1477 |
+
try:
|
| 1478 |
+
conn = DatabaseConnection().get_connection()
|
| 1479 |
+
cursor = conn.cursor()
|
| 1480 |
+
cursor.execute("SELECT * FROM montura_pedido")
|
| 1481 |
+
monturas_pedido = cursor.fetchall()
|
| 1482 |
+
return monturas_pedido
|
| 1483 |
+
except Exception as e:
|
| 1484 |
+
print(e)
|
| 1485 |
+
return []
|
| 1486 |
+
|
| 1487 |
+
|
| 1488 |
+
# get de monturas_pedido por id
|
| 1489 |
+
@app.get("/monturas_pedido/{id_montura_pedido}")
|
| 1490 |
+
def get_montura_pedido(id_montura_pedido: int):
|
| 1491 |
+
try:
|
| 1492 |
+
conn = DatabaseConnection().get_connection()
|
| 1493 |
+
cursor = conn.cursor()
|
| 1494 |
+
cursor.execute(
|
| 1495 |
+
"SELECT * FROM montura_pedido WHERE id_montura_pedido = ?",
|
| 1496 |
+
[id_montura_pedido],
|
| 1497 |
+
)
|
| 1498 |
+
montura_pedido = cursor.fetchone()
|
| 1499 |
+
if montura_pedido:
|
| 1500 |
+
return montura_pedido
|
| 1501 |
+
else:
|
| 1502 |
+
raise HTTPException(status_code=404, detail="Montura_pedido no encontrada")
|
| 1503 |
+
except Exception as e:
|
| 1504 |
+
print(e)
|
| 1505 |
+
return []
|
| 1506 |
+
|
| 1507 |
+
|
| 1508 |
+
# clase montura_pedido para el metodo post
|
| 1509 |
+
class Montura_pedido(BaseModel):
|
| 1510 |
+
id_montura_inventario: int
|
| 1511 |
+
cantidad: int
|
| 1512 |
+
precio: float
|
| 1513 |
+
id_boleta: int
|
| 1514 |
+
|
| 1515 |
+
|
| 1516 |
+
# metodo post de monturas_pedido con manejo de errores
|
| 1517 |
+
@app.post("/monturas_pedido")
|
| 1518 |
+
def create_montura_pedido(montura_pedido: Montura_pedido):
|
| 1519 |
+
try:
|
| 1520 |
+
conn = DatabaseConnection().get_connection()
|
| 1521 |
+
cursor = conn.cursor()
|
| 1522 |
+
cursor.execute(
|
| 1523 |
+
"INSERT INTO montura_pedido (id_montura_inventario, cantidad, precio, id_boleta) VALUES (?, ?, ?, ?)",
|
| 1524 |
+
[
|
| 1525 |
+
montura_pedido.id_montura_inventario,
|
| 1526 |
+
montura_pedido.cantidad,
|
| 1527 |
+
montura_pedido.precio,
|
| 1528 |
+
montura_pedido.id_boleta,
|
| 1529 |
+
],
|
| 1530 |
+
)
|
| 1531 |
+
conn.commit()
|
| 1532 |
+
return {"mensaje": "Montura_pedido creada correctamente"}
|
| 1533 |
+
except Exception as e:
|
| 1534 |
+
print(e)
|
| 1535 |
+
return {"mensaje": "Error al crear la montura_pedido"}
|
| 1536 |
+
|
| 1537 |
+
|
| 1538 |
+
# clase montura_pedido para el metodo put
|
| 1539 |
+
class Montura_pedidoPut(BaseModel):
|
| 1540 |
+
id_montura_pedido: int
|
| 1541 |
+
id_montura_inventario: int
|
| 1542 |
+
cantidad: int
|
| 1543 |
+
precio: float
|
| 1544 |
+
id_boleta: int
|
| 1545 |
+
|
| 1546 |
+
|
| 1547 |
+
# metodo put de monturas_pedido con manejo de errores
|
| 1548 |
+
@app.put("/monturas_pedido")
|
| 1549 |
+
def update_montura_pedido(montura_pedido: Montura_pedidoPut):
|
| 1550 |
+
try:
|
| 1551 |
+
conn = DatabaseConnection().get_connection()
|
| 1552 |
+
cursor = conn.cursor()
|
| 1553 |
+
cursor.execute(
|
| 1554 |
+
"UPDATE montura_pedido SET id_montura_inventario = ?, cantidad = ?, precio = ?, id_boleta = ? WHERE id_montura_pedido = ?",
|
| 1555 |
+
[
|
| 1556 |
+
montura_pedido.id_montura_inventario,
|
| 1557 |
+
montura_pedido.cantidad,
|
| 1558 |
+
montura_pedido.precio,
|
| 1559 |
+
montura_pedido.id_boleta,
|
| 1560 |
+
montura_pedido.id_montura_pedido,
|
| 1561 |
+
],
|
| 1562 |
+
)
|
| 1563 |
+
conn.commit()
|
| 1564 |
+
return {"mensaje": "Montura_pedido actualizada correctamente"}
|
| 1565 |
+
except Exception as e:
|
| 1566 |
+
print(e)
|
| 1567 |
+
return {"mensaje": "Error al actualizar la montura_pedido"}
|
| 1568 |
+
|
| 1569 |
+
|
| 1570 |
+
# metodo delete de monturas_pedido con manejo de errores
|
| 1571 |
+
@app.delete("/monturas_pedido/{id_montura_pedido}")
|
| 1572 |
+
def delete_montura_pedido(id_montura_pedido: int):
|
| 1573 |
+
try:
|
| 1574 |
+
conn = DatabaseConnection().get_connection()
|
| 1575 |
+
cursor = conn.cursor()
|
| 1576 |
+
cursor.execute(
|
| 1577 |
+
"DELETE FROM montura_pedido WHERE id_montura_pedido = ?",
|
| 1578 |
+
[id_montura_pedido],
|
| 1579 |
+
)
|
| 1580 |
+
conn.commit()
|
| 1581 |
+
return {"mensaje": "Montura_pedido eliminada correctamente"}
|
| 1582 |
+
except Exception as e:
|
| 1583 |
+
print(e)
|
| 1584 |
+
return {"mensaje": "Error al eliminar la montura_pedido"}
|
| 1585 |
+
|
| 1586 |
+
|
| 1587 |
+
"""
|
| 1588 |
+
CREATE TABLE lunas_pedido (
|
| 1589 |
+
id_lunas_pedido INTEGER PRIMARY KEY AUTOINCREMENT,
|
| 1590 |
+
id_prescripcion INTEGER REFERENCES Prescripcion(id_prescripcion),
|
| 1591 |
+
precio FLOAT,
|
| 1592 |
+
id_boleta INTEGER REFERENCES boleta(id_boleta),
|
| 1593 |
+
descripcion VARCHAR
|
| 1594 |
+
);
|
| 1595 |
+
"""
|
| 1596 |
+
|
| 1597 |
+
|
| 1598 |
+
# metodo get de lunas_pedido
|
| 1599 |
+
@app.get("/lunas_pedido")
|
| 1600 |
+
def get_lunas_pedido():
|
| 1601 |
+
try:
|
| 1602 |
+
conn = DatabaseConnection().get_connection()
|
| 1603 |
+
cursor = conn.cursor()
|
| 1604 |
+
cursor.execute("SELECT * FROM lunas_pedido")
|
| 1605 |
+
lunas_pedido = cursor.fetchall()
|
| 1606 |
+
return lunas_pedido
|
| 1607 |
+
except Exception as e:
|
| 1608 |
+
print(e)
|
| 1609 |
+
return []
|
| 1610 |
+
|
| 1611 |
+
|
| 1612 |
+
# get de lunas_pedido por id
|
| 1613 |
+
@app.get("/lunas_pedido/{id_lunas_pedido}")
|
| 1614 |
+
def get_lunas_pedido(id_lunas_pedido: int):
|
| 1615 |
+
try:
|
| 1616 |
+
conn = DatabaseConnection().get_connection()
|
| 1617 |
+
cursor = conn.cursor()
|
| 1618 |
+
cursor.execute(
|
| 1619 |
+
"SELECT * FROM lunas_pedido WHERE id_lunas_pedido = ?", [id_lunas_pedido]
|
| 1620 |
+
)
|
| 1621 |
+
luna_pedido = cursor.fetchone()
|
| 1622 |
+
if luna_pedido:
|
| 1623 |
+
return luna_pedido
|
| 1624 |
+
else:
|
| 1625 |
+
raise HTTPException(status_code=404, detail="Lunas_pedido no encontrada")
|
| 1626 |
+
except Exception as e:
|
| 1627 |
+
print(e)
|
| 1628 |
+
return []
|
| 1629 |
+
|
| 1630 |
+
|
| 1631 |
+
# clase lunas_pedido para el metodo post
|
| 1632 |
+
class Lunas_pedido(BaseModel):
|
| 1633 |
+
id_prescripcion: int
|
| 1634 |
+
precio: float
|
| 1635 |
+
id_boleta: int
|
| 1636 |
+
descripcion: str
|
| 1637 |
+
|
| 1638 |
+
|
| 1639 |
+
# metodo post de lunas_pedido con manejo de errores
|
| 1640 |
+
@app.post("/lunas_pedido")
|
| 1641 |
+
def create_lunas_pedido(lunas_pedido: Lunas_pedido):
|
| 1642 |
+
try:
|
| 1643 |
+
conn = DatabaseConnection().get_connection()
|
| 1644 |
+
cursor = conn.cursor()
|
| 1645 |
+
cursor.execute(
|
| 1646 |
+
"INSERT INTO lunas_pedido (id_prescripcion, precio, id_boleta, descripcion) VALUES (?, ?, ?, ?)",
|
| 1647 |
+
[
|
| 1648 |
+
lunas_pedido.id_prescripcion,
|
| 1649 |
+
lunas_pedido.precio,
|
| 1650 |
+
lunas_pedido.id_boleta,
|
| 1651 |
+
lunas_pedido.descripcion,
|
| 1652 |
+
],
|
| 1653 |
+
)
|
| 1654 |
+
conn.commit()
|
| 1655 |
+
return {"mensaje": "Lunas_pedido creada correctamente"}
|
| 1656 |
+
except Exception as e:
|
| 1657 |
+
print(e)
|
| 1658 |
+
return {"mensaje": "Error al crear la lunas_pedido"}
|
| 1659 |
+
|
| 1660 |
+
|
| 1661 |
+
# clase lunas_pedido para el metodo put
|
| 1662 |
+
class Lunas_pedidoPut(BaseModel):
|
| 1663 |
+
id_lunas_pedido: int
|
| 1664 |
+
id_prescripcion: int
|
| 1665 |
+
precio: float
|
| 1666 |
+
id_boleta: int
|
| 1667 |
+
descripcion: str
|
| 1668 |
+
|
| 1669 |
+
|
| 1670 |
+
# metodo put de lunas_pedido con manejo de errores
|
| 1671 |
+
@app.put("/lunas_pedido")
|
| 1672 |
+
def update_lunas_pedido(lunas_pedido: Lunas_pedidoPut):
|
| 1673 |
+
try:
|
| 1674 |
+
conn = DatabaseConnection().get_connection()
|
| 1675 |
+
cursor = conn.cursor()
|
| 1676 |
+
cursor.execute(
|
| 1677 |
+
"UPDATE lunas_pedido SET id_prescripcion = ?, precio = ?, id_boleta = ?, descripcion = ? WHERE id_lunas_pedido = ?",
|
| 1678 |
+
[
|
| 1679 |
+
lunas_pedido.id_prescripcion,
|
| 1680 |
+
lunas_pedido.precio,
|
| 1681 |
+
lunas_pedido.id_boleta,
|
| 1682 |
+
lunas_pedido.descripcion,
|
| 1683 |
+
lunas_pedido.id_lunas_pedido,
|
| 1684 |
+
],
|
| 1685 |
+
)
|
| 1686 |
+
conn.commit()
|
| 1687 |
+
return {"mensaje": "Lunas_pedido actualizada correctamente"}
|
| 1688 |
+
except Exception as e:
|
| 1689 |
+
print(e)
|
| 1690 |
+
return {"mensaje": "Error al actualizar la lunas_pedido"}
|
| 1691 |
+
|
| 1692 |
+
|
| 1693 |
+
# metodo delete de lunas_pedido con manejo de errores
|
| 1694 |
+
@app.delete("/lunas_pedido/{id_lunas_pedido}")
|
| 1695 |
+
def delete_lunas_pedido(id_lunas_pedido: int):
|
| 1696 |
+
try:
|
| 1697 |
+
conn = DatabaseConnection().get_connection()
|
| 1698 |
+
cursor = conn.cursor()
|
| 1699 |
+
cursor.execute(
|
| 1700 |
+
"DELETE FROM lunas_pedido WHERE id_lunas_pedido = ?", [id_lunas_pedido]
|
| 1701 |
+
)
|
| 1702 |
+
conn.commit()
|
| 1703 |
+
return {"mensaje": "Lunas_pedido eliminada correctamente"}
|
| 1704 |
+
except Exception as e:
|
| 1705 |
+
print(e)
|
| 1706 |
+
return {"mensaje": "Error al eliminar la lunas_pedido"}
|
optica.db
ADDED
|
Binary file (53.2 kB). View file
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
reportlab
|