Toggle navigation
Toggle navigation
This project
Loading...
Sign in
cse437_e
/
smartdoorlock-backend
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
dahee kim
2020-11-16 21:15:13 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a6e4b67f13df0899d7a9a4b446e5100e1f608112
a6e4b67f
1 parent
8de6d4a8
change endpoint of device api
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
16 deletions
api/models.py
api/views.py
api/models.py
View file @
a6e4b67
...
...
@@ -7,7 +7,7 @@ class Door(models.Model) :
door_id
=
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
)
class
Device
(
models
.
Model
)
:
rfid
_id
=
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
)
device
_id
=
models
.
CharField
(
max_length
=
255
,
primary_key
=
True
)
created
=
models
.
DateTimeField
(
default
=
timezone
.
now
)
class
Video
(
models
.
Model
)
:
...
...
api/views.py
View file @
a6e4b67
...
...
@@ -52,10 +52,21 @@ class Login(APIView) :
#기기 관련 api
class
Device
(
APIView
)
:
# 기기 목록 조회
def
get
(
self
,
request
,
format
=
None
)
:
queryset
=
Device
.
objects
.
all
()
serializer
=
DeviceSerializer
(
queryset
,
many
=
True
)
res
=
{
'deviceList'
:
serializer
.
data
}
return
Response
(
res
,
status
=
status
.
HTTP_200_OK
)
# 기기 추가
def
post
(
self
,
request
,
format
=
None
)
:
# request
query에 device_id 포함되어있음 : api/device?device_id=12345
def
post
(
self
,
request
,
format
=
None
)
:
# request
body에 device_id 포함되어있음
try
:
request_id
=
request
.
POST
.
get
(
'device_id'
,
None
)
data
=
json
.
loads
(
request
.
body
)
request_id
=
data
.
get
(
'device_id'
,
None
)
if
request_id
==
'None'
:
raise
FieldDoesNotExist
queryset
=
Device
.
objects
.
create
(
rfid_id
=
request_id
)
...
...
@@ -66,19 +77,13 @@ class Device(APIView) :
'date'
:
datetime
.
now
()
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
# 기기 목록 조회
def
get
(
self
,
request
,
format
=
None
)
:
queryset
=
Device
.
objects
.
all
()
serializer
=
DeviceSerializer
(
queryset
,
many
=
True
)
res
=
{
'deviceList'
:
serializer
.
data
}
return
Response
(
res
,
status
=
status
.
HTTP_200_OK
)
# 기기 삭제
def
delete
(
self
,
request
,
device_id
,
format
=
None
):
# request URI
에 device_id 포함
def
delete
(
self
,
request
,
format
=
None
):
# request body
에 device_id 포함
try
:
request_id
=
device_id
data
=
json
.
loads
(
request
.
body
)
request_id
=
data
.
get
(
'device_id'
,
None
)
if
request_id
==
'None'
:
raise
FieldDoesNotExist
queryset
=
Device
.
objects
.
get
(
device_id
=
request_id
)
...
...
@@ -90,16 +95,21 @@ class Device(APIView) :
'date'
:
datetime
.
now
()
},
status
=
status
.
HTTP_400_BAD_REQUEST
)
# 원격 잠금 해제 기록 조회
class
History
(
APIView
):
# 원격 잠금 해제
class
Remote
(
APIView
):
# 원격 잠금 해제 기록 조회
def
get
(
self
,
request
,
format
=
None
)
:
#models.py의 class History 사용.
queryset
=
History
.
objects
.
all
()
serializer
=
HistorySerializer
(
queryset
,
many
=
True
)
res
=
{
'deviceList'
:
serializer
.
data
"remoteHistoryList"
:
serializer
.
data
}
return
Response
(
res
,
status
=
status
.
HTTP_200_OK
)
# 비디오 목록 조회
class
VideoList
(
APIView
)
:
def
get
(
self
,
request
,
format
=
None
)
:
...
...
Please
register
or
login
to post a comment