
    ڬfYp                        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 ddlmZmZmZmZ dd	lmZmZmZmZmZmZ d d
l	mZmZmZ d dlmZ d dlmZmZ d dl m!Z! d dl"m#Z# e#d   Z$ G d de      Z% G d de      Z& G d de      Z' G d de      Z( G d de      Z) G d de      Z* G d dejV                        Z, G d de      Z-y )!    )APIView)Responsestatus)validate_required_paramsvalidate)validate_and_convert_deadline)generics   )ListingListingCategoryListingCategoryServiceListingTerms)ListingTermsSerializerListingSerializerListingCategorySerializer ListingCategoryServiceSerializerListingRecentSerializerListingSingleAPISerializer)success_responsefailed_responsegenerate_random_text)LimitOffsetPagination)NotFoundErrorValidationError)record)logger_settingsmsgc                   ,    e Zd ZddZddZddZddZy)ListingCategoryCRUDViewNc           	         t        d      }t        d| dt        d    d       	 |r[t        j                  j                  |      }t        |      }t        d| dt        d    d       t        |j                  d	
      S t        j                  j                         }t        |d      }t        d| dt        d    d       t        |j                  d
      S # t        j                  $ r- t        d| d       t        dt        j                        cY S t        $ r@}t        d| dt        |       d       t        dt        j                         cY d }~S d }~ww xY w)N   info: startedz. - ListingCategoryCRUDView GET request startedpk	completedz* - Listing Category retrieved successfullyz'Listing Category retrieved successfullydatar   Tmanyz, - Listing categories retrieved successfullyz)Listing categories retrieved successfullywarnz: Listing category not foundListing category not foundr   codeerrorz> - Unexpected error occurred during Listing Category retrievalAn unexpected error occurred)r   r   log_msgr   objectsgetr   r   r*   allDoesNotExistr   r   HTTP_404_NOT_FOUND	ExceptionstrHTTP_500_INTERNAL_SERVER_ERROR)	selfrequestr'   formatprocess_codelisting_category
serializerlisting_categorieses	            7D:\SB Projects\Vendor-App\main-backend\listing\views.pyr5   zListingCategoryCRUDView.get   sR   +A.v,r')*<)==klm	s#2#:#:#>#>"#>#E 67GH
v,r'+2F1GGqrs'Z__Bkll%4%<%<%@%@%B"67IPTU
v,r'+2F1GGstu'Z__Bmnn++ 	e6l^+GHI"'C&JcJcdd 	s7|nBs1vh6tuv"'EFLqLqrr	s+   AC AC =E%E%%5E E% E%c           	         t        d      }t        d| dt        d    d       	 t        |g d       t	        d|j
                  j                  dd      d	g       t        d
|j
                  j                  d
d             t	        d|j
                  j                  dd      dg       t        |j
                        }|j                         r@|j                          t        d| dt        d    d       t        |j
                  d      S t        d| d|j                   d       t        |j                  t        j                        S # t         $ rI}t        d| dt#        |       d       t        t#        |      t        j                        cY d }~S d }~wt$        $ r@}t        d| dt#        |       d       t        dt        j&                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z/ - ListingCategoryCRUDView POST request startedtitledeadlinenoterH    length:max:100rI   rJ   length:max:250r*   r(   z( - Listing Category created successfullyz%Listing Category Created Successfullyr)   r-   z5 - Validation errors during Listing Category creationr/   z4 - Validation error during Listing Category creationr1   z= - Unexpected error occurred during Listing Category creationr2   )r   r   r3   r   r   r*   r5   r	   r   is_validsaver   errorsr   r   HTTP_400_BAD_REQUESTr   r:   r9   r;   r<   r=   r>   r?   rA   verC   s          rD   postzListingCategoryCRUDView.post)   s   +A.v,r')*<)==lmn	s$W.KLWgll..w;>N=OP)*gll6F6FzSU6VWVW\\--fb9<L;MN2EJ""$!v,r'+2F1GGopq'Z__Bijj6l^2j.?.?-@@uvw"z'8'8v?Z?Z[[ 	R6l^2c"gY6jkl"s2wV5P5PQQ 	s7|nBs1vh6stu"'EFLqLqrr	ss7   C)E A E 	G*>FG*G**5G%G*%G*c           	         t        d      }t        d| dt        d    d       	 t        |g d       t	        d|j
                  j                  dd      d	g       t        d
|j
                  j                  d
d             t	        d|j
                  j                  dd      dg       |s*t        d| d       t        dt        j                        S t        j                  j                  |      }t        ||j
                        }|j                         r@|j                          t        d| dt        d    d       t!        |j
                  d      S t        d| d|j"                   d       t        |j"                  t        j                        S # t        j$                  $ r- t        d| d       t        dt        j&                        cY S t(        $ rI}t        d| dt+        |       d       t        t+        |      t        j                        cY d }~S d }~wt,        $ r@}t        d| dt+        |       d       t        dt        j.                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z. - ListingCategoryCRUDView PUT request startedrG   rH   rK   rL   rI   rJ   rM   r-   z,: Listing category ID is required for updatezListing category ID is requiredr/   r&   rN   r(   z( - Listing Category updated successfullyz%Listing Category Updated Successfullyr)   z3 - Validation errors during Listing Category updatez': Listing category not found for updater.   z2 - Validation error during Listing Category updater1   z; - Unexpected error occurred during Listing Category updater2   )r   r   r3   r   r   r*   r5   r	   r   r   rR   r   r4   r   rO   rP   r   rQ   r7   r8   r   r:   r9   r;   )	r<   r=   r'   r>   r?   r@   rA   rT   rC   s	            rD   putzListingCategoryCRUDView.put?   s    +A.v,r')*<)==klm	s$W.KLWgll..w;>N=OP)*gll6F6FzSU6VWVW\\--fb9<L;MNv,/[\]&+LSYSnSnoo.66::b:A23C',,WJ""$!v,r'+2F1GGopq'Z__Bijj6l^2j.?.?-@@stu"z'8'8v?Z?Z[[++ 	e6l^+RST"'C&JcJcdd 	R6l^2c"gY6hij"s2wV5P5PQQ 	s7|nBs1vh6qrs"'EFLqLqrr	ssD   B/F BF A F =I5I5%>H)#I5)I555I0*I50I5c           	      
   t        d      }t        d| dt        d    d       	 t        j                  j                  |      }|j                          t        d| dt        d    d       t        d	
      S # t        j                  $ r- t        d| d       t        dt        j                        cY S t        $ r@}t        d| dt        |       d       t        dt        j                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z1 - ListingCategoryCRUDView DELETE request startedr&   r(   z( - Listing Category deleted successfullyz%Listing Category deleted successfullyr   r-   z): Listing category not found for deletionzListing Category not foundr/   r1   z= - Unexpected error occurred during Listing Category deletionr2   )r   r   r3   r   r4   r5   deleter   r7   r   r   r8   r9   r:   r;   )r<   r=   r'   r>   r?   r@   rC   s          rD   rZ   zListingCategoryCRUDView.delete\   s    +A.v,r')*<)==nop
	s.66::b:A##%6l^2gk.B-CCklm#(OPP++ 	e6l^+TUV"'C&JcJcdd 	s7|nBs1vh6stu"'EFLqLqrr	s$   AA; ;=D:D5C=7D=DNNN__name__
__module____qualname__r5   rU   rW   rZ        rD   r    r       s    s*s,s:src   r    c                   ,    e Zd ZddZddZddZddZy)ListingCategoryServiceCRUDViewNc           	         t        d      }t        d| dt        d    d       	 |r[t        j                  j                  |      }t        |      }t        d| dt        d    d       t        |j                  d	
      S t        j                  j                         }t        |d      }t        d| dt        d    d       t        |j                  d
      S # t        j                  $ r- t        d| d       t        dt        j                        cY S t        $ r@}t        d| dt        |       d       t        dt        j                         cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z5 - ListingCategoryServiceCRUDView GET request startedr&   r(   z2 - Listing category service retrieved successfullyz/Listing category service retrieved successfullyr)   Tr+   z3 - Listing category services retrieved successfullyz0Listing category services retrieved successfullyr-   z$: Listing category service not found"Listing category service not foundr/   r1   zF - Unexpected error occurred during Listing Category Service retrievalr2   )r   r   r3   r   r4   r5   r   r   r*   r6   r7   r   r   r8   r9   r:   r;   )	r<   r=   r'   r>   r?   listing_category_servicerA   listing_category_servicesrC   s	            rD   r5   z"ListingCategoryServiceCRUDView.getm   sT   +A.v,r')*<)==rst	s+A+I+I+M+MQS+M+T(=>VW
v,r'+2F1GGyz{'Z__Bstt,B,J,J,N,N,P)=>W^bc
v,r'+2F1GGz{|'Z__Btuu%22 	m6l^+OPQ"'KRXRkRkll 	s7|nBs1vh6|}~"'EFLqLqrr	srE   c           	      2   t        d      }t        d| dt        d    d       	 t        |j                        }|j                         r@|j                          t        d| dt        d    d       t        |j                  d	
      S t        d| d|j                   d       t        |j                  t        j                        S # t        $ r@}t        d| dt        |       d       t        dt        j                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z6 - ListingCategoryServiceCRUDView POST request startedrN   r(   z0 - Listing category service created successfullyz-Listing category service created successfullyr)   r-   z= - Validation errors during Listing Category Service creationr/   r1   zE - Unexpected error occurred during Listing Category Service creationr2   )r   r   r3   r   r*   rO   rP   r   rQ   r   r   rR   r9   r:   r;   )r<   r=   r>   r?   rA   rC   s         rD   rU   z#ListingCategoryServiceCRUDView.post   s    +A.v,r')*<)==stu
	s9w||LJ""$!v,r'+2F1GGwxy'Z__Bqrr6l^2j.?.?-@@}~"z'8'8v?Z?Z[[ 	s7|nBs1vh6{|}"'EFLqLqrr	ss%   A%C A C 	D5DDDc           	      d   t        d      }t        d| dt        d    d       	 t        |ddg       |s*t        d| d	       t	        d
t
        j                        S t        j                  j                  |      }t        ||j                        }|j                         r@|j                          t        d| dt        d    d       t        |j                  d      S t        d| d|j                   d       t	        |j                  t
        j                        S # t        j                   $ r- t        d| d       t	        dt
        j"                        cY S t$        $ r@}t        d| dt'        |       d       t	        dt
        j(                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z5 - ListingCategoryServiceCRUDView PUT request startedlistingvendor_category_servicer-   z4: Listing Category Service ID is required for updatez'Listing Category Service ID is requiredr/   r&   rN   r(   z0 - Listing category service updated successfullyz-Listing category service updated successfullyr)   z; - Validation errors during Listing Category Service updatez/: Listing category service not found for updaterg   r1   zC - Unexpected error occurred during Listing Category Service updater2   )r   r   r3   r   r   r   rR   r   r4   r5   r   r*   rO   rP   r   rQ   r7   r8   r9   r:   r;   )r<   r=   r'   r>   r?   rh   rA   rC   s           rD   rW   z"ListingCategoryServiceCRUDView.put   s   +A.v,r')*<)==rst	s$Wy:S.TUv,/cde&+T[a[v[vww'='E'E'I'IR'I'P$9:RY`YeYefJ""$!v,r'+2F1GGwxy'Z__Bqrr6l^2j.?.?-@@{|}"z'8'8v?Z?Z[[%22 	m6l^+Z[\"'KRXRkRkll 	s7|nBs1vh6yz{"'EFLqLqrr	ss1   9D(  BD( 'A D( (=F/'F//5F*$F/*F/c           	      
   t        d      }t        d| dt        d    d       	 t        j                  j                  |      }|j                          t        d| dt        d    d       t        d	
      S # t        j                  $ r- t        d| d       t        dt        j                        cY S t        $ r@}t        d| dt        |       d       t        dt        j                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z8 - ListingCategoryServiceCRUDView DELETE request startedr&   r(   z0 - Listing category service deleted successfullyz-Listing Category Service deleted successfullyrY   r-   z1: Listing category service not found for deletionrg   r/   r1   zE - Unexpected error occurred during Listing Category Service deletionr2   )r   r   r3   r   r4   r5   rZ   r   r7   r   r   r8   r9   r:   r;   )r<   r=   r'   r>   r?   rh   rC   s          rD   rZ   z%ListingCategoryServiceCRUDView.delete   s    +A.v,r')*<)==uvw
	s'='E'E'I'IR'I'P$$++-6l^2gk.B-CCstu#(WXX%22 	m6l^+\]^"'KRXRkRkll 	s7|nBs1vh6{|}"'EFLqLqrr	sr[   r\   r]   r^   rb   rc   rD   re   re   l   s    s*ss.src   re   c                   ,    e Zd ZddZddZddZddZy)ListingTermsCRUDViewNc           	         t        d      }t        d| dt        d    d       	 |r[t        j                  j                  |      }t        |      }t        d| dt        d    d       t        |j                  d	
      S t        j                  j                         }t        |d      }t        d| dt        d    d       t        |j                  d
      S # t        j                  $ r- t        d| d       t        dt        j                        cY S t        $ r@}t        d| dt        |       d       t        dt        j                         cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z+ - ListingTermsCRUDView GET request startedr&   r(   z& - Listing term retrieved successfullyz#Listing term retrieved successfullyr)   Tr+   z' - Listing terms retrieved successfullyz$Listing terms retrieved successfullyr-   z: Listing term not foundzListing term not foundr/   r1   z: - Unexpected error occurred during Listing Term retrievalAn unexpected error occurred: )r   r   r3   r   r4   r5   r   r   r*   r6   r7   r   r   rR   r9   r:   r;   )	r<   r=   r'   r>   r?   listing_termrA   listing_termsrC   s	            rD   r5   zListingTermsCRUDView.get   sM   +A.v,r')*<)==hij	u+337727>3LA
v,r'+2F1GGmno'zFkll , 4 4 8 8 :3MM
v,r'+2F1GGnop'zFlmm(( 	e6l^+CDE")AHcHcdd 	u7|nBs1vh6pqr"'GfNsNstt	urE   c           	      :   t        d      }t        d| dt        d    d       	 t        |dg       t	        d|j
                  j                  dd      dg       t        |j
                  	      }|j                         r@|j                          t        d| dt        d
    d       t        |j
                  d      S t        d| d|j                   d       t        |j                  t        j                        S # t        $ rH}t        d| dt!        |              t        t!        |      t        j"                        cY d }~S d }~wt$        $ r@}t        d| dt!        |       d       t        dt        j&                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z, - ListingTermsCRUDView POST request startedrJ   rK   rM   rN   r(   z$ - Listing term created successfullyz!Listing Term created successfullyr)   r-   z1 - Validation errors during Listing Term creationr/   : Validation error - r1   z9 - Unexpected error occurred during Listing Term creationrr   )r   r   r3   r   r   r*   r5   r   rO   rP   r   rQ   r   r   rR   r   r:   HTTP_404_BAD_REQUESTr9   r;   rS   s          rD   rU   zListingTermsCRUDView.post   sf   +A.v,r')*<)==ijk	u$Wvh7VGLL,,VR8;K:LM/W\\BJ""$!v,r'+2F1GGklm'Z__Beff6l^2j.?.?-@@qrs"):):A\A\]] 	T6l^+@R	JK"Rv7R7RSS 	u7|nBs1vh6opq"'GfNsNstt	us7   BD A D 	F=EFF5FFFc           	      R   t        d      }t        d| dt        d    d       	 t        |ddg       t	        d|j
                  j                  dd      d	g       |s*t        d
| d       t        dt        j                        S t        j                  j                  |      }t        ||j
                        }|j                         r@|j                          t        d| dt        d    d       t        |j
                  d      S t        d
| d|j                    d       t        |j                   t        j                        S # t        j"                  $ r- t        d
| d       t        dt        j$                        cY S t&        $ rH}t        d
| dt)        |              t        t)        |      t        j*                        cY d }~S d }~wt,        $ r@}t        d| dt)        |       d       t        dt        j.                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z+ - ListingTermsCRUDView PUT request startedr'   rJ   rK   rM   r-   z(: Listing Term ID is required for updatezListing Term ID is requiredr/   r&   rN   r(   z$ - Listing term updated successfullyz!Listing Term updated successfullyr)   z/ - Validation errors during Listing Term updatez#: Listing Term not found for updateListing Term not foundrv   r1   z7 - Unexpected error occurred during Listing Term updaterr   )r   r   r3   r   r   r*   r5   r   r   rR   r   r4   r   rO   rP   r   rQ   r7   r8   r   r:   rw   r9   r;   )	r<   r=   r'   r>   r?   rs   rA   rT   rC   s	            rD   rW   zListingTermsCRUDView.put   s   +A.v,r')*<)==hij	u$WtFm<VGLL,,VR8;K:LMv,/WXY&+HvOjOjkk'//33r3:L/7<<PJ""$!v,r'+2F1GGklm'Z__Beff6l^2j.?.?-@@opq"z'8'8v?Z?Z[[(( 	a6l^+NOP"'?fF_F_`` 	T6l^+@R	JK"Rv7R7RSS 	u7|nBs1vh6mno"'GfNsNstt	usD   A!E BE A E =H&H&=GH&H&&5H!H&!H&c           	      
   t        d      }t        d| dt        d    d       	 t        j                  j                  |      }|j                          t        d| dt        d    d       t        d	
      S # t        j                  $ r- t        d| d       t        dt        j                        cY S t        $ r@}t        d| dt        |       d       t        dt        j                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z. - ListingTermsCRUDView DELETE request startedr&   r(   z$ - Listing term deleted successfullyz!Listing Term deleted successfullyrY   r-   z%: Listing Term not found for deletionry   r/   r1   z9 - Unexpected error occurred during Listing Term deletionrr   )r   r   r3   r   r4   r5   rZ   r   r7   r   r   r8   r9   r:   r;   )r<   r=   r'   r>   r?   rs   rC   s          rD   rZ   zListingTermsCRUDView.delete   s    +A.v,r')*<)==klm
	u'//33r3:L!6l^2gk.B-CCghi#(KLL(( 	a6l^+PQR"'?fF_F_`` 	u7|nBs1vh6opq"'GfNsNstt	ur[   r\   r]   r^   rb   rc   rD   rp   rp      s    u*u(u6urc   rp   c                   ,    e Zd ZddZddZddZddZy)ListingCRUDViewNc           	         t        d      }t        d| dt        d    d       	 |r[t        j                  j                  |      }t        |      }t        d| dt        d    d       t        |j                  d	
      S t        j                  j                         }t        |d      }t        d| dt        d    d       t        |j                  d
      S # t        j                  $ r- t        d| d       t        dt        j                        cY S t        $ r1}t        d| dt        |       d       t        d      cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z& - ListingCRUDView GET request startedr&   r(   z! - Listing retrieved successfullyzListing retrieved successfullyr)   Tr+   z" - Listings retrieved successfullyzListings retrieved successfullyr-   : Listing not foundzListings not foundr/   r1   z5 - Unexpected error occurred during Listing retrievalrr   rY   )r   r   r3   r   r4   r5   r   r   r*   r6   r7   r   r   r8   r9   r:   )	r<   r=   r'   r>   r?   rl   rA   listingsrC   s	            rD   r5   zListingCRUDView.get  sA   +A.v,r')*<)==cde	K!//--2-6.w7
v,r'+2F1GGhij'zFfgg"??..0.xdC
v,r'+2F1GGijk'zDeff## 	a6l^+>?@")=fF_F_`` 	K7|nBs1vh6klm")IJJ	Ks+   AC AC =EE%&EEEc           	         t        d      }t        d| dt        d    d       	 t        |g d       t	        d|j
                  j                  dd      d	g       t        |j
                  j                  d
d            }t	        d|j
                  j                  dd      dg       |j
                  j                         }||d
<   t        |j
                        }|j                         r@|j                          t        d| dt        d    d       t        |j
                  d      S t        d| d|j                   d       t        |j                  t        j                         S # t"        $ rH}t        d| dt%        |              t        t%        |      t        j&                        cY d }~S d }~wt(        $ r1}t        d| dt%        |       d       t        d      cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z' - ListingCRUDView POST request startedrG   rH   rK   rL   rI   rJ   rM   rN   r(   z - Listing created successfullyzListing created successfullyr)   r-   z, - Validation errors during Listing creationr/   rv   r1   z4 - Unexpected error occurred during Listing creationrr   rY   )r   r   r3   r   r   r*   r5   r	   copyr   rO   rP   r   rQ   r   r   rR   r   r:   rw   r9   )	r<   r=   r>   r?   rI   r*   rA   rT   rC   s	            rD   rU   zListingCRUDView.post#  s   +A.v,r')*<)==def	K$W.IJWgll..wr:<L;MN4W\\5E5EjQS5TUHVGLL,,VB79I8JK<<$$&D'D*=J""$!v,r'+2F1GGfgh'zFdee6l^2j.?.?-@@lmn"):):6C^C^__ 	T6l^+@R	JK"Rv7R7RSS 	K7|nBs1vh6jkl")IJJ	Ks7   DE/ .A E/ /	G88=F;5G8;G8&G3-G83G8c           	         t        d      }t        d| dt        d    d       	 t        |g d       t	        d|j
                  j                  dd      d	g       t        |j
                  j                  d
d             t	        d|j
                  j                  dd      dg       |s*t        d| d       t        dt        j                        S t        j                  j                  |      }t        ||j
                        }|j                         r@|j                          t        d| dt        d    d       t!        |j
                  d      S t        d| d|j"                   d       t        |j"                  t        j$                        S # t        j&                  $ r- t        d| d       t        dt        j                        cY S t(        $ rH}t        d| dt+        |              t        t+        |      t        j,                        cY d }~S d }~wt.        $ r@}t        d| dt+        |       d       t        dt        j0                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z& - ListingCRUDView PUT request startedrG   rH   rK   rL   rI   rJ   rM   r-   z: Listing ID is requiredzListing ID is requiredr/   r&   rN   r(   z - Listing updated successfullyzListing updated successfullyr)   z* - Validation errors during Listing updatez: Listing not found for updateListing not foundrv   r1   z2 - Unexpected error occurred during Listing updaterr   )r   r   r3   r   r   r*   r5   r	   r   r   r8   r   r4   r   rO   rP   r   rQ   rR   r7   r   r:   rw   r9   r;   )	r<   r=   r'   r>   r?   rl   rA   rT   rC   s	            rD   rW   zListingCRUDView.put;  s   +A.v,r')*<)==cde	y$W.IJWgll..wr:<L;MN)',,*:*::b*IJVGLL,,VB79I8JKv,/GHI&+C&JcJcddoo))r)2G*7FJ""$!v,r'+2F1GGfgh'zDbcc6l^2j.?.?-@@jkl"):):6C^C^__## 	`6l^+IJK")<VE^E^__ 	T6l^+@R	JK"Rv7R7RSS 	y7|nBs1vh6hij")IRXRwRwxx	ysD   B.F BF A F =I3I3$=H'!I3'I335I.(I3.I3c           	         t        d      }t        d| dt        d    d       	 t        j                  j                  |      }|j                          t        d| dt        d    d       t        d	
      S # t        j                  $ r t        d| d       t        d
      cY S t        $ r@}t        d| dt        |       d       t        dt        j                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z) - ListingCRUDView DELETE request startedr&   r(   z - Listing deleted successfullyzListing deleted successfullyrY   r-   r~   r   r1   z4 - Unexpected error occurred during Listing deletionrr   r/   )r   r   r3   r   r4   r5   rZ   r   r7   r   r9   r:   r   r;   )r<   r=   r'   r>   r?   rl   rC   s          rD   rZ   zListingCRUDView.deleteX  s    +A.v,r')*<)==fgh
	yoo))r)2GNN6l^2gk.B-CCbcd#*HII## 	>6l^+>?@")<== 	y7|nBs1vh6jkl")IRXRwRwxx	ys$   AA; ;.C3+C335C.(C3.C3r\   r]   r^   rb   rc   rD   r|   r|     s    K*K0y:yrc   r|   c                       e Zd ZddZy)ListingCountViewNc           	         t        d      }t        d| dt        d    d       	 t        j                  j                         }t        d| dt        d    d|        t        d|it        j                  	      S # t        $ rN}t        d
| dt        |       d       t        d
dt        |       it        j                  	      cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z' - ListingCountView GET request startedr(   z0 - Total listings count retrieved successfully: total_listingsr*   r   r1   z; - Unexpected error occurred while retrieving listing countrr   )r   r   r3   r   r4   countr   r   HTTP_200_OKr9   r:   r;   )r<   r=   r>   r?   r   rC   s         rD   r5   zListingCountView.geti  s    +A.v,r')*<)==def	$__224N6l^2gk.B-CCs  uC  tD  E  F(8))   	7|nBs1vh6qrs#A#a&!JK<< 	s   AA< <	CACCCr]   r_   r`   ra   r5   rb   rc   rD   r   r   h  s    rc   r   c                       e Zd ZddZy)ListingRecentViewNc           	         t        d      }t        d| dt        d    d       	 t        j                  j                  d      }t        d| d       t               }d|_        t        |j                  j                  d	|j                              |_        t        |j                  j                  d
d            |_        |j                  ||      }t        |d      }t        d| d       |j                         }t         j                  j#                         }	|	D 
cg c]  }
|
j$                   }}
t        d| d       |j&                  |||d}t        d| d       |j)                  |      S c c}
w # t*        $ rN}t        d| dt-        |       d       t/        ddt-        |       it0        j2                        cY d }~S d }~ww xY w)Nr"   r#   r$   r%   z( - ListingRecentView GET request startedz-created_atz:: Listings ordered by creation date retrieved successfully
   limitoffsetr   Tr+   z>: Listings pagination and serialization completed successfullyz1: Categories retrieved and descriptions extracted)r   total_count
categoriesapplied_countz%: Response data prepared successfullyr1   z/ - Unexpected error occurred during GET requestrr   r   )r   r   r3   r   r4   order_byr   default_limitintquery_paramsr5   r   r   paginate_querysetr   r   r   r6   descriptionr*   get_paginated_responser9   r:   r   r   r;   )r<   r=   r>   r?   r   	paginatorresult_pagerA   r   r   catcategory_descresponse_datarC   s                 rD   r5   zListingRecentView.get}  s   +A.v,r')*<)==efg	//>H6l^+efg-/I&(I#!'"6"6":":7ID[D["\]IO"7#7#7#;#;Ha#HII#55hHK04HJ6l^+ijk"..*K(00446J8BCS__CMC6l^+\]^&OO*+!,	M 6l^+PQR33MBB D  	7|nBs1vh6efg#A#a&!JK<< 	s2   C=E= #E86AE= 8E= =	GAG	GGr]   r   rb   rc   rD   r   r   |  s    rc   r   c                   D    e Zd Zej                  j                         ZeZy)ListingSingleAPIViewN)	r_   r`   ra   r   r4   r6   querysetr   serializer_classrb   rc   rD   r   r     s    ""$H1rc   r   c                       e Zd Zd Zy)#SearchListingFromNameOrCategoryViewc                    |j                   j                  d      }|j                   j                  d      }	 t        j                  j	                         }|r|j                  |      }|r|j                  |      }|j                         st        dg it        j                        S t        |d      }t        d|j                  it        j                        S # t        $ r0}t        d	t        |      it        j                        cY d }~S d }~wt        $ r'}t        d	d
it        j                         cY d }~S d }~ww xY w)NrH   category)title__icontains)'listingcategory__description__icontainsr   r   Tr+   r1   zAn unexpected error occurred.)GETr5   r   r4   r6   filterexistsr   r   r   r   r*   r   r:   r8   r9   r;   )	r<   r=   argskwargsrH   r   r   rA   rC   s	            rD   r5   z'SearchListingFromNameOrCategoryView.get  s    (;;??:.	v**,H#??E?B#??U]?^??$R 09K9KLL*8$?JZ9&BTBTUU 	QWc!f-f6O6OPP 	vW&EFvOtOtuu	vs6   A2C +3C 	E(%DEEE;EENr   rb   rc   rD   r   r     s    vrc   r   N).rest_framework.viewsr   rest_framework.responser   rest_frameworkr   utils.validationr   r   utils.helperr	   r
   modelsr   r   r   r   serializersr   r   r   r   r   r   r   r   r   rest_framework.paginationr   utils.exceptionr   r   utils.loggerr   
utils.datar   r3   r    re   rp   r|   r   r   RetrieveAPIViewr   r   rb   rc   rD   <module>r      s    ( , ! ? 6 ! # R R u  u Q Q ; :  &Vsg VsrIsW IsXRu7 RujXyg Xyvw ( D2833 2
v' vrc   