From e7235021f91207161e5e34948b94cb1b02a520b6 Mon Sep 17 00:00:00 2001 From: fakz9 Date: Thu, 18 Jul 2024 04:57:05 +0300 Subject: [PATCH] feat: shipping warehouse and cost --- main.py | 3 +- models/__init__.py | 2 + models/base.py | 11 +- models/deal.py | 6 +- models/service.py | 14 +- models/shipping_warehouse.py | 9 + routers/__init__.py | 1 + routers/shipping_warehouse.py | 28 + schemas/base.py | 1 + schemas/deal.py | 11 +- schemas/service.py | 1 + schemas/shipping_warehouse.py | 12 + services/deal.py | 16 +- services/shipping_warehouse.py | 37 + test.py | 9 + test/ockho.py | 16 - test/test.json | 1241 -------------------------------- test/test.py | 28 - 18 files changed, 148 insertions(+), 1298 deletions(-) create mode 100644 models/shipping_warehouse.py create mode 100644 routers/shipping_warehouse.py create mode 100644 schemas/shipping_warehouse.py create mode 100644 services/shipping_warehouse.py create mode 100644 test.py delete mode 100644 test/ockho.py delete mode 100644 test/test.json delete mode 100644 test/test.py diff --git a/main.py b/main.py index 52cb0ea..c3d5fe9 100644 --- a/main.py +++ b/main.py @@ -31,7 +31,8 @@ routers_list = [ routers.client_router, routers.service_router, routers.product_router, - routers.barcode_router + routers.barcode_router, + routers.shipping_warehouse_router ] for router in routers_list: app.include_router(router) diff --git a/models/__init__.py b/models/__init__.py index c2803b4..99e304e 100644 --- a/models/__init__.py +++ b/models/__init__.py @@ -7,4 +7,6 @@ from .service import * from .product import * from .secondary import * from .barcode import * +from .shipping_warehouse import * + configure_mappers() diff --git a/models/base.py b/models/base.py index 6e3aeab..07d499f 100644 --- a/models/base.py +++ b/models/base.py @@ -1,4 +1,9 @@ -from sqlalchemy.orm import declarative_base +from sqlalchemy.ext.asyncio import AsyncAttrs +from sqlalchemy.orm import declarative_base, DeclarativeBase -BaseModel = declarative_base() -metadata = BaseModel.metadata \ No newline at end of file + +class BaseModel(DeclarativeBase, AsyncAttrs): + pass + + +metadata = BaseModel.metadata diff --git a/models/deal.py b/models/deal.py index 6c32557..95b71ee 100644 --- a/models/deal.py +++ b/models/deal.py @@ -1,9 +1,10 @@ from enum import IntEnum, unique from sqlalchemy import Column, Integer, String, DateTime, ForeignKey, Boolean -from sqlalchemy.orm import relationship, backref +from sqlalchemy.orm import relationship, backref, Mapped, mapped_column from models.base import BaseModel +from .shipping_warehouse import ShippingWarehouse @unique @@ -32,6 +33,9 @@ class Deal(BaseModel): is_deleted = Column(Boolean, nullable=False, server_default='0', default=False, comment='Удалена') is_completed = Column(Boolean, nullable=False, server_default='0', default=False, comment='Завершена') + shipping_warehouse_id: Mapped[int] = mapped_column(ForeignKey('shipping_warehouses.id'), nullable=True) + shipping_warehouse: Mapped["ShippingWarehouse"] = relationship() + services = relationship('DealService', back_populates='deal', cascade="all, delete-orphan") products = relationship('DealProduct', back_populates='deal', cascade="all, delete-orphan") diff --git a/models/service.py b/models/service.py index 1f41091..d25a872 100644 --- a/models/service.py +++ b/models/service.py @@ -13,12 +13,22 @@ class Service(BaseModel): category_id = Column(Integer, ForeignKey('service_categories.id'), nullable=False, comment='ID категории услуги') category = relationship('ServiceCategory', lazy='joined') - price = Column(Double, nullable=False, comment='Стоимость услуги') + price = Column( + Double, + nullable=False, + comment='Стоимость услуги' + ) + cost = Column( + Double, + nullable=False, + server_default='0', + comment='Себестоимость услуги' + ) + service_type = Column(Integer, server_default=f'{enums.service.ServiceType.DEAL_SERVICE}', nullable=False, comment='Тип услуги') - price_ranges = relationship('ServicePriceRange', back_populates='service', lazy='selectin', diff --git a/models/shipping_warehouse.py b/models/shipping_warehouse.py new file mode 100644 index 0000000..78e5d52 --- /dev/null +++ b/models/shipping_warehouse.py @@ -0,0 +1,9 @@ +from sqlalchemy.orm import Mapped, mapped_column + +from models import BaseModel + + +class ShippingWarehouse(BaseModel): + __tablename__ = 'shipping_warehouses' + id: Mapped[int] = mapped_column(primary_key=True) + name: Mapped[str] = mapped_column(nullable=False) diff --git a/routers/__init__.py b/routers/__init__.py index a22495c..5d0c211 100644 --- a/routers/__init__.py +++ b/routers/__init__.py @@ -4,3 +4,4 @@ from .client import client_router from .service import service_router from .product import product_router from .barcode import barcode_router +from .shipping_warehouse import shipping_warehouse_router diff --git a/routers/shipping_warehouse.py b/routers/shipping_warehouse.py new file mode 100644 index 0000000..3efb6f2 --- /dev/null +++ b/routers/shipping_warehouse.py @@ -0,0 +1,28 @@ +from typing import Annotated + +from fastapi import APIRouter, Depends +from sqlalchemy.ext.asyncio import AsyncSession + +from backend.session import get_session +from schemas.shipping_warehouse import GetAllShippingWarehousesResponse +from services.auth import get_current_user +from services.shipping_warehouse import ShippingWarehouseService + +shipping_warehouse_router = APIRouter( + prefix="/shipping-warehouse", + tags=["shipping-warehouse"], + dependencies=[Depends(get_current_user)] +) + + +@shipping_warehouse_router.get( + '/get-all', + response_model=GetAllShippingWarehousesResponse, + operation_id='get_all_shipping_warehouses' +) +async def get_all( + session: Annotated[AsyncSession, Depends(get_session)] +): + return await ShippingWarehouseService(session).get_all() + + diff --git a/schemas/base.py b/schemas/base.py index 1ddfc12..651b0ac 100644 --- a/schemas/base.py +++ b/schemas/base.py @@ -13,6 +13,7 @@ class CustomModelCamel(BaseModel): alias_generator = to_camel populate_by_name = True + @classmethod def from_sql_model(cls, model, fields: dict): model_dict = {c.name: getattr(model, c.name) for c in model.__table__.columns} diff --git a/schemas/deal.py b/schemas/deal.py index f1c401b..1b620f3 100644 --- a/schemas/deal.py +++ b/schemas/deal.py @@ -1,10 +1,13 @@ import datetime -from typing import List +from typing import List, Optional + +from pydantic import constr from schemas.base import CustomModelCamel, OkMessageSchema from schemas.client import ClientSchema from schemas.product import ProductSchema from schemas.service import ServiceSchema +from schemas.shipping_warehouse import ShippingWarehouseSchema from schemas.user import UserSchema @@ -66,6 +69,7 @@ class DealSchema(CustomModelCamel): is_completed: bool client: ClientSchema comment: str + shipping_warehouse: Optional[ShippingWarehouseSchema] = None class DealGeneralInfoSchema(CustomModelCamel): @@ -88,10 +92,11 @@ class DealCreateRequest(CustomModelCamel): class DealQuickCreateRequest(CustomModelCamel): - name: str - client_name: str + name: constr(strip_whitespace=True) + client_name: constr(strip_whitespace=True) comment: str acceptance_date: datetime.datetime + shipping_warehouse: constr(strip_whitespace=True) class DealSummaryRequest(CustomModelCamel): diff --git a/schemas/service.py b/schemas/service.py index 52e7b81..4dc8ddc 100644 --- a/schemas/service.py +++ b/schemas/service.py @@ -23,6 +23,7 @@ class ServiceSchema(CustomModelCamel): price: float service_type: int price_ranges: List[ServicePriceRangeSchema] + cost: Optional[int] # endregion diff --git a/schemas/shipping_warehouse.py b/schemas/shipping_warehouse.py new file mode 100644 index 0000000..131f18f --- /dev/null +++ b/schemas/shipping_warehouse.py @@ -0,0 +1,12 @@ +from typing import List + +from schemas.base import CustomModelCamel + + +class ShippingWarehouseSchema(CustomModelCamel): + id: int + name: str + + +class GetAllShippingWarehousesResponse(CustomModelCamel): + shipping_warehouses: List[ShippingWarehouseSchema] diff --git a/services/deal.py b/services/deal.py index b0bb916..12cdc7e 100644 --- a/services/deal.py +++ b/services/deal.py @@ -13,6 +13,7 @@ from schemas.client import ClientDetailsSchema from schemas.deal import * from services.base import BaseService from services.client import ClientService +from services.shipping_warehouse import ShippingWarehouseService class DealService(BaseService): @@ -90,6 +91,10 @@ class DealService(BaseService): request.client_name, ClientDetailsSchema() ) + shipping_warehouse_service = ShippingWarehouseService(self.session) + shipping_warehouse = await shipping_warehouse_service.get_by_name(name=request.shipping_warehouse) + if not shipping_warehouse: + shipping_warehouse = await shipping_warehouse_service.create_by_name(name=request.shipping_warehouse) rank = await self._get_rank_for_deal(DealStatus.CREATED) deal = Deal( @@ -97,7 +102,8 @@ class DealService(BaseService): created_at=datetime.datetime.now(), client_id=client.id, current_status=DealStatus.CREATED, - lexorank=rank + lexorank=rank, + shipping_warehouse_id=shipping_warehouse.id ) self.session.add(deal) await self.session.flush() @@ -167,7 +173,8 @@ class DealService(BaseService): price_subquery, Deal.id == price_subquery.c.deal_id) .where( Deal.is_deleted == False, - Deal.is_completed == False + Deal.is_completed == False, + Deal.current_status != DealStatus.COMPLETED ) ) deals_query = await self.session.execute(q) @@ -203,7 +210,9 @@ class DealService(BaseService): deal = await self.session.scalar( select(Deal) .options( - joinedload(Deal.client).joinedload(Client.details), + joinedload(Deal.shipping_warehouse), + joinedload(Deal.client) + .joinedload(Client.details), selectinload(Deal.services) .joinedload(models.secondary.DealService.service) .joinedload(Service.category), @@ -220,6 +229,7 @@ class DealService(BaseService): .joinedload(DealStatusHistory.user), selectinload(Deal.status_history) .noload(DealStatusHistory.deal), + ) .where(Deal.id == deal_id) ) diff --git a/services/shipping_warehouse.py b/services/shipping_warehouse.py new file mode 100644 index 0000000..4f391e7 --- /dev/null +++ b/services/shipping_warehouse.py @@ -0,0 +1,37 @@ +from typing import Union + +from sqlalchemy import select + +import models +from schemas.shipping_warehouse import GetAllShippingWarehousesResponse, ShippingWarehouseSchema +from services.base import BaseService + + +class ShippingWarehouseService(BaseService): + async def get_all(self) -> GetAllShippingWarehousesResponse: + stmt = ( + select( + models.ShippingWarehouse + ) + .order_by( + models.ShippingWarehouse.id + ) + ) + shipping_warehouses = (await self.session.scalars(stmt)).all() + result = [] + for shipping_warehouse in shipping_warehouses: + result.append(ShippingWarehouseSchema.model_validate(shipping_warehouse)) + return GetAllShippingWarehousesResponse(shipping_warehouses=result) + + async def get_by_name(self, name: str) -> Union[models.ShippingWarehouse, None]: + stmt = select(models.ShippingWarehouse).where(models.ShippingWarehouse.name == name) + shipping_warehouse = await self.session.scalar(stmt) + return shipping_warehouse + + async def create_by_name(self, name: str) -> models.ShippingWarehouse: + shipping_warehouse = models.ShippingWarehouse( + name=name + ) + self.session.add(shipping_warehouse) + await self.session.flush() + return shipping_warehouse diff --git a/test.py b/test.py new file mode 100644 index 0000000..67aa148 --- /dev/null +++ b/test.py @@ -0,0 +1,9 @@ +import struct +import sys + +sys.set_int_max_str_digits(-0) +with open('Дизайн.jpg', 'rb') as rf: + data = int.from_bytes(rf.read()) + +with open('result', 'wb') as rf: + rf.write(data.to_bytes(length=len(str(data)))) diff --git a/test/ockho.py b/test/ockho.py deleted file mode 100644 index 4fd112b..0000000 --- a/test/ockho.py +++ /dev/null @@ -1,16 +0,0 @@ -from pprint import pprint - -import lexorank -from lexorank import Bucket, middle - -prev = middle(Bucket.BUCEKT_0) -ranks = [prev] -for _ in range(9): - ranks.append(prev.next()) - prev = ranks[-1] -middle_ranks = lexorank.between(ranks[1], ranks[2]) -pprint(ranks) -print('----------') -ranks.append(middle_ranks) -ranks = sorted(ranks) -pprint(ranks) diff --git a/test/test.json b/test/test.json deleted file mode 100644 index 858b580..0000000 --- a/test/test.json +++ /dev/null @@ -1,1241 +0,0 @@ -{ - "openapi": "3.1.0", - "info": { - "title": "FastAPI", - "version": "0.1.0" - }, - "paths": { - "/auth/login": { - "post": { - "tags": [ - "auth" - ], - "summary": "Login", - "operationId": "login_auth_login_post", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AuthLoginRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AuthLoginResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - }, - "/deal/create": { - "post": { - "tags": [ - "deal" - ], - "summary": "Create", - "operationId": "create_deal_create_post", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DealCreateRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": {} - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - }, - "security": [ - { - "HTTPBearer": [] - } - ] - } - }, - "/deal/quickCreate": { - "post": { - "tags": [ - "deal" - ], - "summary": "Quick Create", - "operationId": "quick_create_deal_quickCreate_post", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DealQuickCreateRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DealQuickCreateResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - }, - "security": [ - { - "HTTPBearer": [] - } - ] - } - }, - "/deal/changeStatus": { - "post": { - "tags": [ - "deal" - ], - "summary": "Change Status", - "operationId": "change_status_deal_changeStatus_post", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DealChangeStatusRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DealChangeStatusResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - }, - "security": [ - { - "HTTPBearer": [] - } - ] - } - }, - "/deal/summaries": { - "get": { - "tags": [ - "deal" - ], - "summary": "Get Summary", - "operationId": "getDealSummaries", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DealSummaryResponse" - } - } - } - } - } - } - }, - "/deal/services/add": { - "post": { - "tags": [ - "deal" - ], - "summary": "Services Add", - "operationId": "services_add_deal_services_add_post", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DealAddServicesRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/DealAddServicesResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - }, - "/client/search": { - "get": { - "tags": [ - "client" - ], - "summary": "Search Clients", - "operationId": "search_clients", - "parameters": [ - { - "name": "name", - "in": "query", - "required": true, - "schema": { - "type": "string", - "title": "Name" - } - } - ], - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": {} - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - }, - "/client/update-details": { - "post": { - "tags": [ - "client" - ], - "summary": "Update Client Details", - "operationId": "update_client_details_client_update_details_post", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ClientUpdateDetailsRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": {} - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - }, - "security": [ - { - "HTTPBearer": [] - } - ] - } - }, - "/client/get-all": { - "get": { - "tags": [ - "client" - ], - "summary": "Get All Clients", - "operationId": "get_all_clients", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ClientGetAllResponse" - } - } - } - } - } - } - }, - "/service/get-all": { - "get": { - "tags": [ - "service" - ], - "summary": "Get All", - "operationId": "get_all_services", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ServiceGetAllResponse" - } - } - } - } - } - } - }, - "/service/create": { - "post": { - "tags": [ - "service" - ], - "summary": "Create", - "operationId": "create_service", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ServiceCreateRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ServiceCreateResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - }, - "/service/categories/get-all": { - "get": { - "tags": [ - "service" - ], - "summary": "Get All Categories", - "operationId": "get_all_service_categories", - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ServiceGetAllCategoriesResponse" - } - } - } - } - } - } - }, - "/service/categories/create": { - "post": { - "tags": [ - "service" - ], - "summary": "Create Category", - "operationId": "create_service_category", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ServiceCreateCategoryRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ServiceCreateCategoryResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - }, - "/product/create": { - "post": { - "tags": [ - "product" - ], - "summary": "Create Product", - "operationId": "create_product", - "requestBody": { - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProductCreateRequest" - } - } - }, - "required": true - }, - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProductCreateResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - }, - "/product/get": { - "get": { - "tags": [ - "product" - ], - "summary": "Get Product", - "operationId": "get_products_by_client_id", - "parameters": [ - { - "name": "client_id", - "in": "query", - "required": true, - "schema": { - "type": "integer", - "title": "Client Id" - } - }, - { - "name": "page", - "in": "query", - "required": true, - "schema": { - "type": "integer", - "title": "Page" - } - }, - { - "name": "items_per_page", - "in": "query", - "required": true, - "schema": { - "type": "integer", - "title": "Items Per Page" - } - } - ], - "responses": { - "200": { - "description": "Successful Response", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/ProductGetResponse" - } - } - } - }, - "422": { - "description": "Validation Error", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/HTTPValidationError" - } - } - } - } - } - } - } - }, - "components": { - "schemas": { - "AuthLoginRequest": { - "properties": { - "auth_date": { - "type": "integer", - "title": "Auth Date" - }, - "first_name": { - "type": "string", - "title": "First Name" - }, - "hash": { - "type": "string", - "title": "Hash" - }, - "id": { - "type": "integer", - "title": "Id" - }, - "photo_url": { - "type": "string", - "title": "Photo Url" - } - }, - "type": "object", - "required": [ - "auth_date", - "first_name", - "hash", - "id", - "photo_url" - ], - "title": "AuthLoginRequest" - }, - "AuthLoginResponse": { - "properties": { - "access_token": { - "type": "string", - "title": "Access Token" - } - }, - "type": "object", - "required": [ - "access_token" - ], - "title": "AuthLoginResponse" - }, - "ClientDetailsSchema": { - "properties": { - "address": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "Address" - }, - "phone_number": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "Phone Number" - }, - "inn": { - "anyOf": [ - { - "type": "integer" - }, - { - "type": "null" - } - ], - "title": "Inn" - }, - "email": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "null" - } - ], - "title": "Email" - } - }, - "type": "object", - "title": "ClientDetailsSchema" - }, - "ClientGetAllResponse": { - "properties": { - "clients": { - "items": { - "$ref": "#/components/schemas/ClientSchema" - }, - "type": "array", - "title": "Clients" - } - }, - "type": "object", - "required": [ - "clients" - ], - "title": "ClientGetAllResponse" - }, - "ClientSchema": { - "properties": { - "id": { - "type": "integer", - "title": "Id" - }, - "name": { - "type": "string", - "title": "Name" - }, - "details": { - "anyOf": [ - { - "$ref": "#/components/schemas/ClientDetailsSchema" - }, - { - "type": "null" - } - ] - } - }, - "type": "object", - "required": [ - "id", - "name" - ], - "title": "ClientSchema" - }, - "ClientUpdateDetailsRequest": { - "properties": { - "client_id": { - "type": "integer", - "title": "Client Id" - }, - "details": { - "$ref": "#/components/schemas/ClientDetailsSchema" - } - }, - "type": "object", - "required": [ - "client_id", - "details" - ], - "title": "ClientUpdateDetailsRequest" - }, - "DealAddServicesRequest": { - "properties": { - "deal_id": { - "type": "integer", - "title": "Deal Id" - }, - "services": { - "items": { - "$ref": "#/components/schemas/DealServiceSchema" - }, - "type": "array", - "title": "Services" - } - }, - "type": "object", - "required": [ - "deal_id", - "services" - ], - "title": "DealAddServicesRequest" - }, - "DealAddServicesResponse": { - "properties": { - "ok": { - "type": "boolean", - "title": "Ok" - }, - "message": { - "type": "string", - "title": "Message" - } - }, - "type": "object", - "required": [ - "ok", - "message" - ], - "title": "DealAddServicesResponse" - }, - "DealChangeStatusRequest": { - "properties": { - "deal_id": { - "type": "integer", - "title": "Deal Id" - }, - "new_status": { - "type": "integer", - "title": "New Status" - } - }, - "type": "object", - "required": [ - "deal_id", - "new_status" - ], - "title": "DealChangeStatusRequest" - }, - "DealChangeStatusResponse": { - "properties": { - "ok": { - "type": "boolean", - "title": "Ok" - } - }, - "type": "object", - "required": [ - "ok" - ], - "title": "DealChangeStatusResponse" - }, - "DealCreateRequest": { - "properties": { - "name": { - "type": "string", - "title": "Name" - } - }, - "type": "object", - "required": [ - "name" - ], - "title": "DealCreateRequest" - }, - "DealQuickCreateRequest": { - "properties": { - "name": { - "type": "string", - "title": "Name" - }, - "client_name": { - "type": "string", - "title": "Client Name" - }, - "client_address": { - "type": "string", - "title": "Client Address" - }, - "comment": { - "type": "string", - "title": "Comment" - }, - "acceptance_date": { - "type": "string", - "format": "date-time", - "title": "Acceptance Date" - } - }, - "type": "object", - "required": [ - "name", - "client_name", - "client_address", - "comment", - "acceptance_date" - ], - "title": "DealQuickCreateRequest" - }, - "DealQuickCreateResponse": { - "properties": { - "deal_id": { - "type": "integer", - "title": "Deal Id" - } - }, - "type": "object", - "required": [ - "deal_id" - ], - "title": "DealQuickCreateResponse" - }, - "DealServiceSchema": { - "properties": { - "id": { - "type": "integer", - "title": "Id" - }, - "quantity": { - "type": "integer", - "title": "Quantity" - } - }, - "type": "object", - "required": [ - "id", - "quantity" - ], - "title": "DealServiceSchema" - }, - "DealSummary": { - "properties": { - "id": { - "type": "integer", - "title": "Id" - }, - "name": { - "type": "string", - "title": "Name" - }, - "client_name": { - "type": "string", - "title": "Client Name" - }, - "changed_at": { - "type": "string", - "format": "date-time", - "title": "Changed At" - }, - "status": { - "type": "integer", - "title": "Status" - }, - "total_price": { - "type": "integer", - "title": "Total Price" - } - }, - "type": "object", - "required": [ - "id", - "name", - "client_name", - "changed_at", - "status", - "total_price" - ], - "title": "DealSummary" - }, - "DealSummaryResponse": { - "properties": { - "summaries": { - "items": { - "$ref": "#/components/schemas/DealSummary" - }, - "type": "array", - "title": "Summaries" - } - }, - "type": "object", - "required": [ - "summaries" - ], - "title": "DealSummaryResponse" - }, - "HTTPValidationError": { - "properties": { - "detail": { - "items": { - "$ref": "#/components/schemas/ValidationError" - }, - "type": "array", - "title": "Detail" - } - }, - "type": "object", - "title": "HTTPValidationError" - }, - "PaginationInfoSchema": { - "properties": { - "total_pages": { - "type": "integer", - "title": "Total Pages" - }, - "total_items": { - "type": "integer", - "title": "Total Items" - } - }, - "type": "object", - "required": [ - "total_pages", - "total_items" - ], - "title": "PaginationInfoSchema" - }, - "ProductCreateRequest": { - "properties": { - "name": { - "type": "string", - "title": "Name" - }, - "article": { - "type": "string", - "title": "Article" - }, - "client_id": { - "type": "integer", - "title": "Client Id" - }, - "barcodes": { - "items": { - "type": "string" - }, - "type": "array", - "title": "Barcodes" - } - }, - "type": "object", - "required": [ - "name", - "article", - "client_id", - "barcodes" - ], - "title": "ProductCreateRequest" - }, - "ProductCreateResponse": { - "properties": { - "product_id": { - "type": "integer", - "title": "Product Id" - } - }, - "type": "object", - "required": [ - "product_id" - ], - "title": "ProductCreateResponse" - }, - "ProductGetResponse": { - "properties": { - "products": { - "items": { - "$ref": "#/components/schemas/ProductSchema" - }, - "type": "array", - "title": "Products" - }, - "pagination_info": { - "$ref": "#/components/schemas/PaginationInfoSchema" - } - }, - "type": "object", - "required": [ - "products", - "pagination_info" - ], - "title": "ProductGetResponse" - }, - "ProductSchema": { - "properties": { - "id": { - "type": "integer", - "title": "Id" - }, - "name": { - "type": "string", - "title": "Name" - }, - "article": { - "type": "string", - "title": "Article" - }, - "client_id": { - "type": "integer", - "title": "Client Id" - } - }, - "type": "object", - "required": [ - "id", - "name", - "article", - "client_id" - ], - "title": "ProductSchema" - }, - "ServiceCategorySchema": { - "properties": { - "id": { - "type": "integer", - "title": "Id" - }, - "name": { - "type": "string", - "title": "Name" - } - }, - "type": "object", - "required": [ - "id", - "name" - ], - "title": "ServiceCategorySchema" - }, - "ServiceCreateCategoryRequest": { - "properties": { - "category": { - "$ref": "#/components/schemas/ServiceCategorySchema" - } - }, - "type": "object", - "required": [ - "category" - ], - "title": "ServiceCreateCategoryRequest" - }, - "ServiceCreateCategoryResponse": { - "properties": { - "ok": { - "type": "boolean", - "title": "Ok" - }, - "message": { - "type": "string", - "title": "Message" - } - }, - "type": "object", - "required": [ - "ok", - "message" - ], - "title": "ServiceCreateCategoryResponse" - }, - "ServiceCreateRequest": { - "properties": { - "service": { - "$ref": "#/components/schemas/ServiceSchema" - } - }, - "type": "object", - "required": [ - "service" - ], - "title": "ServiceCreateRequest" - }, - "ServiceCreateResponse": { - "properties": { - "ok": { - "type": "boolean", - "title": "Ok" - }, - "message": { - "type": "string", - "title": "Message" - } - }, - "type": "object", - "required": [ - "ok", - "message" - ], - "title": "ServiceCreateResponse" - }, - "ServiceGetAllCategoriesResponse": { - "properties": { - "categories": { - "items": { - "$ref": "#/components/schemas/ServiceCategorySchema" - }, - "type": "array", - "title": "Categories" - } - }, - "type": "object", - "required": [ - "categories" - ], - "title": "ServiceGetAllCategoriesResponse" - }, - "ServiceGetAllResponse": { - "properties": { - "services": { - "items": { - "$ref": "#/components/schemas/ServiceSchema" - }, - "type": "array", - "title": "Services" - } - }, - "type": "object", - "required": [ - "services" - ], - "title": "ServiceGetAllResponse" - }, - "ServiceSchema": { - "properties": { - "id": { - "type": "integer", - "title": "Id" - }, - "name": { - "type": "string", - "title": "Name" - }, - "category": { - "$ref": "#/components/schemas/ServiceCategorySchema" - }, - "price": { - "type": "number", - "title": "Price" - } - }, - "type": "object", - "required": [ - "id", - "name", - "category", - "price" - ], - "title": "ServiceSchema" - }, - "ValidationError": { - "properties": { - "loc": { - "items": { - "anyOf": [ - { - "type": "string" - }, - { - "type": "integer" - } - ] - }, - "type": "array", - "title": "Location" - }, - "msg": { - "type": "string", - "title": "Message" - }, - "type": { - "type": "string", - "title": "Error Type" - } - }, - "type": "object", - "required": [ - "loc", - "msg", - "type" - ], - "title": "ValidationError" - } - }, - "securitySchemes": { - "HTTPBearer": { - "type": "http", - "scheme": "bearer" - } - } - } -} \ No newline at end of file diff --git a/test/test.py b/test/test.py deleted file mode 100644 index e6af690..0000000 --- a/test/test.py +++ /dev/null @@ -1,28 +0,0 @@ -import asyncio - -from sqlalchemy import select, func, union -from sqlalchemy.ext.asyncio import AsyncSession -from sqlalchemy.orm import joinedload - -from backend.session import session_maker -from external.s3_uploader.uploader import S3Uploader -from models import Deal, DealProduct, Service - -import models -import models.secondary - - -async def main(session: AsyncSession): - file_bytes = open('photo_2024-04-01 10.26.39.jpeg', 'rb').read() - uploader = S3Uploader('1cc46590-4532-4046-97aa-baf3e49f20ad-AUF') - response = await uploader.upload(file_bytes) - print(response) - - -async def preload(): - async with session_maker() as session: - await main(session) - - -if __name__ == '__main__': - asyncio.run(preload())