Fakultas Ilmu Komputer UI

Commit 9c7a0c21 authored by Usman Sidiq's avatar Usman Sidiq
Browse files

Merge branch 'PBI-6-melihat_halaman_detail_fasilitas_publik' into 'staging'

Pbi 6 melihat halaman detail fasilitas publik

See merge request !46
parents 7d188867 b2139ec3
Pipeline #44653 passed with stages
in 6 minutes and 57 seconds
......@@ -10,6 +10,10 @@ urlpatterns = [
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-komentar/<str:nama_lokasi>/', views.add_komentar, name='add-komentar'),
path('lokasi/list-komentar/<str:nama_lokasi>/<int:id>/', views.list_komentar, name='list-komentar'),
path('lokasi/update-fasilitas/<str:nama_lokasi>/<int:id>/', views.update_fasilitas, name='update-fasilitas'),
path('lokasi/like-fasilitas/<str:nama_lokasi>/<int:id>/<str:operation>/', views.update_like_fasilitas, name='update-like-fasilitas'),
path('lokasi/add-komentar/<str:nama_lokasi>/<int:id>/', views.add_komentar, name='add-komentar'),
path('lokasi/list-komentar/<str:nama_lokasi>/<int:id>/', views.list_komentar, name='list-komentar'),
]
\ No newline at end of file
......@@ -233,5 +233,50 @@ def update_like_fasilitas(request, nama_lokasi, id, operation):
return JsonResponse({'response': "you've successfuly {}d this facility".format(operation)}, status = 201)
except KeyError as e:
return JsonResponse({'response': missing_key_message(str(e))}, status = 500)
except Exception as e:
return JsonResponse({'response': str(e)}, status = 404)
@api_view(['POST'])
@authentication_classes([TokenAuthentication])
@permission_classes([IsAuthenticated])
def add_komentar(request, nama_lokasi, id):
try:
if request.method == 'POST':
lokasi = Lokasi.objects.get(name = nama_lokasi)
fasilitas = Fasilitas.objects.get(lokasi=lokasi, id=id)
user = User.objects.get(email=str(request.user))
deskripsi = request.POST['deskripsi']
komentar = Komentar.objects.create(fasilitas=fasilitas,
user=user,
deskripsi=deskripsi)
return JsonResponse({'response' : 'komentar added', 'id':komentar.id}, status = 201)
else:
return JsonResponse({'response' : request_error_message("post")}, status = 400)
except KeyError as e:
return JsonResponse({'response': missing_key_message(str(e))}, status = 500)
except Exception as e:
return JsonResponse({'response': str(e)}, status = 404)
@api_view(['GET'])
@authentication_classes([])
@permission_classes([])
def list_komentar(request, nama_lokasi, id):
try:
if request.method == 'GET':
lokasi = Lokasi.objects.get(name=nama_lokasi)
fasilitas = Fasilitas.objects.get(lokasi=lokasi, id=id)
list_komentar = Komentar.objects.filter(fasilitas=fasilitas)
return_json = {}
for komentar in list_komentar:
return_json[komentar.id] = {}
komentar_details = return_json[komentar.id]
komentar_details["id"] = komentar.id
komentar_details["deskripsi"] = komentar.deskripsi
komentar_details["creator"] = komentar.user.last_name
komentar_details["date_time"] = komentar.date_time
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)}, status = 404)
\ No newline at end of file
......@@ -28,7 +28,7 @@ mccabe==0.6.1
oauthlib==3.1.0
Pillow==7.0.0
pip==20.0.2
psycopg2==2.8.4
psycopg2
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.19
......
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