o
    uihI                     @   s   d dl 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
 d dlmZ d dlmZ d d	lmZ d
dlmZ ee
ddG dd deZee
ddG dd deZee
ddG dd deZdS )    N)JsonResponse)render)status)method_decorator)csrf_exempt)View)verify_token)User_Vehicles   )VehiclesSerializerdispatch)namec                   @   s   e Zd Zdd Zdd ZdS )Vehiclesc                 C   s\   t |}|d krtdtjddtjdS tjj|d}t|dd}t|jtj	ddtj	dS )	NUser not login.messager   Fsafer   user_idT)many)vehiclesr   )
r   r   r   HTTP_401_UNAUTHORIZEDr	   objectsfilterr   dataHTTP_200_OK)selfrequestr   r   
serializer r    ;/var/www/html/DRIVERZZ_CUSTOMER_APIS/user_vehicles/views.pyget   s   zVehicles.getc                 C   s   t |}|d krtdtjddtjdS t|j}t }||_|d |_	|d |_
|d |_|d |_|d	 |_|d
 |_|d |_|d |_|  tdtjddtjdS )Nr   r   Fr   vehicle_modelvehicle_model_namevehicle_typevehicle_type_nametransmission_typetransmission_type_namevehicle_name
vehicle_nozVehicle added successfully.)r   r   r   r   jsonloadsbodyr	   r   vehicle_model_idr$   vehicle_type_idr&   transmission_type_idr(   r)   r*   saver   r   r   r   request_datavehicler    r    r!   post   s    







zVehicles.postN)__name__
__module____qualname__r"   r5   r    r    r    r!   r      s    
r   c                   @      e Zd Zdd ZdS )VehicleDeletec                 C   s   t |}|d krtdtjddtjdS z!t|j}tjj	||d d}|
  tdtjddtjdW S  tjyK   tdtjddtjd Y S w )	Nr   r   Fr   idr   r;   zVehicle deleted successfully.-Something went wrong. Please try again later.)r   r   r   r   r+   r,   r-   r	   r   r"   deleter   DoesNotExistHTTP_400_BAD_REQUESTr2   r    r    r!   r5   0   s   zVehicleDelete.postNr6   r7   r8   r5   r    r    r    r!   r:   .       r:   c                   @   r9   )VehicleDefaultc                 C   s   t |}|d krtdtjddtjdS tjj|djdd z$t	|j
}tjj||d d	}d
|_|  tdtjddtjdW S  tjyY   tdtjddtjd Y S w )Nr   r   Fr   r   r   )
is_defaultr;   r<   r
   z,Vehicle set as default vehicle successfully.r=   )r   r   r   r   r	   r   r   updater+   r,   r-   r"   rD   r1   r   r?   r@   r2   r    r    r!   r5   A   s   zVehicleDefault.postNrA   r    r    r    r!   rC   ?   rB   rC   )r+   django.httpr   django.shortcutsr   rest_frameworkr   django.utils.decoratorsr   django.views.decorators.csrfr   django.viewsr   authentication.authr   user_vehicles.modelsr	   serializersr   r   r:   rC   r    r    r    r!   <module>   s     

 
