Fakultas Ilmu Komputer UI

Commit f2b280b5 authored by M. Abdurrahman's avatar M. Abdurrahman
Browse files

[REFACTOR] serialize post request add-lokasi

parent c78294ee
Pipeline #42165 passed with stages
in 5 minutes and 4 seconds
......@@ -196,8 +196,7 @@ class InformasiFasilitasViewTest(TestCase):
'latitude' : 0.0,
'longitude' : 0.0,
'alamat' : 'Jl. Raya Bogor no.1, Jakarta',
'no_telp' : '081212123131',
'image' : None})
'no_telp' : '081212123131'})
self.assertEqual(response.status_code, 201)
def test_cannot_get_add_lokasi(self):
......
......@@ -51,14 +51,14 @@ def lokasi_details(request,name):
def add_lokasi(request):
try:
if request.method == 'POST':
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)
data = request.POST
serializer = LokasiSerializer(data=data)
if serializer.is_valid():
serializer.save()
return JsonResponse(serializer.data, status=201)
else:
return JsonResponse(serializer.errors, status=400)
else:
return JsonResponse({'response' : request_error_message("post")}, 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