Fakultas Ilmu Komputer UI

Commit f0ddfef7 authored by Usman Sidiq's avatar Usman Sidiq
Browse files
parents df6044c2 2d996682
Pipeline #40081 passed with stages
in 41 minutes and 8 seconds
......@@ -12,7 +12,6 @@ urlpatterns = [
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/list-fasilitas/<str:nama_lokasi>', views.list_fasilitas, name='list-fasilitas'),
path('lokasi/detail-fasilitas/<str:nama_lokasi>', views.detail_fasilitas, name='detail-fasilitas'),
]
\ No newline at end of file
......@@ -63,26 +63,26 @@ def add_lokasi(request):
except KeyError as e:
return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500)
# @api_view(['GET'])
# @authentication_classes([TokenAuthentication,])
# @permission_classes([])
# def list_fasilitas(request, nama_lokasi):
# try:
# if request.method == 'GET':
# lokasi = Lokasi.objects.get(name = nama_lokasi)
# fasilitas = Fasilitas.objects.get(lokasi=lokasi)
# name = request.POST['name']
# latitude = request.POST['latitude']
# longitude = request.POST['longitude']
# alamat = request.POST['alamat']
# no_telp = request.POST['no_telp']
# image = request.POST['image']
# Lokasi.objects.create(name=name, latitude=latitude, longitude=longitude, alamat=alamat, no_telp=no_telp, image=image)
# return JsonResponse({'response' : 'Location added', 'name':name}, status = 201)
# except KeyError as e:
# return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500)
# except:
# return JsonResponse({'response': 'lokasi might not be here'}) # Create your views here.
@api_view(['GET'])
@authentication_classes([TokenAuthentication,])
@permission_classes([])
def list_fasilitas(request, nama_lokasi):
try:
if request.method == 'GET':
lokasi = Lokasi.objects.get(name = nama_lokasi)
list_fasilitas = Fasilitas.objects.filter(lokasi=lokasi)
return_json = {}
for fasilitas in list_fasilitas:
return_json[fasilitas.id] = {}
fasilitas_details = return_json[fasilitas.id]
fasilitas_details["fasilitas_id"] = fasilitas.id
fasilitas_details["fasilitas_location"] = fasilitas.lokasi.name
fasilitas_details["creator"] = fasilitas.user.last_name
return JsonResponse(return_json, status = 201)
except KeyError as e:
return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500)
except:
return JsonResponse({'response': 'lokasi might not be here'}) # Create your views here.
@api_view(['POST'])
@authentication_classes([TokenAuthentication,])
......@@ -123,4 +123,4 @@ def detail_fasilitas(request, nama_lokasi, id):
except KeyError as e:
return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500)
except Exception as e:
return JsonResponse({'response': str(e)}, status = 502)
\ No newline at end of file
return JsonResponse({'response': str(e)}, status = 404)
\ No newline at end of file
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