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