
    DgEi.              
          d dl mZmZmZ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mZmZ d dlmZ d dlmZ d d	lmZ  e       Zej/                  d
eej0                         ee       ee      fdedede
fd       Zej5                  d
ee         d d ee       ee      fdededede
fd       Zej5                  de       ee       ee      fdedede
fd       Zej=                  de       ee       ee      fdededede
fd       ZejA                  dejB                         ee       ee      fdedede
fd       Z"y)    )	APIRouterDependsHTTPExceptionstatus)Session)get_db)User)Publication)PublicationCreatePublicationUpdatePublicationResponse)get_current_admin)List)datetime/)response_modelstatus_codepublication_indbcurrent_adminc                    t        di | j                         d|j                  i}|j                  r%|j                  st        j                         |_        |j                  |       |j                          |j                  |       |S )u*   
    Créer une nouvelle publication.
    	author_id )
r
   
model_dumpidis_publishedpublished_atr   utcnowaddcommitrefresh)r   r   r   publications       O/home/www/lebenam.kofcorporation.com/app/api/v1/endpoints/admin/publications.pycreate_publicationr$      sv      

#
#
%""K (@(@#+??#4 FF;IIKJJ{    )r   d   skiplimitc                     |j                  t              j                  t        j                  j	                               j                  |       j                  |      j                         }|S )uD   
    Obtenir toutes les publications (publiées et brouillons).
    )queryr
   order_by
created_atdescoffsetr(   all)r'   r(   r   r   publicationss        r#   get_all_publicationsr1   #   sS     88K(11+2H2H2M2M2OPWWX\]ccdijnnpLr%   z/{publication_id}publication_idc                     |j                  t              j                  t        j                  | k(        j	                         }|st        t        j                  d      |S )z-
    Obtenir une publication par son ID.
       Publication non trouvéer   detail)r*   r
   filterr   firstr   r   HTTP_404_NOT_FOUNDr2   r   r   r"   s       r#   get_publicationr;   0   sL     ((;'..{~~/OPVVXK(A(AJdeer%   c                 &   |j                  t              j                  t        j                  | k(        j	                         }|st        t        j                  d      |j                  d      }|j                  d      r&|j                  st        j                         |_        nd|v r|d   sd|_        |j                         D ]  \  }}t        |||        |j!                  |       |j#                          |j%                  |       |S )u)   
    Mettre à jour une publication.
    r4   r5   T)exclude_unsetr   N)r*   r
   r7   r   r8   r   r   r9   r   getr   r   r   r   itemssetattrr   r    r!   )r2   r   r   r   r"   update_datafieldvalues           r#   update_publicationrD   >   s     ((;'..{~~/OPVVXK(A(AJdee ++$+?K ~&{/G/G#+??#4 	;	&{>/J#' #))+ +uUE*+ FF;IIKJJ{r%   )r   c                    |j                  t              j                  t        j                  | k(        j	                         }|st        t        j                  d      |j                  |       |j                          y)z$
    Supprimer une publication.
    r4   r5   N)
r*   r
   r7   r   r8   r   r   r9   deleter    r:   s       r#   delete_publicationrG   \   s^     ((;'..{~~/OPVVXK(A(AJdeeIIkIIK
r%   N)#fastapir   r   r   r   sqlalchemy.ormr   app.db.sessionr   app.models.userr	   app.models.publicationr
   app.schemas.publicationr   r   r   app.core.securityr   typingr   r   routerpostHTTP_201_CREATEDr$   r>   intr1   r;   putrD   rF   HTTP_204_NO_CONTENTrG   r   r%   r#   <module>rV      s   = = " !   . ] ] /  	S!4&BYBYZ &/!"34%  [( C%8 9:&/!"34	



 	
 	
 ;
 0CD &/!"34  E 0CD &/!"34	% 	 	 E: "0J0JK &/!"34  Lr%   