This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from sqlmodel import Session, select
|
||||
import src.models as models
|
||||
import src.productors.exceptions as exceptions
|
||||
import src.messages as messages
|
||||
|
||||
def get_all(
|
||||
session: Session,
|
||||
@@ -22,7 +23,7 @@ def get_one(session: Session, productor_id: int) -> models.ProductorPublic:
|
||||
|
||||
def create_one(session: Session, productor: models.ProductorCreate) -> models.ProductorPublic:
|
||||
if not productor:
|
||||
raise exceptions.ProductorCreateError('ProductorCreate input cannot be None')
|
||||
raise exceptions.ProductorCreateError(messages.Messages.invalid_input('productor', 'input cannot be None'))
|
||||
productor_create = productor.model_dump(exclude_unset=True, exclude='payment_methods')
|
||||
new_productor = models.Productor(**productor_create)
|
||||
|
||||
@@ -43,7 +44,7 @@ def update_one(session: Session, id: int, productor: models.ProductorUpdate) ->
|
||||
result = session.exec(statement)
|
||||
new_productor = result.first()
|
||||
if not new_productor:
|
||||
raise exceptions.ProductorNotFoundError(f'Productor {id} not found')
|
||||
raise exceptions.ProductorNotFoundError(messages.Messages.not_found('productor'))
|
||||
|
||||
productor_updates = productor.model_dump(exclude_unset=True)
|
||||
if 'payment_methods' in productor_updates:
|
||||
@@ -71,7 +72,7 @@ def delete_one(session: Session, id: int) -> models.ProductorPublic:
|
||||
result = session.exec(statement)
|
||||
productor = result.first()
|
||||
if not productor:
|
||||
raise exceptions.ProductorNotFoundError(f'Productor {id} not found')
|
||||
raise exceptions.ProductorNotFoundError(messages.Messages.not_found('productor'))
|
||||
result = models.ProductorPublic.model_validate(productor)
|
||||
session.delete(productor)
|
||||
session.commit()
|
||||
|
||||
Reference in New Issue
Block a user