dahee kim

fix: :bug: fix a few bugs

# Generated by Django 3.1.2 on 2020-11-13 10:30
# Generated by Django 3.1.2 on 2020-11-16 14:19
from django.db import migrations, models
import django.utils.timezone
......@@ -15,7 +15,7 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Device',
fields=[
('device_id', models.AutoField(auto_created=True, primary_key=True, serialize=False))
('device_id', models.AutoField(primary_key=True, serialize=False)),
('rfid_id', models.CharField(max_length=255)),
('created', models.DateTimeField(default=django.utils.timezone.now)),
],
......@@ -27,14 +27,6 @@ class Migration(migrations.Migration):
],
),
migrations.CreateModel(
name='RemoteHistory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('device_name', models.CharField(max_length=255)),
('ctrtime', models.DateTimeField(default=django.utils.timezone.now)),
],
),
migrations.CreateModel(
name='Lock',
fields=[
('id', models.IntegerField(primary_key=True, serialize=False)),
......@@ -49,6 +41,14 @@ class Migration(migrations.Migration):
],
),
migrations.CreateModel(
name='RemoteHistory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('device_name', models.CharField(max_length=255)),
('ctrtime', models.DateTimeField(default=django.utils.timezone.now)),
],
),
migrations.CreateModel(
name='Video',
fields=[
('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
"""
import time
from datetime import datetime, timedelta
import json
# Create your views here.
#로그인 및 토큰 반환
class Login(APIView) :
def get(self, request, format = None) : # request query에 door_id 포함되어있음 : api/auth?door_id=12345
try :
request_id = request.GET.get('door_id', None)
if request_id == 'None' :
raise FieldDoesNotExist
queryset = Door.objects.filter(door_id = request_id) # door_id 유효성 검색
if queryset.exists() # 유효할 
res = {
'is_available' : True
'access_token' : '토큰' # 토큰 도입 후 수정 필요
request_id = request.GET.get('door_id', None)
if request_id == None :
raise FieldDoesNotExist
queryset = Door.objects.filter(door_id = request_id) # door_id 유효성 검색
if queryset.exists() :# 유효할
res = {
'is_available' : True,
'access_token' : '토큰' # 토큰 도입 후 수정 필요
}
else
res = {
'is_available' : False
else :
res = {
'is_available' : False
}
return Response(res, status = status.HTTP_200_OK)
return Response(res, status = status.HTTP_200_OK)
except FieldDoesNotExist as error :
return Response({
'error' : "FieldDoesNotExist ",
'date' : datetime.now()
}, status = status.HTTP_400_BAD_REQUEST)
except FieldDoesNotExist as error :
return Response({
'error' : "FieldDoesNotExist ",
'date' : datetime.now()
}, status = status.HTTP_400_BAD_REQUEST)
#기기 관련 api
class Device(APIView) :
class Devices(APIView) :
# 기기 목록 조회
def get(self, request, format = None) :
queryset = Device.objects.all()
......@@ -65,17 +66,22 @@ class Device(APIView) :
# 기기 추가
def post(self, request, format = None) : # request body에 rfid_id 포함되어있음 
try :
print('냐냐냐냐냐냐')
print(request.body)
data = json.loads(request.body)
request_id = data.get('rfid_id', None)
if request_id == 'None' :
if request_id == None :
raise FieldDoesNotExist
queryset = Device.objects.create(rfid_id = request_id)
return Response({
'msg' : 'success device add'
})
except FieldDoesNotExist as error :
return Response({
'error' : "FieldDoesNotExist ",
'date' : datetime.now()
}, status = status.HTTP_400_BAD_REQUEST)
return Response({
'error' : "FieldDoesNotExist ",
'date' : datetime.now()
}, status = status.HTTP_400_BAD_REQUEST)
......@@ -83,16 +89,19 @@ class Device(APIView) :
def delete(self, request, device_id, format = None): # request URI에 device_id(자동생성되는 기기 고유 번호 != rfid_id) 포함
try :
request_id = device_id
if request_id == 'None':
raise FieldDoesNotExist
if request_id == None:
raise FieldDoesNotExist
queryset = Device.objects.get(device_id=request_id)
queryset.delete()
return Response({
'msg' : 'success delete device'
})
except FieldDoesNotExist as error :
return Response({
'error' : "FieldDoesNotExist ",
'date' : datetime.now()
}, status = status.HTTP_400_BAD_REQUEST)
return Response({
'error' : "FieldDoesNotExist ",
'date' : datetime.now()
}, status = status.HTTP_400_BAD_REQUEST)
# 원격 잠금 해제
class Remote(APIView):
......
......@@ -25,6 +25,7 @@ urlpatterns = [
path('auto/checkDate', views.CheckDate.as_view()),
path('api/setting', views.Recording.as_view()),
path('api/auth', views.Login.as_view()),
path('api/device', views.Device.as_view()),
path('api/remote', view.Remote.as_view()),
path('api/device', views.Devices.as_view()),
path('api/device/<str:device_id>', views.Devices.as_view()),
path('api/remote', views.Remote.as_view()),
]
......