Skip to content

Commit

Permalink
Merge pull request #53 from AgriWiseGP/nearest-lab
Browse files Browse the repository at this point in the history
nearest nursery location endpoint
  • Loading branch information
shroukhegazi committed May 26, 2023
2 parents b04871e + 5e79c7b commit 18bfabb
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
7 changes: 6 additions & 1 deletion agriwise/nearest_lab/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from django.contrib import admin

from .models import Location
from .models import Location, NurersuryLocation


@admin.register(Location)
class LocationAdmin(admin.ModelAdmin):
list_display = ["name", "long", "lat"]


@admin.register(NurersuryLocation)
class NurersuryLocationAdmin(admin.ModelAdmin):
list_display = ["name", "long", "lat"]
22 changes: 22 additions & 0 deletions agriwise/nearest_lab/migrations/0002_nurersurylocation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.0.8 on 2023-05-26 15:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nearest_lab', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='NurersuryLocation',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=600)),
('long', models.FloatField()),
('lat', models.FloatField()),
],
),
]
6 changes: 6 additions & 0 deletions agriwise/nearest_lab/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ class Location(models.Model):
name = CharField(max_length=600)
long = FloatField()
lat = FloatField()


class NurersuryLocation(models.Model):
name = CharField(max_length=600)
long = FloatField()
lat = FloatField()
8 changes: 7 additions & 1 deletion agriwise/nearest_lab/serializers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from rest_framework import serializers

from .models import Location
from .models import Location, NurersuryLocation


class LocationSerializer(serializers.ModelSerializer):
class Meta:
model = Location
fields = "__all__"


class NurersuryLocationSerializer(serializers.ModelSerializer):
class Meta:
model = NurersuryLocation
fields = "__all__"
11 changes: 8 additions & 3 deletions agriwise/nearest_lab/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from django.urls import path

from .views import LocationList
from .views import NurseryLocationList, SupplierLocationList

urlpatterns = [
path(
"locations/",
LocationList.as_view(),
"supplier/",
SupplierLocationList.as_view(),
name="nearest_suppliers_list",
),
path(
"nursery/",
NurseryLocationList.as_view(),
name="nearest_nursery_list",
),
]
19 changes: 13 additions & 6 deletions agriwise/nearest_lab/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from .models import Location
from .serializers import LocationSerializer
from .models import Location, NurersuryLocation
from .serializers import LocationSerializer, NurersuryLocationSerializer


class LocationList(APIView):
def get(self, request, *args, **kwargs):
locations = Location.objects.all()
serializer = LocationSerializer(locations, many=True)
class SupplierLocationList(APIView):
def post(self, request):
queryset = Location.objects.all()
serializer = LocationSerializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)


class NurseryLocationList(APIView):
def post(self, request):
queryset = NurersuryLocation.objects.all()
serializer = NurersuryLocationSerializer(queryset, many=True)
return Response(serializer.data, status=status.HTTP_200_OK)
2 changes: 1 addition & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
include("agriwise.agriculture_specialist.admin_urls"),
),
path("plant-diseases/", include("agriwise.plant_diseases.urls")),
path("nearest-suppliers/", include("agriwise.nearest_lab.urls")),
path("nearest/", include("agriwise.nearest_lab.urls")),
]

if settings.DEBUG:
Expand Down

0 comments on commit 18bfabb

Please sign in to comment.