dahee kim

fix: :bug: fix a few bugs

1 -# Generated by Django 3.1.2 on 2020-11-13 10:30 1 +# Generated by Django 3.1.2 on 2020-11-16 14:19
2 2
3 from django.db import migrations, models 3 from django.db import migrations, models
4 import django.utils.timezone 4 import django.utils.timezone
...@@ -15,7 +15,7 @@ class Migration(migrations.Migration): ...@@ -15,7 +15,7 @@ class Migration(migrations.Migration):
15 migrations.CreateModel( 15 migrations.CreateModel(
16 name='Device', 16 name='Device',
17 fields=[ 17 fields=[
18 - ('device_id', models.AutoField(auto_created=True, primary_key=True, serialize=False)) 18 + ('device_id', models.AutoField(primary_key=True, serialize=False)),
19 ('rfid_id', models.CharField(max_length=255)), 19 ('rfid_id', models.CharField(max_length=255)),
20 ('created', models.DateTimeField(default=django.utils.timezone.now)), 20 ('created', models.DateTimeField(default=django.utils.timezone.now)),
21 ], 21 ],
...@@ -27,14 +27,6 @@ class Migration(migrations.Migration): ...@@ -27,14 +27,6 @@ class Migration(migrations.Migration):
27 ], 27 ],
28 ), 28 ),
29 migrations.CreateModel( 29 migrations.CreateModel(
30 - name='RemoteHistory',
31 - fields=[
32 - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
33 - ('device_name', models.CharField(max_length=255)),
34 - ('ctrtime', models.DateTimeField(default=django.utils.timezone.now)),
35 - ],
36 - ),
37 - migrations.CreateModel(
38 name='Lock', 30 name='Lock',
39 fields=[ 31 fields=[
40 ('id', models.IntegerField(primary_key=True, serialize=False)), 32 ('id', models.IntegerField(primary_key=True, serialize=False)),
...@@ -49,6 +41,14 @@ class Migration(migrations.Migration): ...@@ -49,6 +41,14 @@ class Migration(migrations.Migration):
49 ], 41 ],
50 ), 42 ),
51 migrations.CreateModel( 43 migrations.CreateModel(
44 + name='RemoteHistory',
45 + fields=[
46 + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
47 + ('device_name', models.CharField(max_length=255)),
48 + ('ctrtime', models.DateTimeField(default=django.utils.timezone.now)),
49 + ],
50 + ),
51 + migrations.CreateModel(
52 name='Video', 52 name='Video',
53 fields=[ 53 fields=[
54 ('vid_name', models.CharField(max_length=255, primary_key=True, serialize=False)), 54 ('vid_name', models.CharField(max_length=255, primary_key=True, serialize=False)),
......
...@@ -22,36 +22,37 @@ from src.settings import S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_STORAGE_BUCK ...@@ -22,36 +22,37 @@ from src.settings import S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY, S3_STORAGE_BUCK
22 """ 22 """
23 import time 23 import time
24 from datetime import datetime, timedelta 24 from datetime import datetime, timedelta
25 +import json
25 # Create your views here. 26 # Create your views here.
26 27
27 #로그인 및 토큰 반환 28 #로그인 및 토큰 반환
28 class Login(APIView) : 29 class Login(APIView) :
29 def get(self, request, format = None) : # request query에 door_id 포함되어있음 : api/auth?door_id=12345 30 def get(self, request, format = None) : # request query에 door_id 포함되어있음 : api/auth?door_id=12345
30 try : 31 try :
31 - request_id = request.GET.get('door_id', None) 32 + request_id = request.GET.get('door_id', None)
32 - if request_id == 'None' : 33 + if request_id == None :
33 - raise FieldDoesNotExist 34 + raise FieldDoesNotExist
34 - queryset = Door.objects.filter(door_id = request_id) # door_id 유효성 검색 35 + queryset = Door.objects.filter(door_id = request_id) # door_id 유효성 검색
35 - if queryset.exists() # 유효할  36 + if queryset.exists() :# 유효할
36 - res = { 37 + res = {
37 - 'is_available' : True 38 + 'is_available' : True,
38 - 'access_token' : '토큰' # 토큰 도입 후 수정 필요 39 + 'access_token' : '토큰' # 토큰 도입 후 수정 필요
39 } 40 }
40 - else 41 + else :
41 - res = { 42 + res = {
42 - 'is_available' : False 43 + 'is_available' : False
43 } 44 }
44 45
45 - return Response(res, status = status.HTTP_200_OK) 46 + return Response(res, status = status.HTTP_200_OK)
46 47
47 - except FieldDoesNotExist as error : 48 + except FieldDoesNotExist as error :
48 - return Response({ 49 + return Response({
49 - 'error' : "FieldDoesNotExist ", 50 + 'error' : "FieldDoesNotExist ",
50 - 'date' : datetime.now() 51 + 'date' : datetime.now()
51 - }, status = status.HTTP_400_BAD_REQUEST) 52 + }, status = status.HTTP_400_BAD_REQUEST)
52 53
53 #기기 관련 api 54 #기기 관련 api
54 -class Device(APIView) : 55 +class Devices(APIView) :
55 # 기기 목록 조회 56 # 기기 목록 조회
56 def get(self, request, format = None) : 57 def get(self, request, format = None) :
57 queryset = Device.objects.all() 58 queryset = Device.objects.all()
...@@ -65,17 +66,22 @@ class Device(APIView) : ...@@ -65,17 +66,22 @@ class Device(APIView) :
65 # 기기 추가 66 # 기기 추가
66 def post(self, request, format = None) : # request body에 rfid_id 포함되어있음  67 def post(self, request, format = None) : # request body에 rfid_id 포함되어있음 
67 try : 68 try :
69 + print('냐냐냐냐냐냐')
70 + print(request.body)
68 data = json.loads(request.body) 71 data = json.loads(request.body)
69 request_id = data.get('rfid_id', None) 72 request_id = data.get('rfid_id', None)
70 - if request_id == 'None' : 73 + if request_id == None :
71 raise FieldDoesNotExist 74 raise FieldDoesNotExist
72 queryset = Device.objects.create(rfid_id = request_id) 75 queryset = Device.objects.create(rfid_id = request_id)
76 + return Response({
77 + 'msg' : 'success device add'
78 + })
73 79
74 except FieldDoesNotExist as error : 80 except FieldDoesNotExist as error :
75 - return Response({ 81 + return Response({
76 - 'error' : "FieldDoesNotExist ", 82 + 'error' : "FieldDoesNotExist ",
77 - 'date' : datetime.now() 83 + 'date' : datetime.now()
78 - }, status = status.HTTP_400_BAD_REQUEST) 84 + }, status = status.HTTP_400_BAD_REQUEST)
79 85
80 86
81 87
...@@ -83,16 +89,19 @@ class Device(APIView) : ...@@ -83,16 +89,19 @@ class Device(APIView) :
83 def delete(self, request, device_id, format = None): # request URI에 device_id(자동생성되는 기기 고유 번호 != rfid_id) 포함 89 def delete(self, request, device_id, format = None): # request URI에 device_id(자동생성되는 기기 고유 번호 != rfid_id) 포함
84 try : 90 try :
85 request_id = device_id 91 request_id = device_id
86 - if request_id == 'None': 92 + if request_id == None:
87 - raise FieldDoesNotExist 93 + raise FieldDoesNotExist
88 queryset = Device.objects.get(device_id=request_id) 94 queryset = Device.objects.get(device_id=request_id)
89 queryset.delete() 95 queryset.delete()
96 + return Response({
97 + 'msg' : 'success delete device'
98 + })
90 99
91 except FieldDoesNotExist as error : 100 except FieldDoesNotExist as error :
92 - return Response({ 101 + return Response({
93 - 'error' : "FieldDoesNotExist ", 102 + 'error' : "FieldDoesNotExist ",
94 - 'date' : datetime.now() 103 + 'date' : datetime.now()
95 - }, status = status.HTTP_400_BAD_REQUEST) 104 + }, status = status.HTTP_400_BAD_REQUEST)
96 105
97 # 원격 잠금 해제 106 # 원격 잠금 해제
98 class Remote(APIView): 107 class Remote(APIView):
......
...@@ -25,6 +25,7 @@ urlpatterns = [ ...@@ -25,6 +25,7 @@ urlpatterns = [
25 path('auto/checkDate', views.CheckDate.as_view()), 25 path('auto/checkDate', views.CheckDate.as_view()),
26 path('api/setting', views.Recording.as_view()), 26 path('api/setting', views.Recording.as_view()),
27 path('api/auth', views.Login.as_view()), 27 path('api/auth', views.Login.as_view()),
28 - path('api/device', views.Device.as_view()), 28 + path('api/device', views.Devices.as_view()),
29 - path('api/remote', view.Remote.as_view()), 29 + path('api/device/<str:device_id>', views.Devices.as_view()),
30 + path('api/remote', views.Remote.as_view()),
30 ] 31 ]
......