
    lh                         d dl m Z  d dlmZ d dlmZ d dlmZ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mZmZmZmZ d d	lmZmZmZmZ d d
lmZ d dl dededefdZdede de!defdZ"dede de#fdZ$y)    )datetime)UUID)Session)HTTPExceptionstatus)APIException)QueryPaginator)ProducerProducerKeywordProducerNoise)funccastIntegerand_or_)ProducerFilterSchemaProducerCreateSchemaProducerUpdateSchemaProducerOutputSchema)API_PREFIXES)*dbproducer_keywordreturnc                 >  K   	 t        di |j                         }| j                  |       | j                          | j	                  |       t
        j                  |      S # t        $ r-}t        ddt        |      it        j                  d      d }~ww xY ww)Ncreate_producer_keyword	exceptionz Error creating producer keyword.moduleerrorstatus_codemessage )r   
model_dumpaddcommitrefreshProducerKeywordOutputSchemamodel_validate	Exceptionr   strr   HTTP_500_INTERNAL_SERVER_ERROR)r   r   new_keywordes       j/var/www/html/wine-match-dev/backend/winematch-backend/src/apps/wine/producer/services/producer_keyword.pyr   r      s     
%F(8(C(C(EF
{
		


;*99+FF 
,A'==6	
 	

s)   BAA$ #B$	B-(BBBproducer_idkeyword_datac                 B  K   	 | j                  t              j                  t        j                  |k(  t        j                  d k(        j                         }|st        dddit        j                  d      |j                         j                         D ]  \  }}|	t        |||        | j                          | j                  |       t        j                  |      S # t         $ r-}t        ddt#        |      it        j$                  d      d }~ww xY ww)Nupdate_producer_keywordr   Producer keyword not foundProducer keyword not found.r   z Error updating producer keyword.)queryr   filterr0   
deleted_atfirstr   r   HTTP_404_NOT_FOUNDr$   itemssetattrr&   r'   r(   r)   r*   r+   r,   )r   r0   r1   keywordkeyvaluer.   s          r/   r3   r3       s    

((?+22?3N3NR]3]^m^x^x  }A  _A  B  H  H  J0"$@A"555	  '11399; 	-JC e,	- 			


7*99'BB 
,A'==6	
 	

s0   DBC& !AC& %D&	D/(DDDc                   K   	 | j                  t              j                  t        j                  |k(  t        j                  d k(        j                         }|st        dddit        j                  d      t        j                  |      S # t        $ r-}t        ddt        |      it        j                  d      d }~ww xY ww)Nget_producer_keyword_by_idr   r4   r5   r   z!Failed to fetch producer keyword.)r6   r   r7   r0   r8   r9   r   r   r:   r(   r)   r*   r+   r,   )r   r0   r=   r.   s       r/   rA   rA   <   s     
((?+22?3N3NR]3]_n_y_y  ~B  `B  C  I  I  K3"$@A"555	  +99'BB 
/A'==7	
 	

s)   CB
B C	C(C  CCN)%r   uuidr   sqlalchemy.ormr   fastapir   r   src.core.exceptionsr   src.utils.paginationr	   &src.apps.wine.producer.models.producerr
   r   r   
sqlalchemyr   r   r   r   r   'src.apps.wine.producer.schemas.producerr   r   r   r   src.utils.constantsr   /src.apps.wine.producer.schemas.producer_keywordProducerKeywordAdditionSchemar   intProducerKeywordUpdateSchemar3   r(   rA   r#       r/   <module>rP      s      " ) , / Y Y 3 3 H  H , =

3
 
$


 .
 	
8


 !
rO   