Fakultas Ilmu Komputer UI

Commit edfe3d50 authored by Abdurrahman's avatar Abdurrahman
Browse files

[REFACTOR] minor refactoring for consistency

parent 492a5334
Pipeline #42046 passed with stages
in 4 minutes and 25 seconds
......@@ -4,9 +4,9 @@ from . import views
urlpatterns = [
path('lokasi/list/', views.lokasi_list,name='lokasi-list'),
path('lokasi/detail/<str:name>', views.lokasi_details,name='lokasi-details'),
path('lokasi/detail/<str:name>/', views.lokasi_details,name='lokasi-details'),
path('lokasi/add/', views.add_lokasi,name='add-lokasi'),
path('lokasi/add-fasilitas/<str:nama_lokasi>', views.add_fasilitas, name='add-fasilitas'),
path('lokasi/list-fasilitas/<str:nama_lokasi>', views.list_fasilitas, name='list-fasilitas'),
path('lokasi/detail-fasilitas/<str:nama_lokasi>/<int:id>', views.detail_fasilitas, name='detail-fasilitas'),
path('lokasi/add-fasilitas/<str:nama_lokasi>/', views.add_fasilitas, name='add-fasilitas'),
path('lokasi/list-fasilitas/<str:nama_lokasi>/', views.list_fasilitas, name='list-fasilitas'),
path('lokasi/detail-fasilitas/<str:nama_lokasi>/<int:id>/', views.detail_fasilitas, name='detail-fasilitas'),
]
\ No newline at end of file
......@@ -5,7 +5,8 @@ from django.contrib.auth.models import User
from rest_framework import viewsets
from rest_framework.decorators import api_view, permission_classes, authentication_classes
from rest_framework.authentication import TokenAuthentication
from rest_framework.authentication import TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from .serializers import LokasiSerializer
from .models import Lokasi, Fasilitas, Komentar
......@@ -24,7 +25,7 @@ def lokasi_list(request):
if request.method == 'GET':
lokasi_list = Lokasi.objects.all()
serializer = LokasiSerializer(lokasi_list, many=True)
return JsonResponse(serializer.data, safe=False)
return JsonResponse(serializer.data, safe=False, status = 200)
else:
return JsonResponse({'response' : request_error_message("get")}, status = 400)
......@@ -36,7 +37,7 @@ def lokasi_details(request,name):
if request.method == 'GET':
lokasi = Lokasi.objects.get(name = name)
serializer = LokasiSerializer(lokasi)
return JsonResponse(serializer.data, safe=False)
return JsonResponse(serializer.data, safe=False, status = 200)
else:
return JsonResponse({'response' : request_error_message("get")}, status = 400)
except KeyError as e:
......@@ -45,8 +46,8 @@ def lokasi_details(request,name):
return JsonResponse({'response':'lokasi not found'}, status = 404)
@api_view(['POST'])
@authentication_classes([])
@permission_classes([])
@authentication_classes([TokenAuthentication])
@permission_classes([IsAuthenticated])
def add_lokasi(request):
try:
if request.method == 'POST':
......@@ -64,7 +65,7 @@ def add_lokasi(request):
return JsonResponse({'response': missing_key_message(str(e))}, status = 500)
@api_view(['GET'])
@authentication_classes([TokenAuthentication,])
@authentication_classes([])
@permission_classes([])
def list_fasilitas(request, nama_lokasi):
try:
......@@ -86,15 +87,15 @@ def list_fasilitas(request, nama_lokasi):
fasilitas_details["tag"] = fasilitas.tag
fasilitas_details["image"] = str(fasilitas.image)
fasilitas_details["is_verified"] = fasilitas.is_verified
return JsonResponse(return_json, status = 201)
return JsonResponse(return_json, status = 200)
except KeyError as e:
return JsonResponse({'response': missing_key_message(str(e))}, status = 500)
except Exception as e:
return JsonResponse({'response': str(e)})
@api_view(['POST'])
@authentication_classes([TokenAuthentication,])
@permission_classes([])
@authentication_classes([TokenAuthentication])
@permission_classes([IsAuthenticated])
def add_fasilitas(request, nama_lokasi):
try:
if request.method == 'POST':
......@@ -125,7 +126,7 @@ def detail_fasilitas(request, nama_lokasi, id):
user = fasilitas.user
return_json = {"nama_lokasi": lokasi.name, "deskripsi":fasilitas.deskripsi, "creator":user.last_name, "date_time":fasilitas.date_time,
"like":fasilitas.like, "dislike":fasilitas.dislike, "rating":fasilitas.rating, "tag":fasilitas.tag, "image":str(fasilitas.image), "is_verified":fasilitas.is_verified}
return JsonResponse(return_json, status = 201)
return JsonResponse(return_json, status = 200)
else:
return JsonResponse({'response' : request_error_message("get")}, status = 400)
except KeyError as e:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment