
    NBe`                     ~    d dl Zd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ  G d	 d
e          ZdS )    N)shop_logger)BaseRepository)settings)
UploadFile)article)file_system)selectc                   f    e Zd ZdedefdZdeeef         fdZe	d             Z
e	d             ZdS )	PictureRepositoryref_idpicturec                   K   t           j                            t          j        |j                  }t          j        |j        |           t          j
        ||          }| j                            |           | j                            |           d{V  | j                                         d{V  t          j        dt#          |                      dS )z{
        Saves picture
        :param ref_id: the id of referenced item
        :param picture: the picture upload
        )r   path)instanceNzpicture uploaded: )osr   joinr   pictures_pathfilenameutils	save_filefiledbPictureasync_sessionaddrefreshcommitr   infostr)selfr   r   r   news        S/Users/daniilossinkin/PycharmProjects/ShopsBackend/src/data/repositories/picture.pyupload_picturez PictureRepository.upload_picture   s       w||H2G4DEEd+++j
 
 

 	,,, ((#(666666666 '')))))))))8c#hh8899999    returnc                     K    j                             t          t          j                             d{V }|                                                                } fd|D             }|S )z
        Determinate all picture entities with no corresponding image file
        :return: dict of form { "ref_id" : "file_name" }
        Nc                 ^    i | ])}                     |j                  |j        |j        *S  )$_PictureRepository__get_picture_pathr   r   r   ).0r   r    s     r"   
<dictcomp>z:PictureRepository.get_missing_pictures.<locals>.<dictcomp>*   s6    uuuGtOfOfgngsOtOtu7>7<uuur$   )r   executer	   r   r   scalarsall)r    querypicturesmissings   `   r"   get_missing_picturesz&PictureRepository.get_missing_pictures#   sr      
 (00
1C1CDDDDDDDD==??&&((uuuuxuuur$   c                 V    t           j                            t          j        |           S N)r   r   r   r   r   )r   s    r"   __get_picture_pathz$PictureRepository.__get_picture_path-   s    w||H2D999r$   c                 h    t           j                            |                                            d S r4   )r   r   existsr)   )r    r   s     r"   __picture_existsz"PictureRepository.__picture_exists1   s(    
t..0011111r$   N)__name__
__module____qualname__intr   r#   dictr   r2   staticmethodr)   "_PictureRepository__picture_existsr(   r$   r"   r   r      s        :3 : : : : :*DcN     : : \: 2 2 \2 2 2r$   r   )os.pathr   src.config.loggerr   src.data.repositories.baser   
src.configr   fastapir   src.data.model.dbr   r   	src.utilsr   r   
sqlalchemyr	   r   r(   r$   r"   <module>rH      s     ) ) ) ) ) ) 5 5 5 5 5 5             + + + + + + * * * * * *      '2 '2 '2 '2 '2 '2 '2 '2 '2 '2r$   