
    Jh                        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mZmZ d dlmZ d dlmZ d dlmZ  ed	d
g      Zej/                  d	e
d       eddd       eej0                  dej2                  d       ee      fdededefd       Zej/                  de
d       ee      fdedefd       Zej;                  d	e
ej<                  d       ee      fdedefd       ZejA                  de
d       ee      fdededefd        Z!ejE                  de
ejF                  d!       ee      fdedefd"       Z$y#)$    )	APIRouterDependsstatusQuery)Session)UUID)ResponseModel)CountryOutSchemaCountryCreateSchemaCountryUpdateSchema)country)get_db)	constants 	Countries)prefixtagsz!Get all countries with pagination)response_modelsummary   zPage number to fetch)defaultgedescriptionzNumber of items per page)r   r   ler   pageper_pagedbc                    K   t        j                  || |       d {   }t        |t        j                  dd      S 7 !w)N)r   r   r   TzCountries fetched successfullydatastatus_codesuccessmessage)country_serviceget_all_countriesr	   r   HTTP_200_OK)r   r   r   paginated_datas       W/var/www/html/wine-match-dev/backend/winematch-backend/src/apps/base/routers/country.pylist_countriesr)      sL      +<< N
 &&0	 s   AA "Az/{country_id}zGet country by id
country_idc                    K   t        j                  ||        d {   }t        t        j                  |      t
        j                  dd      S 7 4w)NTzCountry fetched successfullyr   )r$   get_country_by_idr	   r
   from_ormr   r&   )r*   r   r   s      r(   get_countryr.   *   sM     
 $55b*EEG&&w/&&.	  F   AA5AzCreate country)r   r!   r   payloadc                    K   t        j                  ||        d {   }t        t        j                  |      t
        j                  dd      S 7 4w)NTzCountry created successfullyr   )r$   create_countryr	   r
   r-   r   HTTP_201_CREATED)r0   r   created_countrys      r(   r2   r2   8   sM     
 ,::2wGGO&&7++.	  Hr/   zUpdate countryc                    K   t        j                  || |       d {   }t        t        j                  |      ddd      S 7 &w)N)r   r*   r0      TzCountry updated successfullyr   )r$   update_countryr	   r
   r-   )r*   r0   r   updated_countrys       r(   r7   r7   F   sJ      ,::bZahiiO&&7.	  js   AA'AzDelete countryc                 h   K   t        j                  ||        d {    t        i ddd      S 7 w)Nr6   TzCountry deleted successfullyr   )r$   delete_countryr	   )r*   r   s     r(   r:   r:   U   s<     
 
(
(Z
888.	  9s   202N)%fastapir   r   r   r   sqlalchemy.ormr   uuidr   $src.apps.base.schemas.response_modelr	   src.apps.base.schemas.countryr
   r   r   src.apps.base.servicesr   r$   src.core.dependenciesr   	src.utilsr   routergetDEFAULT_PER_PAGEMAX_PER_PAGEintr)   r.   postr3   r2   putr7   deleter&   r:        r(   <module>rM      s   5 5 "  > 
 > ( 	"K=	1 B}6YZaA3IJ**!!.	 &/
 	 [. OMCVW &/


 X
 R6;R;R\lm &/
 

 n
 OMCST &/  	 U }&J\J\fvw &/


 x
rL   