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