Fakultas Ilmu Komputer UI

Commit 41191c83 authored by BIMO IMAN SMARTADI's avatar BIMO IMAN SMARTADI
Browse files

Merge branch 'oauth_and_refactor_code_smell' into 'PBI-4-menambahkan_informasi_fasilitas_publik'

Oauth and refactor code smell

See merge request !30
parents aa6c4570 2a3c3b67
Pipeline #41071 passed with stages
in 6 minutes and 11 seconds
from django.apps import AppConfig
class HelloworldConfig(AppConfig):
name = 'helloworld'
<!DOCTYPE html>
<html>
<head>
<title>Konnichihello</title>
</head>
<body>
Hello World1
</body>
</html>
\ No newline at end of file
from django.conf.urls import url
from django.urls import path
from .views import helloworld
from . import views
app_name = "helloworld"
urlpatterns = [
path('', views.helloworld, name='helloworld'),
]
\ No newline at end of file
from django.shortcuts import render
# Create your views here.
def helloworld(request):
return render(request, 'helloworld.html')
# Generated by Django 2.1.5 on 2020-04-17 10:26
# Generated by Django 2.1.5 on 2020-04-17 13:50
from django.conf import settings
from django.db import migrations, models
......
......@@ -18,7 +18,7 @@ RUNNING_TEXT = 'RT'
TEMPAT_PARKIR_BIASA = 'TB'
FACILITIES = (
((KURSI_RODA, 'Kursi Roda'),
(KURSI_RODA, 'Kursi Roda'),
(LIFT_DISABILITAS, 'Lift Disabilitas'),
(TOILET_DISABILITTAS, 'Toilet Disabilitas'),
(MASJID_MUSHOLA, 'Masjid/Mushola'),
......@@ -30,8 +30,9 @@ FACILITIES = (
(KURSI_UMUM_DISABILITAS, 'Kursi Umum Disabilitas'),
(TEMPAT_PARKIR_DISABILITAS, 'Tempat Parkir Disabilitas'),
(RUNNING_TEXT, 'Running Text'),
(TEMPAT_PARKIR_BIASA, 'Tempat Parkir Biasa'))
)
(TEMPAT_PARKIR_BIASA, 'Tempat Parkir Biasa')
)
class Lokasi(models.Model):
name = models.CharField(max_length=50)
......
from django.test import TestCase
from django.db.utils import IntegrityError
from .models import Lokasi, Fasilitas, Komentar, KURSI_RODA, RUNNING_TEXT
# from registrasi.models import User
from registrasi.models import BisaGoUser
from django.contrib.auth.models import User
import tempfile
# Create your tests here.
class Informasi_Fasilitas_Test(TestCase):
class InformasiFasilitasTest(TestCase):
not_null_constraint_failed_message = 'NOT NULL constraint failed'
def test_models_lokasi_not_created(self):
with self.assertRaises(IntegrityError) as cm:
obj = Lokasi(name=None)
obj.save();
self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed'))
obj.save()
self.assertTrue(str(cm.exception).startswith(self.not_null_constraint_failed_message))
def test_models_create_new_lokasi(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
......@@ -30,8 +31,8 @@ class Informasi_Fasilitas_Test(TestCase):
def test_models_fasilitas_not_created(self):
with self.assertRaises(IntegrityError) as cm:
obj = Fasilitas(lokasi=None)
obj.save();
self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed'))
obj.save()
self.assertTrue(str(cm.exception).startswith(self.not_null_constraint_failed_message))
def test_models_create_new_fasilitas(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
......@@ -68,7 +69,7 @@ class Informasi_Fasilitas_Test(TestCase):
with self.assertRaises(IntegrityError) as cm:
obj = Komentar(fasilitas=None)
obj.save();
self.assertTrue(str(cm.exception).startswith('NOT NULL constraint failed'))
self.assertTrue(str(cm.exception).startswith(self.not_null_constraint_failed_message))
def test_models_create_new_komentar(self):
image = tempfile.NamedTemporaryFile(suffix=".jpg").name
......
......@@ -2,12 +2,7 @@ from django.urls import path, include
from rest_framework import routers
from . import views
#router = routers.DefaultRouter()
#router.register(r'lokasis', views.LokasiViewSet)
urlpatterns = [
#path('', include(router.urls)),
#path('api-auth/', include('rest_framework.urls', namespace='rest_framework'))
path('lokasi/list/', views.lokasi_list,name='lokasi-list'),
path('lokasi/detail/<str:name>', views.lokasi_details,name='lokasi-details'),
path('lokasi/add/', views.add_lokasi,name='add-lokasi'),
......
......@@ -10,11 +10,11 @@ from rest_framework.authentication import TokenAuthentication
from .serializers import LokasiSerializer
from .models import Lokasi, Fasilitas, Komentar
# Create your views here.
def request_error_message(request_kind):
return "get {} request instead".format(request_kind)
#class LokasiViewSet(viewsets.ModelViewSet):
# queryset = Lokasi.objects.all().order_by('name')
# serializer_class = LokasiSerializer
def missing_key_message(key):
return "bad request. {} key needed".format(key)
@csrf_exempt
@api_view(['GET'])
......@@ -26,7 +26,7 @@ def lokasi_list(request):
serializer = LokasiSerializer(lokasi_list, many=True)
return JsonResponse(serializer.data, safe=False)
else:
return JsonResponse({'response' : 'try get request instead'}, status = 400)
return JsonResponse({'response' : request_error_message("get")}, status = 400)
@api_view(['GET'])
@authentication_classes([])
......@@ -38,9 +38,9 @@ def lokasi_details(request,name):
serializer = LokasiSerializer(lokasi)
return JsonResponse(serializer.data, safe=False)
else:
return JsonResponse({'response' : 'try get request instead'}, status = 400)
return JsonResponse({'response' : request_error_message("get")}, status = 400)
except KeyError as e:
return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500)
return JsonResponse({'response': missing_key_message(str(e))}, status = 500)
except:
return JsonResponse({'response':'lokasi not found'}, status = 404)
......@@ -59,9 +59,9 @@ def add_lokasi(request):
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)
else:
return JsonResponse({'response' : 'try post request instead'}, status = 400)
return JsonResponse({'response' : request_error_message("post")}, status = 400)
except KeyError as e:
return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500)
return JsonResponse({'response': missing_key_message(str(e))}, status = 500)
@api_view(['GET'])
@authentication_classes([TokenAuthentication,])
......@@ -88,9 +88,9 @@ def list_fasilitas(request, nama_lokasi):
fasilitas_details["is_verified"] = fasilitas.is_verified
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.
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,])
......@@ -108,11 +108,11 @@ def add_fasilitas(request, nama_lokasi):
image=image)
return JsonResponse({'response' : 'fasilitas added', 'id':fasilitas.id}, status = 201)
else:
return JsonResponse({'response' : 'try post request instead'}, status = 400)
return JsonResponse({'response' : request_error_message("post")}, status = 400)
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'}, status = 404)
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([])
......@@ -127,8 +127,8 @@ def detail_fasilitas(request, nama_lokasi, id):
"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)
else:
return JsonResponse({'response' : 'try get request instead'}, status = 400)
return JsonResponse({'response' : request_error_message("get")}, status = 400)
except KeyError as e:
return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500)
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
from django.contrib import admin
# Register your models here.
from django.db import models
# Create your models here.
......@@ -6,11 +6,6 @@ import new_rest_api.views
from django.views.generic import TemplateView
router = routers.DefaultRouter()
#router.register(r'users', rest_api.views.UserViewSet)
#router.register(r'groups', rest_api.views.GroupViewSet)
urlpatterns = [
path('user-list/', new_rest_api.views.user_list,name='user-list'),
path('user-detail/<str:email>', new_rest_api.views.user_details,name='user-details'),
......
......@@ -16,6 +16,13 @@ from rest_framework.decorators import api_view, permission_classes, authenticati
from registrasi.models import BisaGoUser
def request_error_message(request_kind):
return "get {} request instead".format(request_kind)
def missing_key_message(key):
return "bad request. {} key needed".format(key)
@csrf_exempt
@api_view(['GET'])
@authentication_classes([])
......@@ -29,10 +36,9 @@ def user_list(request):
"name": user.user.last_name,
"email": user.user.email,
"phone_number": user.phone_number})
#serializer = UserSerializer(user_list, many=True)
return JsonResponse(json_return, safe=False)
else:
return JsonResponse({'response' : 'try get request instead'}, status = 400)
return JsonResponse({'response' : request_error_message("get")}, status = 400)
@api_view(['GET'])
@authentication_classes([])
......@@ -62,5 +68,5 @@ def register_user(request):
BisaGoUser.objects.create(user= user, phone_number=phone_number)
return JsonResponse({'response' : 'User created', 'email':email, 'name':name}, status = 201)
except KeyError as e:
return JsonResponse({'response':'bad request. {} key needed'.format(str(e))}, status = 500)
# Create your views here.
return JsonResponse({'response':missing_key_message(str(e))}, status = 500)
\ No newline at end of file
from django.apps import AppConfig
class LoginConfig(AppConfig):
name = 'login'
class OauthConfig(AppConfig):
name = 'oauth'
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