update backend API, update structure dir react-app
This commit is contained in:
parent
c7d15b1943
commit
097778e426
|
@ -1,9 +1,9 @@
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
from rest_framework.urlpatterns import format_suffix_patterns
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
app_name="pairent_app"
|
urlpatterns = format_suffix_patterns([
|
||||||
|
path("apartaments/", views.ApartamentViewSet.as_view({'get': 'list'})),
|
||||||
urlpatterns = [
|
path("apartament/<int:pk>/", views.ApartamentViewSet.as_view({'get': 'retrieve'})),
|
||||||
path('', views.ApartamentListView.as_view(), name="ApartamentList"),
|
])
|
||||||
path('apartament/<int:id>', views.ApartamentDetailView.as_view(), name='ApartamentDetail'),
|
|
||||||
]
|
|
||||||
|
|
|
@ -1,24 +1,19 @@
|
||||||
from rest_framework.views import APIView
|
from rest_framework import viewsets
|
||||||
from rest_framework.response import Response
|
|
||||||
|
|
||||||
from .models import Apartament
|
from .models import Apartament
|
||||||
from .serializer import ApartamentListSerializer, ApartamentDetailSerializer
|
from .serializer import (ApartamentListSerializer,
|
||||||
|
ApartamentDetailSerializer)
|
||||||
|
|
||||||
|
|
||||||
class ApartamentListView(APIView):
|
class ApartamentViewSet(viewsets.ReadOnlyModelViewSet):
|
||||||
"""Вывод списка квартир"""
|
"""Вывод списка квартир или отдельной квартиры"""
|
||||||
|
|
||||||
def get(self, request):
|
def get_queryset(self):
|
||||||
apartaments = Apartament.objects.all()
|
apartaments = Apartament.objects.all()
|
||||||
headers = {'total-count': len(apartaments)}
|
return apartaments
|
||||||
serializer = ApartamentListSerializer(apartaments, many=True)
|
|
||||||
return Response(serializer.data, headers=headers)
|
|
||||||
|
|
||||||
|
def get_serializer_class(self):
|
||||||
class ApartamentDetailView(APIView):
|
if self.action == 'list':
|
||||||
"""Вывод квартиры"""
|
return ApartamentListSerializer
|
||||||
|
elif self.action == "retrieve":
|
||||||
def get(self, request, id):
|
return ApartamentDetailSerializer
|
||||||
apartament = Apartament.objects.get(id=id)
|
|
||||||
serializer = ApartamentDetailSerializer(apartament)
|
|
||||||
return Response(serializer.data)
|
|
|
@ -37,9 +37,11 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'pairent_app',
|
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'corsheaders',
|
'corsheaders',
|
||||||
|
|
||||||
|
'pairent_app',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
@ -53,12 +55,16 @@ MIDDLEWARE = [
|
||||||
'corsheaders.middleware.CorsMiddleware',
|
'corsheaders.middleware.CorsMiddleware',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# Настройка REST FRAMEWORK
|
||||||
REST_FRAMEWORK = {
|
REST_FRAMEWORK = {
|
||||||
'DEFAULT_PERMISSION_CLASSES' : [
|
'DEFAULT_PERMISSION_CLASSES' : [
|
||||||
'rest_framework.permissions.AllowAny'
|
'rest_framework.permissions.AllowAny'
|
||||||
]
|
],
|
||||||
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
|
||||||
|
'PAGE_SIZE': 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Настройка отвечающая, что все могут отправлять запрос на бекенд. УБРАТЬ ПРИ ПРОДАКШЕНЕ!
|
||||||
CORS_ORIGIN_ALLOW_ALL = True
|
CORS_ORIGIN_ALLOW_ALL = True
|
||||||
|
|
||||||
ROOT_URLCONF = 'pairent_backend.urls'
|
ROOT_URLCONF = 'pairent_backend.urls'
|
||||||
|
|
|
@ -18,5 +18,5 @@ from django.urls import path, include
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('', include('pairent_app.urls', namespace='pairent_app')),
|
path('api/', include('pairent_app.urls')),
|
||||||
]
|
]
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@500;600;700&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@500;600;700&display=swap" rel="stylesheet">
|
||||||
</head>
|
</head>
|
||||||
<body id="root">
|
<body>
|
||||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root">
|
||||||
|
<!-- this to content -->
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Header from './components/Header/Header';
|
import Header from './components/header/Header';
|
||||||
import Footer from './components/Footer/Footer';
|
import Footer from './components/footer/Footer';
|
||||||
import './main.css';
|
import './App.css';
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue