._.
This commit is contained in:
parent
530fbf64a3
commit
a2510f9401
@ -1,11 +1,13 @@
|
||||
class AccessoryEntity:
|
||||
def __init__(self, accessory_id: int, name: str, width: float, height: float, length: float, weight: float):
|
||||
self.id = accessory_id
|
||||
self.name = name
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.length = length
|
||||
self.weight = weight
|
||||
from pydantic import BaseModel
|
||||
|
||||
def __repr__(self):
|
||||
return f"<AccessoryEntity(id={self.id}, name={self.name}, width={self.width}, height={self.height}, length={self.length}, weight={self.weight})>"
|
||||
|
||||
class AccessoryEntity(BaseModel):
|
||||
id: int
|
||||
name: str
|
||||
width: float
|
||||
height: float
|
||||
length: float
|
||||
weight: float
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class DeliveryEntity:
|
||||
def __init__(self, delivery_id: Optional[int], count: int, storage_accessories_id: int, step_id: int):
|
||||
self.id = delivery_id
|
||||
self.count = count
|
||||
self.storage_accessories_id = storage_accessories_id
|
||||
self.step_id = step_id
|
||||
class DeliveryEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
count: int
|
||||
storage_accessories_id: int
|
||||
step_id: int
|
||||
|
||||
def __repr__(self):
|
||||
return f"<DeliveryEntity(id={self.id}, count={self.count}, storage_accessories_id={self.storage_accessories_id}, step_id={self.step_id})>"
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class OrderEntity:
|
||||
def __init__(self, order_id: Optional[int], order_datetime: datetime, user_id: int, status_id: int):
|
||||
self.id = order_id
|
||||
self.order_datetime = order_datetime
|
||||
self.user_id = user_id
|
||||
self.status_id = status_id
|
||||
class OrderEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
order_datetime: datetime
|
||||
user_id: int
|
||||
status_id: int
|
||||
|
||||
def __repr__(self):
|
||||
return (f"<OrderEntity(id={self.id}, order_datetime={self.order_datetime}, "
|
||||
f"user_id={self.user_id}, status_id={self.status_id})>")
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class RoleEntity:
|
||||
def __init__(self, role_id: Optional[int], name: str):
|
||||
self.id = role_id
|
||||
self.name = name
|
||||
class RoleEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
name: str
|
||||
|
||||
def __repr__(self):
|
||||
return f"<RoleEntity(id={self.id}, name={self.name})>"
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class StatusEntity:
|
||||
def __init__(self, status_id: Optional[int], name: str):
|
||||
self.id = status_id
|
||||
self.name = name
|
||||
class StatusEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
name: str
|
||||
|
||||
def __repr__(self):
|
||||
return f"<StatusEntity(id={self.id}, name={self.name})>"
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -1,17 +1,14 @@
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class StepEntity:
|
||||
def __init__(self, step_id: Optional[int], start_deadline: datetime, finish_deadline: datetime, order_id: Optional[int],
|
||||
status_id: Optional[int]):
|
||||
self.id = step_id
|
||||
self.start_deadline = start_deadline
|
||||
self.finish_deadline = finish_deadline
|
||||
self.order_id = order_id
|
||||
self.status_id = status_id
|
||||
class StepEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
start_deadline: datetime
|
||||
finish_deadline: datetime
|
||||
order_id: Optional[int] = None
|
||||
status_id: Optional[int] = None
|
||||
|
||||
def __repr__(self):
|
||||
return (f"<StepEntity(id={self.id}, start_deadline={self.start_deadline}, "
|
||||
f"finish_deadline={self.finish_deadline}, order_id={self.order_id}, "
|
||||
f"status_id={self.status_id})>")
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -1,21 +1,13 @@
|
||||
from typing import Optional
|
||||
from typing import List
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class StorageEntity:
|
||||
def __init__(self,
|
||||
storage_id: Optional[int],
|
||||
name: str,
|
||||
x_coordinate: float,
|
||||
y_coordinate: float,
|
||||
storage_accessories: Optional[List[int]] = None):
|
||||
self.id = storage_id
|
||||
self.name = name
|
||||
self.x_coordinate = x_coordinate
|
||||
self.y_coordinate = y_coordinate
|
||||
self.storage_accessories = storage_accessories if storage_accessories is not None else []
|
||||
class StorageEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
name: str
|
||||
x_coordinate: float
|
||||
y_coordinate: float
|
||||
storage_accessories: Optional[List[int]] = []
|
||||
|
||||
def __repr__(self):
|
||||
return (f"<StorageEntity(id={self.id}, name={self.name}, "
|
||||
f"x_coordinate={self.x_coordinate}, y_coordinate={self.y_coordinate}, "
|
||||
f"storage_accessories={self.storage_accessories})>")
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -1,21 +1,14 @@
|
||||
from typing import Optional
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class StorageAccessoryEntity:
|
||||
def __init__(self,
|
||||
storage_accessories_id: Optional[int],
|
||||
current_count: int,
|
||||
change_datetime: Optional[datetime],
|
||||
storage_id: Optional[int],
|
||||
accessory_id: Optional[int]):
|
||||
self.id = storage_accessories_id
|
||||
self.current_count = current_count
|
||||
self.change_datetime = change_datetime
|
||||
self.storage_id = storage_id
|
||||
self.accessory_id = accessory_id
|
||||
class StorageAccessoryEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
current_count: int
|
||||
change_datetime: Optional[datetime] = None
|
||||
storage_id: Optional[int] = None
|
||||
accessory_id: Optional[int] = None
|
||||
|
||||
def __repr__(self):
|
||||
return (f"<StorageAccessoriesEntity(id={self.id}, current_count={self.current_count}, "
|
||||
f"change_datetime={self.change_datetime}, storage_id={self.storage_id}, "
|
||||
f"accessory_id={self.accessory_id})>")
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -1,24 +1,15 @@
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class UserEntity:
|
||||
def __init__(self,
|
||||
user_id: Optional[int],
|
||||
first_name: str,
|
||||
last_name: str,
|
||||
login: str,
|
||||
password: str,
|
||||
role_id: Optional[int] = None,
|
||||
orders: Optional[List[int]] = None):
|
||||
self.id = user_id
|
||||
self.first_name = first_name
|
||||
self.last_name = last_name
|
||||
self.login = login
|
||||
self.password = password
|
||||
self.role_id = role_id
|
||||
self.orders = orders if orders is not None else []
|
||||
class UserEntity(BaseModel):
|
||||
id: Optional[int] = None
|
||||
first_name: str
|
||||
last_name: str
|
||||
login: str
|
||||
password: str
|
||||
role_id: Optional[int] = None
|
||||
orders: List[int] = []
|
||||
|
||||
def __repr__(self):
|
||||
return (f"<UserEntity(id={self.id}, first_name={self.first_name}, "
|
||||
f"last_name={self.last_name}, login={self.login}, "
|
||||
f"role_id={self.role_id}, orders={self.orders})>")
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@ -6,18 +6,35 @@ from app.core.entities.accessory import AccessoryEntity
|
||||
from app.infrastructure.database.models.accessory import Accessory
|
||||
from app.infrastructure.database.repository.accessory_repository import AccessoriesRepository
|
||||
|
||||
|
||||
class AccessoriesService:
|
||||
def __init__(self, db: Session):
|
||||
self.repository = AccessoriesRepository(db)
|
||||
|
||||
def get_all_accessories(self) -> List[AccessoryEntity]:
|
||||
accessories = self.repository.get_all()
|
||||
return [AccessoryEntity(a.id, a.name, a.width, a.height, a.length, a.weight) for a in accessories]
|
||||
return [
|
||||
AccessoryEntity(
|
||||
id=a.id,
|
||||
name=a.name,
|
||||
width=a.width,
|
||||
height=a.height,
|
||||
length=a.length,
|
||||
weight=a.weight,
|
||||
)
|
||||
for a in accessories]
|
||||
|
||||
def get_accessory_by_id(self, accessory_id: int) -> Optional[AccessoryEntity]:
|
||||
accessory = self.repository.get_by_id(accessory_id)
|
||||
if accessory:
|
||||
return AccessoryEntity(accessory.id, accessory.name, accessory.width, accessory.height, accessory.length, accessory.weight)
|
||||
return AccessoryEntity(
|
||||
id=accessory.id,
|
||||
name=accessory.name,
|
||||
width=accessory.width,
|
||||
height=accessory.height,
|
||||
length=accessory.length,
|
||||
weight=accessory.weight,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@ -27,10 +44,17 @@ class AccessoriesService:
|
||||
width=entity.width,
|
||||
height=entity.height,
|
||||
length=entity.length,
|
||||
weight=entity.weight
|
||||
weight=entity.weight,
|
||||
)
|
||||
created_accessory = self.repository.create(accessory_model)
|
||||
return AccessoryEntity(created_accessory.id, created_accessory.name, created_accessory.width, created_accessory.height, created_accessory.length, created_accessory.weight)
|
||||
return AccessoryEntity(
|
||||
id=created_accessory.id,
|
||||
name=created_accessory.name,
|
||||
width=created_accessory.width,
|
||||
height=created_accessory.height,
|
||||
length=created_accessory.length,
|
||||
weight=created_accessory.weight,
|
||||
)
|
||||
|
||||
def update_accessory(self, accessory_id: int, entity: AccessoryEntity) -> Optional[AccessoryEntity]:
|
||||
accessory_model = self.repository.get_by_id(accessory_id)
|
||||
@ -41,7 +65,14 @@ class AccessoriesService:
|
||||
accessory_model.length = entity.length
|
||||
accessory_model.weight = entity.weight
|
||||
self.repository.update(accessory_model)
|
||||
return AccessoryEntity(accessory_model.id, accessory_model.name, accessory_model.width, accessory_model.height, accessory_model.length, accessory_model.weight)
|
||||
return AccessoryEntity(
|
||||
id=accessory_model.id,
|
||||
name=accessory_model.name,
|
||||
width=accessory_model.width,
|
||||
height=accessory_model.height,
|
||||
length=accessory_model.length,
|
||||
weight=accessory_model.weight,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@ -13,12 +13,25 @@ class DeliveryService:
|
||||
|
||||
def get_all_deliveries(self) -> List[DeliveryEntity]:
|
||||
deliveries = self.repository.get_all()
|
||||
return [DeliveryEntity(d.id, d.count, d.storage_accessories_id, d.step_id) for d in deliveries]
|
||||
return [
|
||||
DeliveryEntity(
|
||||
id=d.id,
|
||||
count=d.count,
|
||||
storage_accessories_id=d.storage_accessories_id,
|
||||
step_id=d.step_id,
|
||||
)
|
||||
for d in deliveries
|
||||
]
|
||||
|
||||
def get_delivery_by_id(self, delivery_id: int) -> Optional[DeliveryEntity]:
|
||||
delivery = self.repository.get_by_id(delivery_id)
|
||||
if delivery:
|
||||
return DeliveryEntity(delivery.id, delivery.count, delivery.storage_accessories_id, delivery.step_id)
|
||||
return DeliveryEntity(
|
||||
id=delivery.id,
|
||||
count=delivery.count,
|
||||
storage_accessories_id=delivery.storage_accessories_id,
|
||||
step_id=delivery.step_id,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@ -26,11 +39,15 @@ class DeliveryService:
|
||||
delivery_model = Delivery(
|
||||
count=entity.count,
|
||||
storage_accessories_id=entity.storage_accessories_id,
|
||||
step_id=entity.step_id
|
||||
step_id=entity.step_id,
|
||||
)
|
||||
created_delivery = self.repository.create(delivery_model)
|
||||
return DeliveryEntity(created_delivery.id, created_delivery.count, created_delivery.storage_accessories_id,
|
||||
created_delivery.step_id)
|
||||
return DeliveryEntity(
|
||||
id=created_delivery.id,
|
||||
count=created_delivery.count,
|
||||
storage_accessories_id=created_delivery.storage_accessories_id,
|
||||
step_id=created_delivery.step_id,
|
||||
)
|
||||
|
||||
def update_delivery(self, delivery_id: int, entity: DeliveryEntity) -> Optional[DeliveryEntity]:
|
||||
delivery_model = self.repository.get_by_id(delivery_id)
|
||||
@ -39,8 +56,12 @@ class DeliveryService:
|
||||
delivery_model.storage_accessories_id = entity.storage_accessories_id
|
||||
delivery_model.step_id = entity.step_id
|
||||
self.repository.update(delivery_model)
|
||||
return DeliveryEntity(delivery_model.id, delivery_model.count, delivery_model.storage_accessories_id,
|
||||
delivery_model.step_id)
|
||||
return DeliveryEntity(
|
||||
id=delivery_model.id,
|
||||
count=delivery_model.count,
|
||||
storage_accessories_id=delivery_model.storage_accessories_id,
|
||||
step_id=delivery_model.step_id,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@ -13,12 +13,25 @@ class OrderService:
|
||||
|
||||
def get_all_orders(self) -> List[OrderEntity]:
|
||||
orders = self.repository.get_all()
|
||||
return [OrderEntity(o.id, o.order_datetime, o.user_id, o.status_id) for o in orders]
|
||||
return [
|
||||
OrderEntity(
|
||||
id=o.id,
|
||||
order_datetime=o.order_datetime,
|
||||
user_id=o.user_id,
|
||||
status_id=o.status_id,
|
||||
)
|
||||
for o in orders
|
||||
]
|
||||
|
||||
def get_order_by_id(self, order_id: int) -> Optional[OrderEntity]:
|
||||
order = self.repository.get_by_id(order_id)
|
||||
if order:
|
||||
return OrderEntity(order.id, order.order_datetime, order.user_id, order.status_id)
|
||||
return OrderEntity(
|
||||
id=order.id,
|
||||
order_datetime=order.order_datetime,
|
||||
user_id=order.user_id,
|
||||
status_id=order.status_id,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@ -26,11 +39,15 @@ class OrderService:
|
||||
order_model = Order(
|
||||
order_datetime=entity.order_datetime,
|
||||
user_id=entity.user_id,
|
||||
status_id=entity.status_id
|
||||
status_id=entity.status_id,
|
||||
)
|
||||
created_order = self.repository.create(order_model)
|
||||
return OrderEntity(created_order.id, created_order.order_datetime, created_order.user_id,
|
||||
created_order.status_id)
|
||||
return OrderEntity(
|
||||
id=created_order.id,
|
||||
order_datetime=created_order.order_datetime,
|
||||
user_id=created_order.user_id,
|
||||
status_id=created_order.status_id,
|
||||
)
|
||||
|
||||
def update_order(self, order_id: int, entity: OrderEntity) -> Optional[OrderEntity]:
|
||||
order_model = self.repository.get_by_id(order_id)
|
||||
@ -39,7 +56,12 @@ class OrderService:
|
||||
order_model.user_id = entity.user_id
|
||||
order_model.status_id = entity.status_id
|
||||
self.repository.update(order_model)
|
||||
return OrderEntity(order_model.id, order_model.order_datetime, order_model.user_id, order_model.status_id)
|
||||
return OrderEntity(
|
||||
id=order_model.id,
|
||||
order_datetime=order_model.order_datetime,
|
||||
user_id=order_model.user_id,
|
||||
status_id=order_model.status_id,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@ -13,26 +13,40 @@ class RoleService:
|
||||
|
||||
def get_all_roles(self) -> List[RoleEntity]:
|
||||
roles = self.repository.get_all()
|
||||
return [RoleEntity(r.id, r.name) for r in roles]
|
||||
return [
|
||||
RoleEntity(
|
||||
id=r.id,
|
||||
name=r.name,
|
||||
) for r in roles
|
||||
]
|
||||
|
||||
def get_role_by_id(self, role_id: int) -> Optional[RoleEntity]:
|
||||
role = self.repository.get_by_id(role_id)
|
||||
if role:
|
||||
return RoleEntity(role.id, role.name)
|
||||
return RoleEntity(
|
||||
id=role.id,
|
||||
name=role.name,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
def create_role(self, entity: RoleEntity) -> RoleEntity:
|
||||
role_model = Role(name=entity.name)
|
||||
created_role = self.repository.create(role_model)
|
||||
return RoleEntity(created_role.id, created_role.name)
|
||||
return RoleEntity(
|
||||
id=created_role.id,
|
||||
name=created_role.name,
|
||||
)
|
||||
|
||||
def update_role(self, role_id: int, entity: RoleEntity) -> Optional[RoleEntity]:
|
||||
role_model = self.repository.get_by_id(role_id)
|
||||
if role_model:
|
||||
role_model.name = entity.name
|
||||
self.repository.update(role_model)
|
||||
return RoleEntity(role_model.id, role_model.name)
|
||||
return RoleEntity(
|
||||
id=role_model.id,
|
||||
name=role_model.name,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@ -13,26 +13,41 @@ class StatusService:
|
||||
|
||||
def get_all_statuses(self) -> List[StatusEntity]:
|
||||
statuses = self.repository.get_all()
|
||||
return [StatusEntity(s.id, s.name) for s in statuses]
|
||||
return [
|
||||
StatusEntity(
|
||||
id=s.id,
|
||||
name=s.name,
|
||||
)
|
||||
for s in statuses
|
||||
]
|
||||
|
||||
def get_status_by_id(self, status_id: int) -> Optional[StatusEntity]:
|
||||
status = self.repository.get_by_id(status_id)
|
||||
if status:
|
||||
return StatusEntity(status.id, status.name)
|
||||
return StatusEntity(
|
||||
id=status.id,
|
||||
name=status.name,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
def create_status(self, entity: StatusEntity) -> StatusEntity:
|
||||
status_model = Status(name=entity.name)
|
||||
created_status = self.repository.create(status_model)
|
||||
return StatusEntity(created_status.id, created_status.name)
|
||||
return StatusEntity(
|
||||
id=created_status.id,
|
||||
name=created_status.name,
|
||||
)
|
||||
|
||||
def update_status(self, status_id: int, entity: StatusEntity) -> Optional[StatusEntity]:
|
||||
status_model = self.repository.get_by_id(status_id)
|
||||
if status_model:
|
||||
status_model.name = entity.name
|
||||
self.repository.update(status_model)
|
||||
return StatusEntity(status_model.id, status_model.name)
|
||||
return StatusEntity(
|
||||
id=status_model.id,
|
||||
name=status_model.name,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@ -15,11 +15,11 @@ class StepService:
|
||||
steps = self.repository.get_all()
|
||||
return [
|
||||
StepEntity(
|
||||
s.id,
|
||||
s.start_deadline,
|
||||
s.finish_deadline,
|
||||
s.order_id,
|
||||
s.status_id
|
||||
id=s.id,
|
||||
start_deadline=s.start_deadline,
|
||||
finish_deadline=s.finish_deadline,
|
||||
order_id=s.order_id,
|
||||
status_id=s.status_id,
|
||||
) for s in steps
|
||||
]
|
||||
|
||||
@ -27,11 +27,11 @@ class StepService:
|
||||
step = self.repository.get_by_id(step_id)
|
||||
if step:
|
||||
return StepEntity(
|
||||
step.id,
|
||||
step.start_deadline,
|
||||
step.finish_deadline,
|
||||
step.order_id,
|
||||
step.status_id
|
||||
id=step.id,
|
||||
start_deadline=step.start_deadline,
|
||||
finish_deadline=step.finish_deadline,
|
||||
order_id=step.order_id,
|
||||
status_id=step.status_id,
|
||||
)
|
||||
|
||||
return None
|
||||
@ -41,15 +41,15 @@ class StepService:
|
||||
start_deadline=entity.start_deadline,
|
||||
finish_deadline=entity.finish_deadline,
|
||||
order_id=entity.order_id,
|
||||
status_id=entity.status_id
|
||||
status_id=entity.status_id,
|
||||
)
|
||||
created_step = self.repository.create(step_model)
|
||||
return StepEntity(
|
||||
created_step.id,
|
||||
created_step.start_deadline,
|
||||
created_step.finish_deadline,
|
||||
created_step.order_id,
|
||||
created_step.status_id
|
||||
id=created_step.id,
|
||||
start_deadline=created_step.start_deadline,
|
||||
finish_deadline=created_step.finish_deadline,
|
||||
order_id=created_step.order_id,
|
||||
status_id=created_step.status_id,
|
||||
)
|
||||
|
||||
def update_step(self, step_id: int, entity: StepEntity) -> Optional[StepEntity]:
|
||||
@ -61,11 +61,11 @@ class StepService:
|
||||
step_model.status_id = entity.status_id
|
||||
self.repository.update(step_model)
|
||||
return StepEntity(
|
||||
step_model.id,
|
||||
step_model.start_deadline,
|
||||
step_model.finish_deadline,
|
||||
step_model.order_id,
|
||||
step_model.status_id
|
||||
id=step_model.id,
|
||||
start_deadline=step_model.start_deadline,
|
||||
finish_deadline=step_model.finish_deadline,
|
||||
order_id=step_model.order_id,
|
||||
status_id=step_model.status_id,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@ -15,11 +15,11 @@ class StorageAccessoryService:
|
||||
storage_accessories = self.repository.get_all()
|
||||
return [
|
||||
StorageAccessoryEntity(
|
||||
sa.id,
|
||||
sa.current_count,
|
||||
sa.change_datetime,
|
||||
sa.storage_id,
|
||||
sa.accessory_id
|
||||
id=sa.id,
|
||||
current_count=sa.current_count,
|
||||
change_datetime=sa.change_datetime,
|
||||
storage_id=sa.storage_id,
|
||||
accessory_id=sa.accessory_id,
|
||||
) for sa in storage_accessories
|
||||
]
|
||||
|
||||
@ -27,11 +27,11 @@ class StorageAccessoryService:
|
||||
storage_accessory = self.repository.get_by_id(storage_accessories_id)
|
||||
if storage_accessory:
|
||||
return StorageAccessoryEntity(
|
||||
storage_accessory.id,
|
||||
storage_accessory.current_count,
|
||||
storage_accessory.change_datetime,
|
||||
storage_accessory.storage_id,
|
||||
storage_accessory.accessory_id
|
||||
id=storage_accessory.id,
|
||||
current_count=storage_accessory.current_count,
|
||||
change_datetime=storage_accessory.change_datetime,
|
||||
storage_id=storage_accessory.storage_id,
|
||||
accessory_id=storage_accessory.accessory_id,
|
||||
)
|
||||
|
||||
return None
|
||||
@ -41,15 +41,15 @@ class StorageAccessoryService:
|
||||
current_count=entity.current_count,
|
||||
change_datetime=entity.change_datetime,
|
||||
storage_id=entity.storage_id,
|
||||
accessory_id=entity.accessory_id
|
||||
accessory_id=entity.accessory_id,
|
||||
)
|
||||
created_storage_accessory = self.repository.create(storage_accessory_model)
|
||||
return StorageAccessoryEntity(
|
||||
created_storage_accessory.id,
|
||||
created_storage_accessory.current_count,
|
||||
created_storage_accessory.change_datetime,
|
||||
created_storage_accessory.storage_id,
|
||||
created_storage_accessory.accessory_id
|
||||
id=created_storage_accessory.id,
|
||||
current_count=created_storage_accessory.current_count,
|
||||
change_datetime=created_storage_accessory.change_datetime,
|
||||
storage_id=created_storage_accessory.storage_id,
|
||||
accessory_id=created_storage_accessory.accessory_id,
|
||||
)
|
||||
|
||||
def update_storage_accessory(self, storage_accessories_id: int, entity: StorageAccessoryEntity) -> Optional[
|
||||
@ -62,11 +62,11 @@ class StorageAccessoryService:
|
||||
storage_accessory_model.accessory_id = entity.accessory_id
|
||||
self.repository.update(storage_accessory_model)
|
||||
return StorageAccessoryEntity(
|
||||
storage_accessory_model.id,
|
||||
storage_accessory_model.current_count,
|
||||
storage_accessory_model.change_datetime,
|
||||
storage_accessory_model.storage_id,
|
||||
storage_accessory_model.accessory_id
|
||||
id=storage_accessory_model.id,
|
||||
current_count=storage_accessory_model.current_count,
|
||||
change_datetime=storage_accessory_model.change_datetime,
|
||||
storage_id=storage_accessory_model.storage_id,
|
||||
accessory_id=storage_accessory_model.accessory_id,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@ -15,11 +15,11 @@ class StorageService:
|
||||
storages = self.repository.get_all()
|
||||
return [
|
||||
StorageEntity(
|
||||
s.id,
|
||||
s.name,
|
||||
s.x_coordinate,
|
||||
s.y_coordinate,
|
||||
s.storage_accessories
|
||||
id=s.id,
|
||||
name=s.name,
|
||||
x_coordinate=s.x_coordinate,
|
||||
y_coordinate=s.y_coordinate,
|
||||
storage_accessories=s.storage_accessories,
|
||||
) for s in storages
|
||||
]
|
||||
|
||||
@ -27,11 +27,11 @@ class StorageService:
|
||||
storage = self.repository.get_by_id(storage_id)
|
||||
if storage:
|
||||
return StorageEntity(
|
||||
storage.id,
|
||||
storage.name,
|
||||
storage.x_coordinate,
|
||||
storage.y_coordinate,
|
||||
storage.storage_accessories
|
||||
id=storage.id,
|
||||
name=storage.name,
|
||||
x_coordinate=storage.x_coordinate,
|
||||
y_coordinate=storage.y_coordinate,
|
||||
storage_accessories=storage.storage_accessories,
|
||||
)
|
||||
|
||||
return None
|
||||
@ -45,11 +45,11 @@ class StorageService:
|
||||
)
|
||||
created_storage = self.repository.create(storage_model)
|
||||
return StorageEntity(
|
||||
created_storage.id,
|
||||
created_storage.name,
|
||||
created_storage.x_coordinate,
|
||||
created_storage.y_coordinate,
|
||||
created_storage.storage_accessories
|
||||
id=created_storage.id,
|
||||
name=created_storage.name,
|
||||
x_coordinate=created_storage.x_coordinate,
|
||||
y_coordinate=created_storage.y_coordinate,
|
||||
storage_accessories=created_storage.storage_accessories,
|
||||
)
|
||||
|
||||
def update_storage(self, storage_id: int, entity: StorageEntity) -> Optional[StorageEntity]:
|
||||
@ -61,11 +61,11 @@ class StorageService:
|
||||
storage_model.storage_accessories = entity.storage_accessories
|
||||
self.repository.update(storage_model)
|
||||
return StorageEntity(
|
||||
storage_model.id,
|
||||
storage_model.name,
|
||||
storage_model.x_coordinate,
|
||||
storage_model.y_coordinate,
|
||||
storage_model.storage_accessories
|
||||
id=storage_model.id,
|
||||
name=storage_model.name,
|
||||
x_coordinate=storage_model.x_coordinate,
|
||||
y_coordinate=storage_model.y_coordinate,
|
||||
storage_accessories=storage_model.storage_accessories,
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@ -42,12 +42,12 @@ class UserService:
|
||||
user = self.repository.get_by_login(login)
|
||||
if user:
|
||||
return UserEntity(
|
||||
user.id,
|
||||
user.first_name,
|
||||
user.last_name,
|
||||
user.login,
|
||||
user.password,
|
||||
user.role_id
|
||||
id=user.id,
|
||||
first_name=user.first_name,
|
||||
last_name=user.last_name,
|
||||
login=user.login,
|
||||
password=user.password,
|
||||
role_id=user.role_id
|
||||
)
|
||||
|
||||
return None
|
||||
@ -58,16 +58,16 @@ class UserService:
|
||||
last_name=entity.last_name,
|
||||
login=entity.login,
|
||||
password=entity.password,
|
||||
role_id=entity.role_id
|
||||
role_id=entity.role_id,
|
||||
)
|
||||
created_user = self.repository.create(user_model)
|
||||
return UserEntity(
|
||||
created_user.id,
|
||||
created_user.first_name,
|
||||
created_user.last_name,
|
||||
created_user.login,
|
||||
created_user.password,
|
||||
created_user.role_id
|
||||
id=created_user.id,
|
||||
first_name=created_user.first_name,
|
||||
last_name=created_user.last_name,
|
||||
login=created_user.login,
|
||||
password=created_user.password,
|
||||
role_id=created_user.role_id,
|
||||
)
|
||||
|
||||
def update_user(self, user_id: int, entity: UserEntity) -> Optional[UserEntity]:
|
||||
@ -80,12 +80,12 @@ class UserService:
|
||||
user_model.role_id = entity.role_id
|
||||
self.repository.update(user_model)
|
||||
return UserEntity(
|
||||
user_model.id,
|
||||
user_model.first_name,
|
||||
user_model.last_name,
|
||||
user_model.login,
|
||||
user_model.password,
|
||||
user_model.role_id
|
||||
id=user_model.id,
|
||||
first_name=user_model.first_name,
|
||||
last_name=user_model.last_name,
|
||||
login=user_model.login,
|
||||
password=user_model.password,
|
||||
role_id=user_model.role_id
|
||||
)
|
||||
|
||||
return None
|
||||
|
||||
@ -14,4 +14,4 @@ class Accessory(Base):
|
||||
length = Column(Float)
|
||||
weight = Column(Float)
|
||||
|
||||
storage_accessories = relationship('StorageAccessories', back_populates='accessories')
|
||||
storage_accessories = relationship('StorageAccessories', back_populates='accessory')
|
||||
|
||||
@ -13,5 +13,5 @@ class Delivery(Base):
|
||||
storage_accessories_id = Column(Integer, ForeignKey('storage_accessories.id'))
|
||||
step_id = Column(Integer, ForeignKey('steps.id'))
|
||||
|
||||
storage_accessories = relationship('StorageAccessories', back_populates='delivery')
|
||||
step = relationship('Step', back_populates='delivery')
|
||||
storage_accessory = relationship('StorageAccessories', back_populates='deliveries')
|
||||
step = relationship('Step', back_populates='deliveries')
|
||||
|
||||
@ -15,3 +15,5 @@ class Order(Base):
|
||||
|
||||
user = relationship('User', back_populates='orders')
|
||||
status = relationship('Status', back_populates='orders')
|
||||
|
||||
steps = relationship('Step', back_populates='order')
|
||||
@ -15,7 +15,7 @@ class StorageAccessories(Base):
|
||||
accessory_id = Column(Integer, ForeignKey('accessories.id'))
|
||||
|
||||
storage = relationship('Storage', back_populates='storage_accessories')
|
||||
accessory = relationship('Accessories', back_populates='storage_accessories')
|
||||
accessory = relationship('Accessory', back_populates='storage_accessories')
|
||||
|
||||
deliveries = relationship('Delivery', back_populates='storage_accessories')
|
||||
deliveries = relationship('Delivery', back_populates='storage_accessory')
|
||||
|
||||
|
||||
19
app/main.py
19
app/main.py
@ -1,6 +1,25 @@
|
||||
from fastapi import FastAPI
|
||||
from app.infrastructure.database.database import init_db
|
||||
from app.infrastructure.fastapi.user_routes import router as user_router
|
||||
from app.infrastructure.fastapi.storage_routes import router as storage_router
|
||||
from app.infrastructure.fastapi.storage_accessory_routes import router as storage_accessory_router
|
||||
from app.infrastructure.fastapi.step_routes import router as step_router
|
||||
from app.infrastructure.fastapi.status_routes import router as status_router
|
||||
from app.infrastructure.fastapi.role_routes import router as role_router
|
||||
from app.infrastructure.fastapi.order_routes import router as order_router
|
||||
from app.infrastructure.fastapi.delivery_routes import router as delivery_router
|
||||
from app.infrastructure.fastapi.accessory_routes import router as accessory_router
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
init_db()
|
||||
|
||||
app.include_router(user_router, prefix="/api/users", tags=["users"])
|
||||
app.include_router(storage_router, prefix="/api/storages", tags=["storages"])
|
||||
app.include_router(storage_accessory_router, prefix="/api/storage_accessories", tags=["storage_accessories"])
|
||||
app.include_router(step_router, prefix="/api/steps", tags=["steps"])
|
||||
app.include_router(status_router, prefix="/api/statuses", tags=["statuses"])
|
||||
app.include_router(role_router, prefix="/api/roles", tags=["roles"])
|
||||
app.include_router(order_router, prefix="/api/orders", tags=["orders"])
|
||||
app.include_router(delivery_router, prefix="/api/deliveries", tags=["deliveries"])
|
||||
app.include_router(accessory_router, prefix="/api/accessories", tags=["accessories"])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user