feat: removed price categories
This commit is contained in:
		@@ -15,18 +15,11 @@ from .shipping_warehouse import ShippingWarehouse
 | 
				
			|||||||
if TYPE_CHECKING:
 | 
					if TYPE_CHECKING:
 | 
				
			||||||
    from . import (
 | 
					    from . import (
 | 
				
			||||||
        DealBillRequest,
 | 
					        DealBillRequest,
 | 
				
			||||||
        ServicePriceCategory,
 | 
					 | 
				
			||||||
        DealGroup,
 | 
					        DealGroup,
 | 
				
			||||||
        User,
 | 
					        User,
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class DealPriceCategory(BaseModel):
 | 
					 | 
				
			||||||
    __tablename__ = 'deal_price_category'
 | 
					 | 
				
			||||||
    deal_id: Mapped[int] = mapped_column(ForeignKey('deals.id'), primary_key=True, unique=True)
 | 
					 | 
				
			||||||
    category_id: Mapped[int] = mapped_column(ForeignKey('service_price_category.id'), primary_key=True)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class Deal(BaseModel):
 | 
					class Deal(BaseModel):
 | 
				
			||||||
    __tablename__ = 'deals'
 | 
					    __tablename__ = 'deals'
 | 
				
			||||||
    id = Column(Integer, autoincrement=True, primary_key=True, index=True)
 | 
					    id = Column(Integer, autoincrement=True, primary_key=True, index=True)
 | 
				
			||||||
@@ -85,9 +78,7 @@ class Deal(BaseModel):
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    comment = Column(String, nullable=False, server_default='', comment='Коментарий к заданию')
 | 
					    comment = Column(String, nullable=False, server_default='', comment='Коментарий к заданию')
 | 
				
			||||||
    bill_request: Mapped[Optional['DealBillRequest']] = relationship(back_populates='deal', lazy='joined')
 | 
					    bill_request: Mapped[Optional['DealBillRequest']] = relationship(back_populates='deal', lazy='joined')
 | 
				
			||||||
    category: Mapped[Optional["ServicePriceCategory"]] = relationship('ServicePriceCategory',
 | 
					
 | 
				
			||||||
                                                                      secondary=DealPriceCategory.__table__,
 | 
					 | 
				
			||||||
                                                                      lazy='joined')
 | 
					 | 
				
			||||||
    group: Mapped[Optional["DealGroup"]] = relationship(
 | 
					    group: Mapped[Optional["DealGroup"]] = relationship(
 | 
				
			||||||
        'DealGroup',
 | 
					        'DealGroup',
 | 
				
			||||||
        secondary='deal_relations',
 | 
					        secondary='deal_relations',
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -9,7 +9,6 @@ services_kit_services = Table(
 | 
				
			|||||||
    BaseModel.metadata,
 | 
					    BaseModel.metadata,
 | 
				
			||||||
    Column('services_kit_id', ForeignKey('services_kits.id')),
 | 
					    Column('services_kit_id', ForeignKey('services_kits.id')),
 | 
				
			||||||
    Column('service_id', ForeignKey('services.id')),
 | 
					    Column('service_id', ForeignKey('services.id')),
 | 
				
			||||||
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -47,10 +46,6 @@ class Service(BaseModel):
 | 
				
			|||||||
                                lazy='selectin',
 | 
					                                lazy='selectin',
 | 
				
			||||||
                                order_by="asc(ServicePriceRange.from_quantity)",
 | 
					                                order_by="asc(ServicePriceRange.from_quantity)",
 | 
				
			||||||
                                cascade="all, delete-orphan")
 | 
					                                cascade="all, delete-orphan")
 | 
				
			||||||
    category_prices = relationship('ServiceCategoryPrice',
 | 
					 | 
				
			||||||
                                   back_populates='service',
 | 
					 | 
				
			||||||
                                   lazy='selectin',
 | 
					 | 
				
			||||||
                                   cascade="all, delete-orphan")
 | 
					 | 
				
			||||||
    rank: Mapped[str] = mapped_column(
 | 
					    rank: Mapped[str] = mapped_column(
 | 
				
			||||||
        nullable=False,
 | 
					        nullable=False,
 | 
				
			||||||
        server_default='',
 | 
					        server_default='',
 | 
				
			||||||
@@ -68,23 +63,6 @@ class ServicePriceRange(BaseModel):
 | 
				
			|||||||
    price = Column(Double, nullable=False, comment='Цена')
 | 
					    price = Column(Double, nullable=False, comment='Цена')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ServiceCategoryPrice(BaseModel):
 | 
					 | 
				
			||||||
    __tablename__ = 'service_category_prices'
 | 
					 | 
				
			||||||
    service_id: Mapped[int] = mapped_column(ForeignKey('services.id'), primary_key=True)
 | 
					 | 
				
			||||||
    category_id: Mapped[int] = mapped_column(ForeignKey('service_price_category.id'), primary_key=True)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    price: Mapped[float] = mapped_column(Double, nullable=False, comment='Цена')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    service: Mapped["Service"] = relationship('Service', lazy='joined', back_populates='category_prices')
 | 
					 | 
				
			||||||
    category: Mapped["ServicePriceCategory"] = relationship('ServicePriceCategory', lazy='joined')
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class ServicePriceCategory(BaseModel):
 | 
					 | 
				
			||||||
    __tablename__ = 'service_price_category'
 | 
					 | 
				
			||||||
    id: Mapped[int] = mapped_column(primary_key=True)
 | 
					 | 
				
			||||||
    name: Mapped[str] = mapped_column(nullable=False)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class ServiceCategory(BaseModel):
 | 
					class ServiceCategory(BaseModel):
 | 
				
			||||||
    __tablename__ = 'service_categories'
 | 
					    __tablename__ = 'service_categories'
 | 
				
			||||||
    id = Column(Integer, autoincrement=True, primary_key=True, index=True)
 | 
					    id = Column(Integer, autoincrement=True, primary_key=True, index=True)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -227,61 +227,6 @@ async def update_services_kit(
 | 
				
			|||||||
    return await ServiceService(session).update_kit(request)
 | 
					    return await ServiceService(session).update_kit(request)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# endregion
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# region Price Categories
 | 
					 | 
				
			||||||
# crud price categories
 | 
					 | 
				
			||||||
@service_router.get(
 | 
					 | 
				
			||||||
    '/price-categories/get-all',
 | 
					 | 
				
			||||||
    response_model=GetAllPriceCategoriesResponse,
 | 
					 | 
				
			||||||
    operation_id='get_all_price_categories',
 | 
					 | 
				
			||||||
    dependencies=[Depends(guest_user)]
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
async def get_all_price_categories(
 | 
					 | 
				
			||||||
        session: SessionDependency
 | 
					 | 
				
			||||||
):
 | 
					 | 
				
			||||||
    return await ServiceService(session).get_all_price_categories()
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@service_router.post(
 | 
					 | 
				
			||||||
    '/price-categories/create',
 | 
					 | 
				
			||||||
    response_model=CreatePriceCategoryResponse,
 | 
					 | 
				
			||||||
    operation_id='create_price_category',
 | 
					 | 
				
			||||||
    dependencies=[Depends(authorized_user)]
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
async def create_price_category(
 | 
					 | 
				
			||||||
        session: SessionDependency,
 | 
					 | 
				
			||||||
        request: CreatePriceCategoryRequest
 | 
					 | 
				
			||||||
):
 | 
					 | 
				
			||||||
    return await ServiceService(session).create_price_category(request)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@service_router.post(
 | 
					 | 
				
			||||||
    '/price-categories/update',
 | 
					 | 
				
			||||||
    response_model=UpdatePriceCategoryResponse,
 | 
					 | 
				
			||||||
    operation_id='update_price_category',
 | 
					 | 
				
			||||||
    dependencies=[Depends(authorized_user)]
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
async def update_price_category(
 | 
					 | 
				
			||||||
        session: SessionDependency,
 | 
					 | 
				
			||||||
        request: UpdatePriceCategoryRequest
 | 
					 | 
				
			||||||
):
 | 
					 | 
				
			||||||
    return await ServiceService(session).update_price_category(request)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@service_router.post(
 | 
					 | 
				
			||||||
    '/price-categories/delete',
 | 
					 | 
				
			||||||
    response_model=DeletePriceCategoryResponse,
 | 
					 | 
				
			||||||
    operation_id='delete_price_category',
 | 
					 | 
				
			||||||
    dependencies=[Depends(authorized_user)]
 | 
					 | 
				
			||||||
)
 | 
					 | 
				
			||||||
async def delete_price_category(
 | 
					 | 
				
			||||||
        session: SessionDependency,
 | 
					 | 
				
			||||||
        request: DeletePriceCategoryRequest
 | 
					 | 
				
			||||||
):
 | 
					 | 
				
			||||||
    return await ServiceService(session).delete_price_category(request)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# endregion
 | 
					# endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# region Exports
 | 
					# region Exports
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,7 +10,7 @@ from schemas.client import ClientSchema
 | 
				
			|||||||
from schemas.group import DealGroupSchema
 | 
					from schemas.group import DealGroupSchema
 | 
				
			||||||
from schemas.marketplace import BaseMarketplaceSchema
 | 
					from schemas.marketplace import BaseMarketplaceSchema
 | 
				
			||||||
from schemas.product import ProductSchema
 | 
					from schemas.product import ProductSchema
 | 
				
			||||||
from schemas.service import ServiceSchema, ServicePriceCategorySchema
 | 
					from schemas.service import ServiceSchema
 | 
				
			||||||
from schemas.shipping import PalletSchema, BoxSchema
 | 
					from schemas.shipping import PalletSchema, BoxSchema
 | 
				
			||||||
from schemas.shipping_warehouse import ShippingWarehouseSchema, BaseShippingWarehouseSchema
 | 
					from schemas.shipping_warehouse import ShippingWarehouseSchema, BaseShippingWarehouseSchema
 | 
				
			||||||
from schemas.status import StatusSchema, DealStatusHistorySchema
 | 
					from schemas.status import StatusSchema, DealStatusHistorySchema
 | 
				
			||||||
@@ -91,7 +91,6 @@ class DealSchema(BaseSchema):
 | 
				
			|||||||
    comment: str
 | 
					    comment: str
 | 
				
			||||||
    shipping_warehouse: Optional[Union[ShippingWarehouseSchema, str]] = None
 | 
					    shipping_warehouse: Optional[Union[ShippingWarehouseSchema, str]] = None
 | 
				
			||||||
    bill_request: Optional[DealBillRequestSchema] = None
 | 
					    bill_request: Optional[DealBillRequestSchema] = None
 | 
				
			||||||
    category: Optional[ServicePriceCategorySchema] = None
 | 
					 | 
				
			||||||
    group: Optional[DealGroupSchema] = None
 | 
					    group: Optional[DealGroupSchema] = None
 | 
				
			||||||
    manager: Optional[UserSchema] = None
 | 
					    manager: Optional[UserSchema] = None
 | 
				
			||||||
    pallets: List[PalletSchema] = []
 | 
					    pallets: List[PalletSchema] = []
 | 
				
			||||||
@@ -163,7 +162,6 @@ class DealQuickCreateRequest(BaseSchema):
 | 
				
			|||||||
    acceptance_date: datetime.datetime
 | 
					    acceptance_date: datetime.datetime
 | 
				
			||||||
    shipping_warehouse: constr(strip_whitespace=True)
 | 
					    shipping_warehouse: constr(strip_whitespace=True)
 | 
				
			||||||
    base_marketplace: BaseMarketplaceSchema
 | 
					    base_marketplace: BaseMarketplaceSchema
 | 
				
			||||||
    category: Optional[ServicePriceCategorySchema] = None
 | 
					 | 
				
			||||||
    status_id: int
 | 
					    status_id: int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -20,16 +20,6 @@ class ServiceCategorySchema(BaseSchema):
 | 
				
			|||||||
    product_service_rank: str
 | 
					    product_service_rank: str
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ServicePriceCategorySchema(BaseSchema):
 | 
					 | 
				
			||||||
    id: int
 | 
					 | 
				
			||||||
    name: str
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class ServiceCategoryPriceSchema(BaseSchema):
 | 
					 | 
				
			||||||
    category: ServicePriceCategorySchema
 | 
					 | 
				
			||||||
    price: float
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class ServiceSchema(BaseSchema):
 | 
					class ServiceSchema(BaseSchema):
 | 
				
			||||||
    id: int
 | 
					    id: int
 | 
				
			||||||
    name: str
 | 
					    name: str
 | 
				
			||||||
@@ -37,7 +27,6 @@ class ServiceSchema(BaseSchema):
 | 
				
			|||||||
    price: float
 | 
					    price: float
 | 
				
			||||||
    service_type: int
 | 
					    service_type: int
 | 
				
			||||||
    price_ranges: List[ServicePriceRangeSchema]
 | 
					    price_ranges: List[ServicePriceRangeSchema]
 | 
				
			||||||
    category_prices: List[ServiceCategoryPriceSchema]
 | 
					 | 
				
			||||||
    cost: Optional[int]
 | 
					    cost: Optional[int]
 | 
				
			||||||
    rank: str
 | 
					    rank: str
 | 
				
			||||||
    is_placeholder: Optional[bool] = False
 | 
					    is_placeholder: Optional[bool] = False
 | 
				
			||||||
@@ -65,10 +54,6 @@ class UpdateServiceKitSchema(BaseServiceKitSchema):
 | 
				
			|||||||
    services_ids: List[int]
 | 
					    services_ids: List[int]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# endregion
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# region Category prices
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# endregion
 | 
					# endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# endregion
 | 
					# endregion
 | 
				
			||||||
@@ -170,22 +155,6 @@ class GetAllServicesKitsResponse(BaseSchema):
 | 
				
			|||||||
    services_kits: List[GetServiceKitSchema]
 | 
					    services_kits: List[GetServiceKitSchema]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class GetAllPriceCategoriesResponse(BaseSchema):
 | 
					 | 
				
			||||||
    price_categories: List[ServicePriceCategorySchema]
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class CreatePriceCategoryResponse(OkMessageSchema):
 | 
					 | 
				
			||||||
    pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class UpdatePriceCategoryResponse(OkMessageSchema):
 | 
					 | 
				
			||||||
    pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class DeletePriceCategoryResponse(OkMessageSchema):
 | 
					 | 
				
			||||||
    pass
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
class ServiceReorderResponse(OkMessageSchema):
 | 
					class ServiceReorderResponse(OkMessageSchema):
 | 
				
			||||||
    pass
 | 
					    pass
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -118,15 +118,6 @@ class DealService(BaseService):
 | 
				
			|||||||
            base_marketplace_key=request.base_marketplace.key
 | 
					            base_marketplace_key=request.base_marketplace.key
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        self.session.add(deal)
 | 
					        self.session.add(deal)
 | 
				
			||||||
        await self.session.flush()
 | 
					 | 
				
			||||||
        # add category if specified
 | 
					 | 
				
			||||||
        if request.category:
 | 
					 | 
				
			||||||
            deal_category = DealPriceCategory(
 | 
					 | 
				
			||||||
                deal_id=deal.id,
 | 
					 | 
				
			||||||
                category_id=request.category.id
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
            self.session.add(deal_category)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        await self.session.commit()
 | 
					        await self.session.commit()
 | 
				
			||||||
        return DealQuickCreateResponse(deal_id=deal.id)
 | 
					        return DealQuickCreateResponse(deal_id=deal.id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,8 +5,7 @@ from sqlalchemy.exc import IntegrityError
 | 
				
			|||||||
from sqlalchemy.orm import joinedload
 | 
					from sqlalchemy.orm import joinedload
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from enums.service import ServiceType
 | 
					from enums.service import ServiceType
 | 
				
			||||||
from models import Service, ServiceCategory, ServicePriceRange, ServicesKit, services_kit_services, \
 | 
					from models import Service, ServiceCategory, ServicePriceRange, ServicesKit, services_kit_services
 | 
				
			||||||
    ServiceCategoryPrice, ServicePriceCategory
 | 
					 | 
				
			||||||
from schemas.service import *
 | 
					from schemas.service import *
 | 
				
			||||||
from services.base import BaseService
 | 
					from services.base import BaseService
 | 
				
			||||||
from utils.list_utils import previous_current_next
 | 
					from utils.list_utils import previous_current_next
 | 
				
			||||||
@@ -62,7 +61,6 @@ class ServiceService(BaseService):
 | 
				
			|||||||
                    price=0,
 | 
					                    price=0,
 | 
				
			||||||
                    service_type=service_type,
 | 
					                    service_type=service_type,
 | 
				
			||||||
                    price_ranges=[],
 | 
					                    price_ranges=[],
 | 
				
			||||||
                    category_prices=[],
 | 
					 | 
				
			||||||
                    cost=0,
 | 
					                    cost=0,
 | 
				
			||||||
                    rank='',
 | 
					                    rank='',
 | 
				
			||||||
                    is_placeholder=True
 | 
					                    is_placeholder=True
 | 
				
			||||||
@@ -88,7 +86,6 @@ class ServiceService(BaseService):
 | 
				
			|||||||
            del service_dict['id']
 | 
					            del service_dict['id']
 | 
				
			||||||
            del service_dict['category']
 | 
					            del service_dict['category']
 | 
				
			||||||
            del service_dict['price_ranges']
 | 
					            del service_dict['price_ranges']
 | 
				
			||||||
            del service_dict['category_prices']
 | 
					 | 
				
			||||||
            del service_dict['is_placeholder']
 | 
					            del service_dict['is_placeholder']
 | 
				
			||||||
            service_type = ServiceType(raw_service.service_type)
 | 
					            service_type = ServiceType(raw_service.service_type)
 | 
				
			||||||
            category_id = raw_service.category.id
 | 
					            category_id = raw_service.category.id
 | 
				
			||||||
@@ -110,15 +107,6 @@ class ServiceService(BaseService):
 | 
				
			|||||||
                del price_range_dict['id']
 | 
					                del price_range_dict['id']
 | 
				
			||||||
                price_range_obj = ServicePriceRange(**price_range_dict)
 | 
					                price_range_obj = ServicePriceRange(**price_range_dict)
 | 
				
			||||||
                self.session.add(price_range_obj)
 | 
					                self.session.add(price_range_obj)
 | 
				
			||||||
            category_prices = request.service.category_prices
 | 
					 | 
				
			||||||
            for category_price in category_prices:
 | 
					 | 
				
			||||||
                category_price_dict = category_price.model_dump()
 | 
					 | 
				
			||||||
                category_price_dict['service_id'] = service.id
 | 
					 | 
				
			||||||
                category_price_dict['category_id'] = category_price.category.id
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                del category_price_dict['category']
 | 
					 | 
				
			||||||
                category_price_obj = ServiceCategoryPrice(**category_price_dict)
 | 
					 | 
				
			||||||
                self.session.add(category_price_obj)
 | 
					 | 
				
			||||||
            await self.session.commit()
 | 
					            await self.session.commit()
 | 
				
			||||||
            return ServiceCreateResponse(ok=True, message="Услуга успешно создана")
 | 
					            return ServiceCreateResponse(ok=True, message="Услуга успешно создана")
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
@@ -136,7 +124,6 @@ class ServiceService(BaseService):
 | 
				
			|||||||
            service_dict['category_id'] = raw_service.category.id
 | 
					            service_dict['category_id'] = raw_service.category.id
 | 
				
			||||||
            del service_dict['category']
 | 
					            del service_dict['category']
 | 
				
			||||||
            del service_dict['price_ranges']
 | 
					            del service_dict['price_ranges']
 | 
				
			||||||
            del service_dict['category_prices']
 | 
					 | 
				
			||||||
            del service_dict['is_placeholder']
 | 
					            del service_dict['is_placeholder']
 | 
				
			||||||
            if prev_category_id != new_category_id:
 | 
					            if prev_category_id != new_category_id:
 | 
				
			||||||
                latest_rank = await self.get_latest_rank_in_category(new_category_id, ServiceType(raw_service.service_type))
 | 
					                latest_rank = await self.get_latest_rank_in_category(new_category_id, ServiceType(raw_service.service_type))
 | 
				
			||||||
@@ -173,25 +160,6 @@ class ServiceService(BaseService):
 | 
				
			|||||||
                    price_range_obj = ServicePriceRange(**price_range_dict)
 | 
					                    price_range_obj = ServicePriceRange(**price_range_dict)
 | 
				
			||||||
                    self.session.add(price_range_obj)
 | 
					                    self.session.add(price_range_obj)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            # deleting previouse category prices
 | 
					 | 
				
			||||||
            stmt = (
 | 
					 | 
				
			||||||
                delete(
 | 
					 | 
				
			||||||
                    ServiceCategoryPrice
 | 
					 | 
				
			||||||
                ).where(
 | 
					 | 
				
			||||||
                    ServiceCategoryPrice.service_id == service.id
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
            await self.session.execute(stmt)
 | 
					 | 
				
			||||||
            await self.session.flush()
 | 
					 | 
				
			||||||
            # inserting new category prices
 | 
					 | 
				
			||||||
            for category_price in raw_service.category_prices:
 | 
					 | 
				
			||||||
                category_price_dict = category_price.dict()
 | 
					 | 
				
			||||||
                category_price_dict['service_id'] = raw_service.id
 | 
					 | 
				
			||||||
                category_price_dict['category_id'] = category_price.category.id
 | 
					 | 
				
			||||||
                del category_price_dict['category']
 | 
					 | 
				
			||||||
                category_price_obj = ServiceCategoryPrice(**category_price_dict)
 | 
					 | 
				
			||||||
                self.session.add(category_price_obj)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await self.session.commit()
 | 
					            await self.session.commit()
 | 
				
			||||||
            return ServiceUpdateResponse(ok=True, message="Услуга успешно обновлена")
 | 
					            return ServiceUpdateResponse(ok=True, message="Услуга успешно обновлена")
 | 
				
			||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
@@ -345,63 +313,6 @@ class ServiceService(BaseService):
 | 
				
			|||||||
        except Exception as e:
 | 
					        except Exception as e:
 | 
				
			||||||
            return UpdateServicesKitResponse(ok=False, message=str(e))
 | 
					            return UpdateServicesKitResponse(ok=False, message=str(e))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    async def get_all_price_categories(self) -> GetAllPriceCategoriesResponse:
 | 
					 | 
				
			||||||
        query = await (self.session
 | 
					 | 
				
			||||||
                       .scalars(select(ServicePriceCategory)
 | 
					 | 
				
			||||||
                                .order_by(ServicePriceCategory.id)))
 | 
					 | 
				
			||||||
        price_categories = []
 | 
					 | 
				
			||||||
        for category in query.all():
 | 
					 | 
				
			||||||
            price_categories.append(ServicePriceCategorySchema.model_validate(category))
 | 
					 | 
				
			||||||
        return GetAllPriceCategoriesResponse(price_categories=price_categories)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    async def create_price_category(self, request: CreatePriceCategoryRequest) -> ServiceCreateCategoryResponse:
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            raw_category = request.name
 | 
					 | 
				
			||||||
            category = ServicePriceCategory(name=raw_category)
 | 
					 | 
				
			||||||
            self.session.add(category)
 | 
					 | 
				
			||||||
            await self.session.commit()
 | 
					 | 
				
			||||||
            return ServiceCreateCategoryResponse(ok=True, message="Категория цен успешно создана")
 | 
					 | 
				
			||||||
        except Exception as e:
 | 
					 | 
				
			||||||
            return ServiceCreateCategoryResponse(ok=False, message=f"Неудалось создать категорию цен, ошибка: {e}")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    async def update_price_category(self, request: UpdatePriceCategoryRequest) -> ServiceUpdateResponse:
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            raw_category = request.name
 | 
					 | 
				
			||||||
            category = await (self.session.get(ServicePriceCategory, request.id))
 | 
					 | 
				
			||||||
            if not category:
 | 
					 | 
				
			||||||
                return ServiceUpdateResponse(ok=False, message="Категория цен не найдена")
 | 
					 | 
				
			||||||
            await self.session.execute(
 | 
					 | 
				
			||||||
                update(ServicePriceCategory)
 | 
					 | 
				
			||||||
                .where(ServicePriceCategory.id == request.id)
 | 
					 | 
				
			||||||
                .values(name=raw_category)
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
            await self.session.commit()
 | 
					 | 
				
			||||||
            return ServiceUpdateResponse(ok=True, message="Категория цен успешно обновлена")
 | 
					 | 
				
			||||||
        except Exception as e:
 | 
					 | 
				
			||||||
            return ServiceUpdateResponse(ok=False, message=f"Неудалось обновить категорию цен, ошибка: {e}")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    async def delete_price_category(self, request: DeletePriceCategoryRequest) -> ServiceDeleteResponse:
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            category = await (
 | 
					 | 
				
			||||||
                self.session
 | 
					 | 
				
			||||||
                .scalar(
 | 
					 | 
				
			||||||
                    select(
 | 
					 | 
				
			||||||
                        ServicePriceCategory
 | 
					 | 
				
			||||||
                    )
 | 
					 | 
				
			||||||
                    .filter(
 | 
					 | 
				
			||||||
                        ServicePriceCategory.id == request.id
 | 
					 | 
				
			||||||
                    )
 | 
					 | 
				
			||||||
                )
 | 
					 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
            if not category:
 | 
					 | 
				
			||||||
                return ServiceDeleteResponse(ok=False, message="Категория цен не найдена")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            await self.session.delete(category)
 | 
					 | 
				
			||||||
            await self.session.commit()
 | 
					 | 
				
			||||||
            return ServiceDeleteResponse(ok=True, message="Категория цен успешно удалена")
 | 
					 | 
				
			||||||
        except Exception as e:
 | 
					 | 
				
			||||||
            return ServiceDeleteResponse(ok=False, message=f"Неудалось удалить категорию цен, ошибка: {e}")
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    async def reorder(self, request: ServiceReorderRequest) -> ServiceReorderResponse:
 | 
					    async def reorder(self, request: ServiceReorderRequest) -> ServiceReorderResponse:
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            draining_service = await (self.session.get(Service, request.draining_service_id))
 | 
					            draining_service = await (self.session.get(Service, request.draining_service_id))
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user