Добавление взаимодействия с другим сервисом

main
through-your-tears 9 months ago
parent a1ea1c6566
commit a2e6175ee4

@ -6,7 +6,7 @@ services:
build:
context: ./src
dockerfile: Dockerfile
command: gunicorn conf.wsgi:application --bind 0.0.0.0:8000
command: gunicorn conf.wsgi:application --bind 0.0.0.0:8000 --threads 4
volumes:
- static_volume:/home/app/web/static
- media_volume:/home/app/web/media

@ -197,3 +197,5 @@ SESSION_ENGINE = "django.contrib.sessions.backends.cache"
SESSION_CACHE_ALIAS = "default"
CACHE_TTL = 60 * 1
RECOMMEND_BASE_API_URL = 'https://hack3.k-lab.su/'

@ -1,5 +1,8 @@
from django.contrib.gis.geos.point import Point
from django.conf import settings
import requests
from business.repositories import QRCodeUsingRepository
from .repositories import LocationRepository, OrganizationRepository, CategoryRepository
@ -57,3 +60,32 @@ def parse_organizations_to_db(data):
except Exception:
pass
def send_locations_to_recommend_service():
for org in OrganizationRepository.all():
requests.post(url=settings.RECOMMEND_BASE_API_URL, data={
"location_id": org.location.pk,
"category_id": org.category.pk,
"latitude": org.location.coords[0],
"longitude": org.location.coords[1]
})
def get_recommendation(user, now_location):
data = []
for org_id in QRCodeUsingRepository.get_organizations(user).values_list('organization__pk', flat=True):
organization = OrganizationRepository.get(org_id)
data.append({
"location_id": organization.location.pk,
"category_id": organization.category.pk,
"latitude": organization.location.coords[0],
"longitude": organization.location.coords[1]
})
if now_location:
data.append({
"location_id": -1,
"category_id": -1,
"latitude": now_location[0],
"longitude": now_location[1]
})
requests.post(url=settings.RECOMMEND_BASE_API_URL, data=data)

@ -14,7 +14,7 @@ from core.permissions import IsAuthorOrReadOnly
from business.repositories import QRCodeUsingRepository
from .repositories import CategoryRepository, OrganizationRepository
from .serializers import CategorySerializer, OrganizationListSerializer, OrganizationCreateSerializer
from .services import parse_organizations_to_db
from .services import parse_organizations_to_db, send_locations_to_recommend_service, get_recommendation
# Create your views here.
@ -123,6 +123,13 @@ class VisitedOrganizationsListAPIView(ListAPIView):
return QRCodeUsingRepository.get_organizations(self.request.user)
class SendDataToRecommendAPIView(APIView):
def post(self, request):
send_locations_to_recommend_service()
return Response(status=status.HTTP_200_OK)
class UploadAPIView(APIView):
def post(self, request):

Binary file not shown.
Loading…
Cancel
Save