Skip to content

Commit 5607c00

Browse files
author
lruzicki
committed
TECH-717: draft endpoint that always return true added
1 parent b4e7488 commit 5607c00

File tree

16 files changed

+78
-75
lines changed

16 files changed

+78
-75
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__/
2+
*.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

govstack_test_harness_api/building_blocks/bb-digital-registries/services.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.urls import path
2+
from .views import getDataFromSubFolder, get_registry_data
3+
4+
urlpatterns = [
5+
path('bbdr/', getDataFromSubFolder, name='digital_registries'),
6+
path('data/<str:registryname>/<str:versionnumber>/', get_registry_data, name='data_registry'),
7+
]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from rest_framework.decorators import api_view
2+
from rest_framework.views import APIView
3+
from rest_framework.response import Response
4+
from django.http import JsonResponse
5+
from django.views.decorators.csrf import csrf_exempt
6+
from django.core.paginator import Paginator
7+
from rest_framework.decorators import api_view
8+
9+
@api_view(['GET'])
10+
def getDataFromSubFolder(request):
11+
person = {'registry':'John', 'ID':'7312'}
12+
return Response(person)
13+
14+
15+
@api_view(['GET'])
16+
@csrf_exempt
17+
def get_registry_data(request, registryname, versionnumber):
18+
# Extract query parameters
19+
search = request.GET.get('search')
20+
filter = request.GET.get('filter')
21+
ordering = request.GET.get('ordering')
22+
page = request.GET.get('page', 1)
23+
page_size = request.GET.get('page_size', 10)
24+
query_fieldname = request.GET.get('query.<fieldname>')
25+
26+
# Logic to retrieve data from your database and filter/order as required
27+
# For demonstration purposes, let's say you have created a list named 'data'
28+
data = [...] # replace this with your logic to fetch data from the database
29+
30+
# Apply pagination
31+
paginator = Paginator(data, page_size)
32+
current_page = paginator.get_page(page)
33+
34+
# Construct the response
35+
response = {
36+
"count": paginator.count,
37+
"next": None if not current_page.has_next() else f"?page={current_page.next_page_number()}",
38+
"previous": None if not current_page.has_previous() else f"?page={current_page.previous_page_number()}",
39+
"results": list(current_page)
40+
}
41+
42+
return Response({
43+
"count": 1,
44+
"next": "1",
45+
"previous": "",
46+
"results": [
47+
{
48+
"ID": "EE378627348834",
49+
"FirstName": "John Helmut",
50+
"LastName": "Smith Carry",
51+
"BirthCertificateID": "RR-1234567889"
52+
}
53+
]
54+
})

govstack_test_harness_api/urls.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
urlpatterns = []
1+
from django.urls import path, include
2+
from . import views
3+
4+
urlpatterns = [
5+
path('', include('govstack_test_harness_api.building_blocks.bb-digital-registries.urls')),
6+
]

govstack_test_harness_api/views.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
from django.shortcuts import render
22

33
# Create your views here.
4+
5+
from rest_framework.response import Response
6+
from rest_framework.decorators import api_view
7+
8+
@api_view(['GET'])
9+
def getData(request):
10+
person = {'name':'Lucas', 'age':'28'}
11+
return Response(person)

0 commit comments

Comments
 (0)