fix write times
This commit is contained in:
3
API.md
3
API.md
@@ -20,4 +20,5 @@ zapisuje cas ako end.
|
||||
**Example Request:**
|
||||
|
||||
```bash
|
||||
curl -X GET "http://your-domain/api/timer/write/12345/222-222-222-222/1741169316.149847/"
|
||||
curl -X GET "http://your-domain/api/timer/write/12345/222-222-222-222/1741169316.149847/"
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
from django.urls import path
|
||||
|
||||
from timer.views import WriteTimeApiView
|
||||
from timer.views import WriteTimeApiView, HealthCheckApiView
|
||||
|
||||
urlpatterns = [
|
||||
path(
|
||||
"healthcheck/",
|
||||
HealthCheckApiView.as_view(),
|
||||
name="healthcheck",
|
||||
),
|
||||
|
||||
path(
|
||||
"write/<str:timer_id>/<str:chip_id>/<str:time>/",
|
||||
WriteTimeApiView.as_view(),
|
||||
name="write_time",
|
||||
),
|
||||
|
||||
|
||||
|
||||
]
|
||||
@@ -1,7 +1,7 @@
|
||||
import http
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
from django.utils import timezone
|
||||
from django.views.generic import View
|
||||
from django.http import JsonResponse
|
||||
|
||||
@@ -12,6 +12,16 @@ logger = logging.getLogger(__name__)
|
||||
from timer.models import TimeRecord
|
||||
|
||||
|
||||
class HealthCheckApiView(View):
|
||||
"""
|
||||
View to check if the server is running
|
||||
returns standard JsonResponse with status 'ok'
|
||||
"""
|
||||
@staticmethod
|
||||
def get(request, *args, **kwargs):
|
||||
return JsonResponse({"status": "ok"}, status=http.HTTPStatus.OK, safe=False)
|
||||
|
||||
|
||||
class WriteTimeApiView(View):
|
||||
"""
|
||||
View to write time records
|
||||
@@ -23,7 +33,7 @@ class WriteTimeApiView(View):
|
||||
try:
|
||||
|
||||
# parse datetime from string of unix timestamp with milliseconds '1741169756.049847'
|
||||
record_time = datetime.fromtimestamp(float(kwargs['time']))
|
||||
record_time = timezone.make_aware(datetime.fromtimestamp(float(kwargs['time'])))
|
||||
|
||||
# create new TimeRecord object and save it to the database
|
||||
TimeRecord(
|
||||
|
||||
Reference in New Issue
Block a user