ajuste de cruds incompleto
This commit is contained in:
116
output/generated/routers/branches_router.py
Normal file
116
output/generated/routers/branches_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.branches.models import Branches
|
||||
from app.modules.branches.schema import , Response
|
||||
from app.modules.branches.services import BranchesService
|
||||
|
||||
router = APIRouter(prefix="/branches", tags=["branches"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_branches(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a branches - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create branches")
|
||||
|
||||
try:
|
||||
result = BranchesService.create_branches(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_branchess(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return BranchesService.get_branchess(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_branches_by_id(
|
||||
branches_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get branches by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = BranchesService.get_branches(db=db, branches_id=branches_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_branches(
|
||||
branches_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing branches - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update branches")
|
||||
|
||||
try:
|
||||
result = BranchesService.update_branches(
|
||||
db=db,
|
||||
branches_id=branches_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_branches(
|
||||
branches_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete branches by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete branches")
|
||||
|
||||
try:
|
||||
result = BranchesService.delete_branches(db=db, branches_id=branches_id, current_user=current_user)
|
||||
return {"message": "branches deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
117
output/generated/routers/client_router.py
Normal file
117
output/generated/routers/client_router.py
Normal file
@@ -0,0 +1,117 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.client.models import Client
|
||||
from app.modules.client.schema import , Response
|
||||
from app.modules.client.services import ClientService
|
||||
|
||||
router = APIRouter(prefix="/client", tags=["client"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_client(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a client - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create client")
|
||||
|
||||
try:
|
||||
result = ClientService.create_client(db=db, data=data)
|
||||
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_clients(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return ClientService.get_clients(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/client_id}", response_model=Response)
|
||||
def get_client_by_id(
|
||||
client_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get client by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = ClientService.get_client(db=db, client_id=client_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/client_id}", response_model=Response)
|
||||
async def update_client(
|
||||
client_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing client - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update client")
|
||||
|
||||
try:
|
||||
result = ClientService.update_client(
|
||||
db=db,
|
||||
client_id=client_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/client_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_client(
|
||||
client_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete client by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete client")
|
||||
|
||||
try:
|
||||
result = ClientService.delete_client(db=db, client_id=client_id, current_user=current_user)
|
||||
return {"message": "client deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/coments_router.py
Normal file
116
output/generated/routers/coments_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.coments.models import Coments
|
||||
from app.modules.coments.schema import , Response
|
||||
from app.modules.coments.services import ComentsService
|
||||
|
||||
router = APIRouter(prefix="/coments", tags=["coments"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_coments(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a coments - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create coments")
|
||||
|
||||
try:
|
||||
result = ComentsService.create_coments(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_comentss(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return ComentsService.get_comentss(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_coments_by_id(
|
||||
coments_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get coments by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = ComentsService.get_coments(db=db, coments_id=coments_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_coments(
|
||||
coments_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing coments - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update coments")
|
||||
|
||||
try:
|
||||
result = ComentsService.update_coments(
|
||||
db=db,
|
||||
coments_id=coments_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_coments(
|
||||
coments_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete coments by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete coments")
|
||||
|
||||
try:
|
||||
result = ComentsService.delete_coments(db=db, coments_id=coments_id, current_user=current_user)
|
||||
return {"message": "coments deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/configuration_router.py
Normal file
116
output/generated/routers/configuration_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.configuration.models import Configuration
|
||||
from app.modules.configuration.schema import , Response
|
||||
from app.modules.configuration.services import ConfigurationService
|
||||
|
||||
router = APIRouter(prefix="/configuration", tags=["configuration"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_configuration(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a configuration - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create configuration")
|
||||
|
||||
try:
|
||||
result = ConfigurationService.create_configuration(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_configurations(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return ConfigurationService.get_configurations(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_configuration_by_id(
|
||||
configuration_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get configuration by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = ConfigurationService.get_configuration(db=db, configuration_id=configuration_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_configuration(
|
||||
configuration_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing configuration - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update configuration")
|
||||
|
||||
try:
|
||||
result = ConfigurationService.update_configuration(
|
||||
db=db,
|
||||
configuration_id=configuration_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_configuration(
|
||||
configuration_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete configuration by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete configuration")
|
||||
|
||||
try:
|
||||
result = ConfigurationService.delete_configuration(db=db, configuration_id=configuration_id, current_user=current_user)
|
||||
return {"message": "configuration deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/credits_router.py
Normal file
116
output/generated/routers/credits_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.credits.models import Credits
|
||||
from app.modules.credits.schema import , Response
|
||||
from app.modules.credits.services import CreditsService
|
||||
|
||||
router = APIRouter(prefix="/credits", tags=["credits"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_credits(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a credits - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create credits")
|
||||
|
||||
try:
|
||||
result = CreditsService.create_credits(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_creditss(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return CreditsService.get_creditss(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_credits_by_id(
|
||||
credits_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get credits by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = CreditsService.get_credits(db=db, credits_id=credits_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_credits(
|
||||
credits_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing credits - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update credits")
|
||||
|
||||
try:
|
||||
result = CreditsService.update_credits(
|
||||
db=db,
|
||||
credits_id=credits_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_credits(
|
||||
credits_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete credits by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete credits")
|
||||
|
||||
try:
|
||||
result = CreditsService.delete_credits(db=db, credits_id=credits_id, current_user=current_user)
|
||||
return {"message": "credits deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/edos_router.py
Normal file
116
output/generated/routers/edos_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.edos.models import EDOS
|
||||
from app.modules.edos.schema import , Response
|
||||
from app.modules.edos.services import EDOSService
|
||||
|
||||
router = APIRouter(prefix="/edos", tags=["edos"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_edos(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a edos - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create edos")
|
||||
|
||||
try:
|
||||
result = EDOSService.create_edos(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_edoss(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return EDOSService.get_edoss(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_edos_by_id(
|
||||
edos_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get edos by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = EDOSService.get_edos(db=db, edos_id=edos_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_edos(
|
||||
edos_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing edos - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update edos")
|
||||
|
||||
try:
|
||||
result = EDOSService.update_edos(
|
||||
db=db,
|
||||
edos_id=edos_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_edos(
|
||||
edos_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete edos by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete edos")
|
||||
|
||||
try:
|
||||
result = EDOSService.delete_edos(db=db, edos_id=edos_id, current_user=current_user)
|
||||
return {"message": "edos deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/efos_router.py
Normal file
116
output/generated/routers/efos_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.efos.models import EFOS
|
||||
from app.modules.efos.schema import , Response
|
||||
from app.modules.efos.services import EFOSService
|
||||
|
||||
router = APIRouter(prefix="/efos", tags=["efos"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_efos(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a efos - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create efos")
|
||||
|
||||
try:
|
||||
result = EFOSService.create_efos(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_efoss(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return EFOSService.get_efoss(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_efos_by_id(
|
||||
efos_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get efos by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = EFOSService.get_efos(db=db, efos_id=efos_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_efos(
|
||||
efos_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing efos - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update efos")
|
||||
|
||||
try:
|
||||
result = EFOSService.update_efos(
|
||||
db=db,
|
||||
efos_id=efos_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_efos(
|
||||
efos_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete efos by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete efos")
|
||||
|
||||
try:
|
||||
result = EFOSService.delete_efos(db=db, efos_id=efos_id, current_user=current_user)
|
||||
return {"message": "efos deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/feed_router.py
Normal file
116
output/generated/routers/feed_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.feed.models import Feed
|
||||
from app.modules.feed.schema import , Response
|
||||
from app.modules.feed.services import FeedService
|
||||
|
||||
router = APIRouter(prefix="/feed", tags=["feed"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_feed(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a feed - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create feed")
|
||||
|
||||
try:
|
||||
result = FeedService.create_feed(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_feeds(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return FeedService.get_feeds(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_feed_by_id(
|
||||
feed_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get feed by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = FeedService.get_feed(db=db, feed_id=feed_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_feed(
|
||||
feed_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing feed - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update feed")
|
||||
|
||||
try:
|
||||
result = FeedService.update_feed(
|
||||
db=db,
|
||||
feed_id=feed_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_feed(
|
||||
feed_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete feed by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete feed")
|
||||
|
||||
try:
|
||||
result = FeedService.delete_feed(db=db, feed_id=feed_id, current_user=current_user)
|
||||
return {"message": "feed deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/files_router.py
Normal file
116
output/generated/routers/files_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.files.models import Files
|
||||
from app.modules.files.schema import , Response
|
||||
from app.modules.files.services import FilesService
|
||||
|
||||
router = APIRouter(prefix="/files", tags=["files"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_files(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a files - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create files")
|
||||
|
||||
try:
|
||||
result = FilesService.create_files(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_filess(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return FilesService.get_filess(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_files_by_id(
|
||||
files_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get files by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = FilesService.get_files(db=db, files_id=files_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_files(
|
||||
files_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing files - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update files")
|
||||
|
||||
try:
|
||||
result = FilesService.update_files(
|
||||
db=db,
|
||||
files_id=files_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_files(
|
||||
files_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete files by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete files")
|
||||
|
||||
try:
|
||||
result = FilesService.delete_files(db=db, files_id=files_id, current_user=current_user)
|
||||
return {"message": "files deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/invoices_router.py
Normal file
116
output/generated/routers/invoices_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.invoices.models import Invoices
|
||||
from app.modules.invoices.schema import , Response
|
||||
from app.modules.invoices.services import InvoicesService
|
||||
|
||||
router = APIRouter(prefix="/invoices", tags=["invoices"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_invoices(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a invoices - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create invoices")
|
||||
|
||||
try:
|
||||
result = InvoicesService.create_invoices(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_invoicess(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return InvoicesService.get_invoicess(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_invoices_by_id(
|
||||
invoices_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get invoices by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = InvoicesService.get_invoices(db=db, invoices_id=invoices_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_invoices(
|
||||
invoices_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing invoices - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update invoices")
|
||||
|
||||
try:
|
||||
result = InvoicesService.update_invoices(
|
||||
db=db,
|
||||
invoices_id=invoices_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_invoices(
|
||||
invoices_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete invoices by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete invoices")
|
||||
|
||||
try:
|
||||
result = InvoicesService.delete_invoices(db=db, invoices_id=invoices_id, current_user=current_user)
|
||||
return {"message": "invoices deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/license_router.py
Normal file
116
output/generated/routers/license_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.license.models import License
|
||||
from app.modules.license.schema import , Response
|
||||
from app.modules.license.services import LicenseService
|
||||
|
||||
router = APIRouter(prefix="/license", tags=["license"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_license(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a license - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create license")
|
||||
|
||||
try:
|
||||
result = LicenseService.create_license(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_licenses(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return LicenseService.get_licenses(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_license_by_id(
|
||||
license_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get license by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = LicenseService.get_license(db=db, license_id=license_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_license(
|
||||
license_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing license - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update license")
|
||||
|
||||
try:
|
||||
result = LicenseService.update_license(
|
||||
db=db,
|
||||
license_id=license_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_license(
|
||||
license_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete license by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete license")
|
||||
|
||||
try:
|
||||
result = LicenseService.delete_license(db=db, license_id=license_id, current_user=current_user)
|
||||
return {"message": "license deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/locations_router.py
Normal file
116
output/generated/routers/locations_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.locations.models import Locations
|
||||
from app.modules.locations.schema import , Response
|
||||
from app.modules.locations.services import LocationsService
|
||||
|
||||
router = APIRouter(prefix="/locations", tags=["locations"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_locations(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a locations - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create locations")
|
||||
|
||||
try:
|
||||
result = LocationsService.create_locations(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_locationss(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return LocationsService.get_locationss(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_locations_by_id(
|
||||
locations_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get locations by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = LocationsService.get_locations(db=db, locations_id=locations_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_locations(
|
||||
locations_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing locations - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update locations")
|
||||
|
||||
try:
|
||||
result = LocationsService.update_locations(
|
||||
db=db,
|
||||
locations_id=locations_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_locations(
|
||||
locations_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete locations by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete locations")
|
||||
|
||||
try:
|
||||
result = LocationsService.delete_locations(db=db, locations_id=locations_id, current_user=current_user)
|
||||
return {"message": "locations deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/moves_router.py
Normal file
116
output/generated/routers/moves_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.moves.models import Moves
|
||||
from app.modules.moves.schema import , Response
|
||||
from app.modules.moves.services import MovesService
|
||||
|
||||
router = APIRouter(prefix="/moves", tags=["moves"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_moves(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a moves - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create moves")
|
||||
|
||||
try:
|
||||
result = MovesService.create_moves(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_movess(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return MovesService.get_movess(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_moves_by_id(
|
||||
moves_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get moves by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = MovesService.get_moves(db=db, moves_id=moves_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_moves(
|
||||
moves_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing moves - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update moves")
|
||||
|
||||
try:
|
||||
result = MovesService.update_moves(
|
||||
db=db,
|
||||
moves_id=moves_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_moves(
|
||||
moves_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete moves by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete moves")
|
||||
|
||||
try:
|
||||
result = MovesService.delete_moves(db=db, moves_id=moves_id, current_user=current_user)
|
||||
return {"message": "moves deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
116
output/generated/routers/suppliers_router.py
Normal file
116
output/generated/routers/suppliers_router.py
Normal file
@@ -0,0 +1,116 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Header, status
|
||||
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional, List
|
||||
#
|
||||
from database import get_db
|
||||
from app.core.auth import get_current_user
|
||||
from app.models.user import User # Modelo base de usuario
|
||||
from app.modules.suppliers.models import Suppliers
|
||||
from app.modules.suppliers.schema import , Response
|
||||
from app.modules.suppliers.services import SuppliersService
|
||||
|
||||
router = APIRouter(prefix="/suppliers", tags=["suppliers"])
|
||||
security = HTTPBearer()
|
||||
|
||||
#================ Create ====================
|
||||
@router.post("/create", response_model=Response, status_code=status.HTTP_201_CREATED)
|
||||
async def create_suppliers(
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Create a suppliers - Requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="User not found - invalid token")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to create suppliers")
|
||||
|
||||
try:
|
||||
result = SuppliersService.create_suppliers(db=db, data=data)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=400, detail=str(e))
|
||||
|
||||
#================ Get ====================
|
||||
@router.get("/", response_model=List[Response])
|
||||
def get_supplierss(
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=1000, description="Max number of records to return")
|
||||
):
|
||||
"""Get list with pagination - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
return SuppliersService.get_supplierss(db=db, skip=skip, limit=limit)
|
||||
|
||||
#================ Get by ID ====================
|
||||
@router.get("/{{{entity_name}}_id}", response_model=Response)
|
||||
def get_suppliers_by_id(
|
||||
suppliers_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Get suppliers by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
try:
|
||||
result = SuppliersService.get_suppliers(db=db, suppliers_id=suppliers_id, current_user=current_user)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Update ====================
|
||||
@router.patch("/update/{{{entity_name}}_id}", response_model=Response)
|
||||
async def update_suppliers(
|
||||
suppliers_id: int,
|
||||
data: ,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Update existing suppliers - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to update suppliers")
|
||||
|
||||
try:
|
||||
result = SuppliersService.update_suppliers(
|
||||
db=db,
|
||||
suppliers_id=suppliers_id,
|
||||
data=data,
|
||||
current_user=current_user
|
||||
)
|
||||
return result
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
|
||||
#================ Delete ====================
|
||||
@router.delete("/delete/{{{entity_name}}_id}", status_code=status.HTTP_200_OK)
|
||||
async def delete_suppliers(
|
||||
suppliers_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Delete suppliers by ID - requires authentication"""
|
||||
|
||||
if not current_user:
|
||||
raise HTTPException(status_code=401, detail="Authentication required")
|
||||
|
||||
if current_user.tipo_usuario not in ["root", "admin"]:
|
||||
raise HTTPException(status_code=403, detail="You don't have permission to delete suppliers")
|
||||
|
||||
try:
|
||||
result = SuppliersService.delete_suppliers(db=db, suppliers_id=suppliers_id, current_user=current_user)
|
||||
return {"message": "suppliers deleted successfully"}
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=404, detail=str(e))
|
||||
67
output/generated/services/branches_service.py
Normal file
67
output/generated/services/branches_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.branches.models import Branches
|
||||
from app.modules.branches.schema import
|
||||
|
||||
|
||||
class BranchesService:
|
||||
@staticmethod
|
||||
def create_branches(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_branches = Branches(**data.dict())
|
||||
db.add(new_branches)
|
||||
db.commit()
|
||||
db.refresh(new_branches)
|
||||
return new_branches
|
||||
|
||||
@staticmethod
|
||||
def get_branches(db: Session, branches_id: int, current_user):
|
||||
branches = db.query(Branches).filter(Branches.id == branches_id).first()
|
||||
if not branches:
|
||||
raise ValueError("branches no encontrado")
|
||||
return branches
|
||||
|
||||
@staticmethod
|
||||
def update_branches(db: Session, branches_id: int, data: , current_user):
|
||||
branches = db.query(Branches).filter(Branches.id == branches_id).first()
|
||||
if not branches:
|
||||
raise ValueError("branches no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este branches")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(branches, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(branches)
|
||||
return branches
|
||||
|
||||
@staticmethod
|
||||
def delete_branches(db: Session, branches_id: int, current_user):
|
||||
branches = db.query(Branches).filter(Branches.id == branches_id).first()
|
||||
if not branches:
|
||||
raise ValueError("branches no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este branches")
|
||||
|
||||
try:
|
||||
branches.is_active = False
|
||||
branches.deleted_at = datetime.utcnow()
|
||||
branches.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(branches)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el branches: {e}")
|
||||
|
||||
return {"message": "branches eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/client_service.py
Normal file
67
output/generated/services/client_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.client.models import Client
|
||||
from app.modules.client.schema import
|
||||
|
||||
|
||||
class ClientService:
|
||||
@staticmethod
|
||||
def create_client(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_client = Client(**data.dict())
|
||||
db.add(new_client)
|
||||
db.commit()
|
||||
db.refresh(new_client)
|
||||
return new_client
|
||||
|
||||
@staticmethod
|
||||
def get_client(db: Session, client_id: int, current_user):
|
||||
client = db.query(Client).filter(Client.id == client_id).first()
|
||||
if not client:
|
||||
raise ValueError("client no encontrado")
|
||||
return client
|
||||
|
||||
@staticmethod
|
||||
def update_client(db: Session, client_id: int, data: , current_user):
|
||||
client = db.query(Client).filter(Client.id == client_id).first()
|
||||
if not client:
|
||||
raise ValueError("client no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este client")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(client, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(client)
|
||||
return client
|
||||
|
||||
@staticmethod
|
||||
def delete_client(db: Session, client_id: int, current_user):
|
||||
client = db.query(Client).filter(Client.id == client_id).first()
|
||||
if not client:
|
||||
raise ValueError("client no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este client")
|
||||
|
||||
try:
|
||||
client.is_active = False
|
||||
client.deleted_at = datetime.utcnow()
|
||||
client.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(client)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el client: {e}")
|
||||
|
||||
return {"message": "client eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/coments_service.py
Normal file
67
output/generated/services/coments_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.coments.models import Coments
|
||||
from app.modules.coments.schema import
|
||||
|
||||
|
||||
class ComentsService:
|
||||
@staticmethod
|
||||
def create_coments(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_coments = Coments(**data.dict())
|
||||
db.add(new_coments)
|
||||
db.commit()
|
||||
db.refresh(new_coments)
|
||||
return new_coments
|
||||
|
||||
@staticmethod
|
||||
def get_coments(db: Session, coments_id: int, current_user):
|
||||
coments = db.query(Coments).filter(Coments.id == coments_id).first()
|
||||
if not coments:
|
||||
raise ValueError("coments no encontrado")
|
||||
return coments
|
||||
|
||||
@staticmethod
|
||||
def update_coments(db: Session, coments_id: int, data: , current_user):
|
||||
coments = db.query(Coments).filter(Coments.id == coments_id).first()
|
||||
if not coments:
|
||||
raise ValueError("coments no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este coments")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(coments, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(coments)
|
||||
return coments
|
||||
|
||||
@staticmethod
|
||||
def delete_coments(db: Session, coments_id: int, current_user):
|
||||
coments = db.query(Coments).filter(Coments.id == coments_id).first()
|
||||
if not coments:
|
||||
raise ValueError("coments no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este coments")
|
||||
|
||||
try:
|
||||
coments.is_active = False
|
||||
coments.deleted_at = datetime.utcnow()
|
||||
coments.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(coments)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el coments: {e}")
|
||||
|
||||
return {"message": "coments eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/configuration_service.py
Normal file
67
output/generated/services/configuration_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.configuration.models import Configuration
|
||||
from app.modules.configuration.schema import
|
||||
|
||||
|
||||
class ConfigurationService:
|
||||
@staticmethod
|
||||
def create_configuration(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_configuration = Configuration(**data.dict())
|
||||
db.add(new_configuration)
|
||||
db.commit()
|
||||
db.refresh(new_configuration)
|
||||
return new_configuration
|
||||
|
||||
@staticmethod
|
||||
def get_configuration(db: Session, configuration_id: int, current_user):
|
||||
configuration = db.query(Configuration).filter(Configuration.id == configuration_id).first()
|
||||
if not configuration:
|
||||
raise ValueError("configuration no encontrado")
|
||||
return configuration
|
||||
|
||||
@staticmethod
|
||||
def update_configuration(db: Session, configuration_id: int, data: , current_user):
|
||||
configuration = db.query(Configuration).filter(Configuration.id == configuration_id).first()
|
||||
if not configuration:
|
||||
raise ValueError("configuration no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este configuration")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(configuration, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(configuration)
|
||||
return configuration
|
||||
|
||||
@staticmethod
|
||||
def delete_configuration(db: Session, configuration_id: int, current_user):
|
||||
configuration = db.query(Configuration).filter(Configuration.id == configuration_id).first()
|
||||
if not configuration:
|
||||
raise ValueError("configuration no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este configuration")
|
||||
|
||||
try:
|
||||
configuration.is_active = False
|
||||
configuration.deleted_at = datetime.utcnow()
|
||||
configuration.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(configuration)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el configuration: {e}")
|
||||
|
||||
return {"message": "configuration eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/credits_service.py
Normal file
67
output/generated/services/credits_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.credits.models import Credits
|
||||
from app.modules.credits.schema import
|
||||
|
||||
|
||||
class CreditsService:
|
||||
@staticmethod
|
||||
def create_credits(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_credits = Credits(**data.dict())
|
||||
db.add(new_credits)
|
||||
db.commit()
|
||||
db.refresh(new_credits)
|
||||
return new_credits
|
||||
|
||||
@staticmethod
|
||||
def get_credits(db: Session, credits_id: int, current_user):
|
||||
credits = db.query(Credits).filter(Credits.id == credits_id).first()
|
||||
if not credits:
|
||||
raise ValueError("credits no encontrado")
|
||||
return credits
|
||||
|
||||
@staticmethod
|
||||
def update_credits(db: Session, credits_id: int, data: , current_user):
|
||||
credits = db.query(Credits).filter(Credits.id == credits_id).first()
|
||||
if not credits:
|
||||
raise ValueError("credits no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este credits")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(credits, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(credits)
|
||||
return credits
|
||||
|
||||
@staticmethod
|
||||
def delete_credits(db: Session, credits_id: int, current_user):
|
||||
credits = db.query(Credits).filter(Credits.id == credits_id).first()
|
||||
if not credits:
|
||||
raise ValueError("credits no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este credits")
|
||||
|
||||
try:
|
||||
credits.is_active = False
|
||||
credits.deleted_at = datetime.utcnow()
|
||||
credits.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(credits)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el credits: {e}")
|
||||
|
||||
return {"message": "credits eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/edos_service.py
Normal file
67
output/generated/services/edos_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.edos.models import EDOS
|
||||
from app.modules.edos.schema import
|
||||
|
||||
|
||||
class EDOSService:
|
||||
@staticmethod
|
||||
def create_edos(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_edos = EDOS(**data.dict())
|
||||
db.add(new_edos)
|
||||
db.commit()
|
||||
db.refresh(new_edos)
|
||||
return new_edos
|
||||
|
||||
@staticmethod
|
||||
def get_edos(db: Session, edos_id: int, current_user):
|
||||
edos = db.query(EDOS).filter(EDOS.id == edos_id).first()
|
||||
if not edos:
|
||||
raise ValueError("edos no encontrado")
|
||||
return edos
|
||||
|
||||
@staticmethod
|
||||
def update_edos(db: Session, edos_id: int, data: , current_user):
|
||||
edos = db.query(EDOS).filter(EDOS.id == edos_id).first()
|
||||
if not edos:
|
||||
raise ValueError("edos no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este edos")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(edos, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(edos)
|
||||
return edos
|
||||
|
||||
@staticmethod
|
||||
def delete_edos(db: Session, edos_id: int, current_user):
|
||||
edos = db.query(EDOS).filter(EDOS.id == edos_id).first()
|
||||
if not edos:
|
||||
raise ValueError("edos no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este edos")
|
||||
|
||||
try:
|
||||
edos.is_active = False
|
||||
edos.deleted_at = datetime.utcnow()
|
||||
edos.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(edos)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el edos: {e}")
|
||||
|
||||
return {"message": "edos eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/efos_service.py
Normal file
67
output/generated/services/efos_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.efos.models import EFOS
|
||||
from app.modules.efos.schema import
|
||||
|
||||
|
||||
class EFOSService:
|
||||
@staticmethod
|
||||
def create_efos(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_efos = EFOS(**data.dict())
|
||||
db.add(new_efos)
|
||||
db.commit()
|
||||
db.refresh(new_efos)
|
||||
return new_efos
|
||||
|
||||
@staticmethod
|
||||
def get_efos(db: Session, efos_id: int, current_user):
|
||||
efos = db.query(EFOS).filter(EFOS.id == efos_id).first()
|
||||
if not efos:
|
||||
raise ValueError("efos no encontrado")
|
||||
return efos
|
||||
|
||||
@staticmethod
|
||||
def update_efos(db: Session, efos_id: int, data: , current_user):
|
||||
efos = db.query(EFOS).filter(EFOS.id == efos_id).first()
|
||||
if not efos:
|
||||
raise ValueError("efos no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este efos")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(efos, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(efos)
|
||||
return efos
|
||||
|
||||
@staticmethod
|
||||
def delete_efos(db: Session, efos_id: int, current_user):
|
||||
efos = db.query(EFOS).filter(EFOS.id == efos_id).first()
|
||||
if not efos:
|
||||
raise ValueError("efos no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este efos")
|
||||
|
||||
try:
|
||||
efos.is_active = False
|
||||
efos.deleted_at = datetime.utcnow()
|
||||
efos.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(efos)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el efos: {e}")
|
||||
|
||||
return {"message": "efos eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/feed_service.py
Normal file
67
output/generated/services/feed_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.feed.models import Feed
|
||||
from app.modules.feed.schema import
|
||||
|
||||
|
||||
class FeedService:
|
||||
@staticmethod
|
||||
def create_feed(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_feed = Feed(**data.dict())
|
||||
db.add(new_feed)
|
||||
db.commit()
|
||||
db.refresh(new_feed)
|
||||
return new_feed
|
||||
|
||||
@staticmethod
|
||||
def get_feed(db: Session, feed_id: int, current_user):
|
||||
feed = db.query(Feed).filter(Feed.id == feed_id).first()
|
||||
if not feed:
|
||||
raise ValueError("feed no encontrado")
|
||||
return feed
|
||||
|
||||
@staticmethod
|
||||
def update_feed(db: Session, feed_id: int, data: , current_user):
|
||||
feed = db.query(Feed).filter(Feed.id == feed_id).first()
|
||||
if not feed:
|
||||
raise ValueError("feed no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este feed")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(feed, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(feed)
|
||||
return feed
|
||||
|
||||
@staticmethod
|
||||
def delete_feed(db: Session, feed_id: int, current_user):
|
||||
feed = db.query(Feed).filter(Feed.id == feed_id).first()
|
||||
if not feed:
|
||||
raise ValueError("feed no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este feed")
|
||||
|
||||
try:
|
||||
feed.is_active = False
|
||||
feed.deleted_at = datetime.utcnow()
|
||||
feed.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(feed)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el feed: {e}")
|
||||
|
||||
return {"message": "feed eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/files_service.py
Normal file
67
output/generated/services/files_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.files.models import Files
|
||||
from app.modules.files.schema import
|
||||
|
||||
|
||||
class FilesService:
|
||||
@staticmethod
|
||||
def create_files(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_files = Files(**data.dict())
|
||||
db.add(new_files)
|
||||
db.commit()
|
||||
db.refresh(new_files)
|
||||
return new_files
|
||||
|
||||
@staticmethod
|
||||
def get_files(db: Session, files_id: int, current_user):
|
||||
files = db.query(Files).filter(Files.id == files_id).first()
|
||||
if not files:
|
||||
raise ValueError("files no encontrado")
|
||||
return files
|
||||
|
||||
@staticmethod
|
||||
def update_files(db: Session, files_id: int, data: , current_user):
|
||||
files = db.query(Files).filter(Files.id == files_id).first()
|
||||
if not files:
|
||||
raise ValueError("files no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este files")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(files, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(files)
|
||||
return files
|
||||
|
||||
@staticmethod
|
||||
def delete_files(db: Session, files_id: int, current_user):
|
||||
files = db.query(Files).filter(Files.id == files_id).first()
|
||||
if not files:
|
||||
raise ValueError("files no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este files")
|
||||
|
||||
try:
|
||||
files.is_active = False
|
||||
files.deleted_at = datetime.utcnow()
|
||||
files.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(files)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el files: {e}")
|
||||
|
||||
return {"message": "files eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/invoices_service.py
Normal file
67
output/generated/services/invoices_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.invoices.models import Invoices
|
||||
from app.modules.invoices.schema import
|
||||
|
||||
|
||||
class InvoicesService:
|
||||
@staticmethod
|
||||
def create_invoices(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_invoices = Invoices(**data.dict())
|
||||
db.add(new_invoices)
|
||||
db.commit()
|
||||
db.refresh(new_invoices)
|
||||
return new_invoices
|
||||
|
||||
@staticmethod
|
||||
def get_invoices(db: Session, invoices_id: int, current_user):
|
||||
invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first()
|
||||
if not invoices:
|
||||
raise ValueError("invoices no encontrado")
|
||||
return invoices
|
||||
|
||||
@staticmethod
|
||||
def update_invoices(db: Session, invoices_id: int, data: , current_user):
|
||||
invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first()
|
||||
if not invoices:
|
||||
raise ValueError("invoices no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este invoices")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(invoices, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(invoices)
|
||||
return invoices
|
||||
|
||||
@staticmethod
|
||||
def delete_invoices(db: Session, invoices_id: int, current_user):
|
||||
invoices = db.query(Invoices).filter(Invoices.id == invoices_id).first()
|
||||
if not invoices:
|
||||
raise ValueError("invoices no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este invoices")
|
||||
|
||||
try:
|
||||
invoices.is_active = False
|
||||
invoices.deleted_at = datetime.utcnow()
|
||||
invoices.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(invoices)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el invoices: {e}")
|
||||
|
||||
return {"message": "invoices eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/license_service.py
Normal file
67
output/generated/services/license_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.license.models import License
|
||||
from app.modules.license.schema import
|
||||
|
||||
|
||||
class LicenseService:
|
||||
@staticmethod
|
||||
def create_license(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_license = License(**data.dict())
|
||||
db.add(new_license)
|
||||
db.commit()
|
||||
db.refresh(new_license)
|
||||
return new_license
|
||||
|
||||
@staticmethod
|
||||
def get_license(db: Session, license_id: int, current_user):
|
||||
license = db.query(License).filter(License.id == license_id).first()
|
||||
if not license:
|
||||
raise ValueError("license no encontrado")
|
||||
return license
|
||||
|
||||
@staticmethod
|
||||
def update_license(db: Session, license_id: int, data: , current_user):
|
||||
license = db.query(License).filter(License.id == license_id).first()
|
||||
if not license:
|
||||
raise ValueError("license no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este license")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(license, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(license)
|
||||
return license
|
||||
|
||||
@staticmethod
|
||||
def delete_license(db: Session, license_id: int, current_user):
|
||||
license = db.query(License).filter(License.id == license_id).first()
|
||||
if not license:
|
||||
raise ValueError("license no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este license")
|
||||
|
||||
try:
|
||||
license.is_active = False
|
||||
license.deleted_at = datetime.utcnow()
|
||||
license.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(license)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el license: {e}")
|
||||
|
||||
return {"message": "license eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/locations_service.py
Normal file
67
output/generated/services/locations_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.locations.models import Locations
|
||||
from app.modules.locations.schema import
|
||||
|
||||
|
||||
class LocationsService:
|
||||
@staticmethod
|
||||
def create_locations(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_locations = Locations(**data.dict())
|
||||
db.add(new_locations)
|
||||
db.commit()
|
||||
db.refresh(new_locations)
|
||||
return new_locations
|
||||
|
||||
@staticmethod
|
||||
def get_locations(db: Session, locations_id: int, current_user):
|
||||
locations = db.query(Locations).filter(Locations.id == locations_id).first()
|
||||
if not locations:
|
||||
raise ValueError("locations no encontrado")
|
||||
return locations
|
||||
|
||||
@staticmethod
|
||||
def update_locations(db: Session, locations_id: int, data: , current_user):
|
||||
locations = db.query(Locations).filter(Locations.id == locations_id).first()
|
||||
if not locations:
|
||||
raise ValueError("locations no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este locations")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(locations, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(locations)
|
||||
return locations
|
||||
|
||||
@staticmethod
|
||||
def delete_locations(db: Session, locations_id: int, current_user):
|
||||
locations = db.query(Locations).filter(Locations.id == locations_id).first()
|
||||
if not locations:
|
||||
raise ValueError("locations no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este locations")
|
||||
|
||||
try:
|
||||
locations.is_active = False
|
||||
locations.deleted_at = datetime.utcnow()
|
||||
locations.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(locations)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el locations: {e}")
|
||||
|
||||
return {"message": "locations eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/moves_service.py
Normal file
67
output/generated/services/moves_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.moves.models import Moves
|
||||
from app.modules.moves.schema import
|
||||
|
||||
|
||||
class MovesService:
|
||||
@staticmethod
|
||||
def create_moves(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_moves = Moves(**data.dict())
|
||||
db.add(new_moves)
|
||||
db.commit()
|
||||
db.refresh(new_moves)
|
||||
return new_moves
|
||||
|
||||
@staticmethod
|
||||
def get_moves(db: Session, moves_id: int, current_user):
|
||||
moves = db.query(Moves).filter(Moves.id == moves_id).first()
|
||||
if not moves:
|
||||
raise ValueError("moves no encontrado")
|
||||
return moves
|
||||
|
||||
@staticmethod
|
||||
def update_moves(db: Session, moves_id: int, data: , current_user):
|
||||
moves = db.query(Moves).filter(Moves.id == moves_id).first()
|
||||
if not moves:
|
||||
raise ValueError("moves no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este moves")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(moves, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(moves)
|
||||
return moves
|
||||
|
||||
@staticmethod
|
||||
def delete_moves(db: Session, moves_id: int, current_user):
|
||||
moves = db.query(Moves).filter(Moves.id == moves_id).first()
|
||||
if not moves:
|
||||
raise ValueError("moves no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este moves")
|
||||
|
||||
try:
|
||||
moves.is_active = False
|
||||
moves.deleted_at = datetime.utcnow()
|
||||
moves.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(moves)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el moves: {e}")
|
||||
|
||||
return {"message": "moves eliminado correctamente"}
|
||||
|
||||
|
||||
67
output/generated/services/suppliers_service.py
Normal file
67
output/generated/services/suppliers_service.py
Normal file
@@ -0,0 +1,67 @@
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from fastapi import HTTPException
|
||||
from app.modules.suppliers.models import Suppliers
|
||||
from app.modules.suppliers.schema import
|
||||
|
||||
|
||||
class SuppliersService:
|
||||
@staticmethod
|
||||
def create_suppliers(db: Session, data: ):
|
||||
|
||||
|
||||
|
||||
|
||||
new_suppliers = Suppliers(**data.dict())
|
||||
db.add(new_suppliers)
|
||||
db.commit()
|
||||
db.refresh(new_suppliers)
|
||||
return new_suppliers
|
||||
|
||||
@staticmethod
|
||||
def get_suppliers(db: Session, suppliers_id: int, current_user):
|
||||
suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first()
|
||||
if not suppliers:
|
||||
raise ValueError("suppliers no encontrado")
|
||||
return suppliers
|
||||
|
||||
@staticmethod
|
||||
def update_suppliers(db: Session, suppliers_id: int, data: , current_user):
|
||||
suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first()
|
||||
if not suppliers:
|
||||
raise ValueError("suppliers no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para actualizar este suppliers")
|
||||
|
||||
update_data = data.dict(exclude_unset=True)
|
||||
for key, value in update_data.items():
|
||||
setattr(suppliers, key, value)
|
||||
|
||||
db.commit()
|
||||
db.refresh(suppliers)
|
||||
return suppliers
|
||||
|
||||
@staticmethod
|
||||
def delete_suppliers(db: Session, suppliers_id: int, current_user):
|
||||
suppliers = db.query(Suppliers).filter(Suppliers.id == suppliers_id).first()
|
||||
if not suppliers:
|
||||
raise ValueError("suppliers no encontrado")
|
||||
|
||||
if current_user.role not in ["ROOT", "ADMIN"]:
|
||||
raise ValueError("No tienes permisos para eliminar este suppliers")
|
||||
|
||||
try:
|
||||
suppliers.is_active = False
|
||||
suppliers.deleted_at = datetime.utcnow()
|
||||
suppliers.deleted_by = current_user.id
|
||||
db.commit()
|
||||
db.refresh(suppliers)
|
||||
except Exception as e:
|
||||
db.rollback()
|
||||
raise ValueError(f"Error al eliminar el suppliers: {e}")
|
||||
|
||||
return {"message": "suppliers eliminado correctamente"}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user