feat: new barcodes
This commit is contained in:
		@@ -1,11 +1,15 @@
 | 
			
		||||
import base64
 | 
			
		||||
from io import BytesIO
 | 
			
		||||
from typing import Annotated, Union
 | 
			
		||||
 | 
			
		||||
from fastapi import APIRouter, Depends, UploadFile
 | 
			
		||||
from sqlalchemy.ext.asyncio import AsyncSession
 | 
			
		||||
 | 
			
		||||
from starlette.responses import StreamingResponse
 | 
			
		||||
from fastapi.responses import FileResponse
 | 
			
		||||
import utils.dependecies
 | 
			
		||||
from backend.session import get_session
 | 
			
		||||
from schemas.barcode import GetProductBarcodeResponse, GetProductBarcodeRequest
 | 
			
		||||
from schemas.barcode import GetProductBarcodeResponse, GetProductBarcodeRequest, GetProductBarcodePdfResponse, \
 | 
			
		||||
    GetProductBarcodePdfRequest
 | 
			
		||||
from schemas.base import PaginationSchema
 | 
			
		||||
from schemas.product import *
 | 
			
		||||
from services.auth import get_current_user
 | 
			
		||||
@@ -127,6 +131,28 @@ async def get_product_barcode(
 | 
			
		||||
    return await BarcodeService(session).get_barcode(request)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@product_router.post(
 | 
			
		||||
    '/barcode/get-pdf',
 | 
			
		||||
    operation_id='get_product_barcode_pdf',
 | 
			
		||||
    response_model=GetProductBarcodePdfResponse
 | 
			
		||||
)
 | 
			
		||||
async def get_product_barcode_pdf(
 | 
			
		||||
        request: GetProductBarcodePdfRequest,
 | 
			
		||||
        session: Annotated[AsyncSession, Depends(get_session)]
 | 
			
		||||
):
 | 
			
		||||
    filename, pdf_buffer = await BarcodeService(session).get_barcode_pdf(request)
 | 
			
		||||
    pdf_buffer: BytesIO
 | 
			
		||||
    base64_string = base64.b64encode(pdf_buffer.read()).decode('utf-8')
 | 
			
		||||
    return GetProductBarcodePdfResponse(
 | 
			
		||||
        base64_string=base64_string,
 | 
			
		||||
        filename=filename,
 | 
			
		||||
        mime_type='application/pdf'
 | 
			
		||||
    )
 | 
			
		||||
    # return StreamingResponse(content=pdf_buffer,
 | 
			
		||||
    #                          media_type='application/pdf',
 | 
			
		||||
    #                          headers={"Content-Disposition": f"inline; filename={filename}"})
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@product_router.post(
 | 
			
		||||
    '/images/upload/{product_id}',
 | 
			
		||||
    response_model=ProductUploadImageResponse,
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user