o
    Ii%                     @   s   d dl 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mZmZ d d	lmZ G d
d dejZG dd dejZG dd dejZdS )    )viewsetsstatusfilters)action)Response)IsAuthenticated)DjangoFilterBackend   )NotificationFavoriteActivity)NotificationSerializerFavoriteSerializerActivitySerializer)StandardResultsSetPaginationc                   @   s   e Zd ZdZeZegZeZ	e
ejgZddgZdgZdgZdd Zedd	gd
dddZedd	gd
dd Zeddgd
dd ZdS )NotificationViewSetzNotification ViewSettypeis_read
created_at-created_atc                 C      t jj| jjdS Nuser)r
   objectsfilterrequestr   self r   8/var/www/newdalilibackend/backend/notifications/views.pyget_queryset      z NotificationViewSet.get_querysetTpostdetailmethodsNc                 C   s   |   }|  tt|jS )zMark notification as read)
get_objectmark_as_readr   r   data)r   r   pknotificationr   r   r    	mark_read   s   zNotificationViewSet.mark_readFc                 C   s,   t jj|jddjdd}td| diS )zMark all notifications as readFr   r   T)r   messagez notifications marked as read)r
   r   r   r   updater   r   r   countr   r   r    mark_all_read   s   z!NotificationViewSet.mark_all_readgetc                 C   s"   t jj|jdd }td|iS )zGet unread notifications countFr-   r1   )r
   r   r   r   r1   r   r0   r   r   r    unread_count(   s   z NotificationViewSet.unread_count)N)__name__
__module____qualname____doc__r   serializer_classr   permission_classesr   pagination_classr   r   OrderingFilterfilter_backendsfilterset_fieldsordering_fieldsorderingr!   r   r,   r2   r4   r   r   r   r    r      s     

r   c                   @   sZ   e Zd ZdZeZegZeZ	e
ejgZdgZdgZdd Zdd Zedd	gd
dd ZdS )FavoriteViewSetzFavorite ViewSetr   r   c                 C   r   r   )r   r   r   r   r   r   r   r   r    r!   ;   r"   zFavoriteViewSet.get_querysetc                 C      |j | jjd d S r   saver   r   r   
serializerr   r   r    perform_create>      zFavoriteViewSet.perform_createFr#   r$   c           	      C   sN  ddl m} ddl}|t}|jdp|jd}|d|j	j
 d|  |s8|d tdd	itjd
S z	|jj|d}W n |jy]   |d| d tdditjd
 Y S w tjj|j	|d }|r|  d}|d|j	j
 d|  ntjj|j	|d d}|d|j	j
 d|  t||j
|rddS ddS )z"Toggle favorite status for a placer   )PlaceNplace_idz Toggle favorite request - User: z, Place ID: z,Toggle favorite failed - place_id is missingerrorzplace_id is required)r   )r*   zToggle favorite failed - Place z
 not foundzPlace not found)r   placeFzFavorite removed - User: z	, Place: TzFavorite added - User: u2   تم إضافة المكان إلى المفضلةu0   تم إزالة المكان من المفضلة)is_favoriterJ   r.   )places.modelsrI   logging	getLoggerr5   r)   r3   query_paramsinfor   idwarningr   r   HTTP_400_BAD_REQUESTr   DoesNotExistHTTP_404_NOT_FOUNDr   r   firstdeletecreate)	r   r   rI   rO   loggerrJ   rL   favoriterM   r   r   r    toggleA   sP   


zFavoriteViewSet.toggleN)r5   r6   r7   r8   r   r9   r   r:   r   r;   r   r   r<   r=   r?   r@   r!   rG   r   r]   r   r   r   r    rA   2   s    
rA   c                   @   s`   e Zd ZdZeZegZeZ	e
ejgZdgZdgZdgZdd Zdd Zed	d
gddd ZdS )ActivityViewSetzActivity ViewSetr   r   r   c                 C   r   r   )r   r   r   r   r   r   r   r   r    r!   ~   r"   zActivityViewSet.get_querysetc                 C   rB   r   rC   rE   r   r   r    rG      rH   zActivityViewSet.perform_createFr#   r$   c                 C   s*   t jj|jd d }td| diS )zClear all activitiesr   r   r.   z activities cleared)r   r   r   r   rY   r   r0   r   r   r    clear   s   zActivityViewSet.clearN)r5   r6   r7   r8   r   r9   r   r:   r   r;   r   r   r<   r=   r>   r?   r@   r!   rG   r   r_   r   r   r   r    r^   t   s    
r^   N)rest_frameworkr   r   r   rest_framework.decoratorsr   rest_framework.responser   rest_framework.permissionsr   django_filters.rest_frameworkr   modelsr
   r   r   serializersr   r   r   common.paginationr   ReadOnlyModelViewSetr   ModelViewSetrA   r^   r   r   r   r    <module>   s    'B