bx-865-apps #1
|
@ -1678,6 +1678,14 @@
|
|||
"detail": "rest_framework",
|
||||
"documentation": {}
|
||||
},
|
||||
{
|
||||
"label": "status",
|
||||
"importPath": "rest_framework",
|
||||
"description": "rest_framework",
|
||||
"isExtraImport": true,
|
||||
"detail": "rest_framework",
|
||||
"documentation": {}
|
||||
},
|
||||
{
|
||||
"label": "TestCase",
|
||||
"importPath": "django.test",
|
||||
|
@ -1745,6 +1753,14 @@
|
|||
"detail": "django.http",
|
||||
"documentation": {}
|
||||
},
|
||||
{
|
||||
"label": "get_object_or_404",
|
||||
"importPath": "django.shortcuts",
|
||||
"description": "django.shortcuts",
|
||||
"isExtraImport": true,
|
||||
"detail": "django.shortcuts",
|
||||
"documentation": {}
|
||||
},
|
||||
{
|
||||
"label": "parse_image",
|
||||
"importPath": "api.tracer",
|
||||
|
@ -8516,7 +8532,7 @@
|
|||
"kind": 6,
|
||||
"importPath": "back.api.views",
|
||||
"description": "back.api.views",
|
||||
"peekOfCode": "class FloorplanPointsView(APIView):\n def get(self, request, id):\n if FloorplanPoints.objects.filter(plan=id).exists():\n points = FloorplanPoints.objects.get(plan=id)\n serializer = FloorplanPointsSerializer(points, many=False)\n return JsonResponse(serializer.data, safe=False)\n else:\n return JsonResponse(\"No item\", status=400)\n def post(self, request, id):\n data = JSONParser().parse(request)",
|
||||
"peekOfCode": "class FloorplanPointsView(APIView):\n def get(self, request, id):\n if FloorplanPoints.objects.filter(plan=id).exists():\n points = FloorplanPoints.objects.get(plan=id)\n serializer = FloorplanPointsSerializer(points, many=False)\n return JsonResponse(serializer.data, safe=False)\n else:\n return JsonResponse(\n \"No item\", safe=False, status=status.HTTP_400_BAD_REQUEST\n )",
|
||||
"detail": "back.api.views",
|
||||
"documentation": {}
|
||||
},
|
||||
|
|
|
@ -87,7 +87,7 @@ const sampling_data = async () => {
|
|||
.attr('class', _class)
|
||||
.on('click', clickFunk)
|
||||
}
|
||||
if (i % 10 == 0) {
|
||||
if (i % 200 == 0) {
|
||||
await nextFrame()
|
||||
}
|
||||
};
|
||||
|
|
|
@ -34,11 +34,16 @@ const dataToState = async (data: any) => {
|
|||
|
||||
try {
|
||||
const res = await fetch(`${config.public.apiBase}/api/floorplan/${data.id}/points`)
|
||||
if (res.status !== 200) {
|
||||
throw new Error()
|
||||
}
|
||||
const points = await res.json()
|
||||
target_points.value = points.points
|
||||
target_array.value = points.points
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
target_points.value = []
|
||||
target_array.value = []
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +59,9 @@ const selectFileEvent = async () => {
|
|||
loadingFile.value = true
|
||||
try {
|
||||
const res = await fetch(`${config.public.apiBase}/api/floorplan/${selectFile.value}`)
|
||||
if (res.status !== 200) {
|
||||
throw new Error()
|
||||
}
|
||||
const data = await res.json()
|
||||
await dataToState(data)
|
||||
} catch (error) {
|
||||
|
@ -66,6 +74,9 @@ const loadFiles = async () => {
|
|||
try {
|
||||
loadingFile.value = true
|
||||
const res = await fetch(`${config.public.apiBase}/api/floorplan/`)
|
||||
if (res.status !== 200) {
|
||||
throw new Error()
|
||||
}
|
||||
const data = await res.json()
|
||||
files.value = data
|
||||
} catch (error) {
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import json
|
||||
from rest_framework.parsers import JSONParser, MultiPartParser
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import status
|
||||
|
||||
from django.http import JsonResponse
|
||||
from django.shortcuts import get_object_or_404
|
||||
|
||||
from api.tracer import parse_image, read_image, numpy_zip_str_to_arr
|
||||
|
||||
from .serializers import (
|
||||
FloorplanListSerializer,
|
||||
FloorplanPointsSerializer,
|
||||
|
@ -66,7 +70,7 @@ class FloorplanView(APIView):
|
|||
)
|
||||
else:
|
||||
logger.info(serializer.errors)
|
||||
return JsonResponse(serializer.errors, status=500)
|
||||
return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
raise e
|
||||
|
@ -94,11 +98,14 @@ class FloorplanView(APIView):
|
|||
serializer = FloorplanSerializer(item, data=request.data, partial=True)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return JsonResponse(serializer.data, status=201)
|
||||
return JsonResponse(serializer.data, status=status.HTTP_200_OK)
|
||||
else:
|
||||
logger.info(serializer.errors)
|
||||
return JsonResponse(
|
||||
serializer.errors, status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
else:
|
||||
return JsonResponse("No item", status=400)
|
||||
return JsonResponse("No item", status=status.HTTP_400_BAD_REQUEST)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
raise e
|
||||
|
@ -111,12 +118,17 @@ class FloorplanPointsView(APIView):
|
|||
serializer = FloorplanPointsSerializer(points, many=False)
|
||||
return JsonResponse(serializer.data, safe=False)
|
||||
else:
|
||||
return JsonResponse("No item", status=400)
|
||||
return JsonResponse(
|
||||
"No item", safe=False, status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
|
||||
def post(self, request, id):
|
||||
data = JSONParser().parse(request)
|
||||
data["plan"] = id
|
||||
serializer = FloorplanPointsSerializer(data=data)
|
||||
floorplapoints_object = get_object_or_404(FloorplanPoints, plan=id)
|
||||
serializer = FloorplanPointsSerializer(floorplapoints_object, data=data, partial=True)
|
||||
if serializer.is_valid():
|
||||
serializer.save()
|
||||
return JsonResponse(serializer.data, status=201)
|
||||
return JsonResponse(serializer.data, status=status.HTTP_201_CREATED)
|
||||
else:
|
||||
return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
|
Loading…
Reference in New Issue