Reoraganized project
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class ApiConfig(AppConfig):
|
||||||
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
|
name = "api"
|
||||||
@@ -3,4 +3,4 @@ from django.apps import AppConfig
|
|||||||
|
|
||||||
class CountriesConfig(AppConfig):
|
class CountriesConfig(AppConfig):
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = "countries"
|
name = "api.countries"
|
||||||
@@ -9,6 +9,7 @@ class Country(models.Model):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
db_table = "countries"
|
db_table = "countries"
|
||||||
|
managed = False
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from countries.models import Country
|
from api.countries.models import Country
|
||||||
|
|
||||||
|
|
||||||
class CountrySerializer(serializers.ModelSerializer):
|
class CountrySerializer(serializers.ModelSerializer):
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
import api.countries.views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("", api.countries.views.CountryListView.as_view(), name="countries"),
|
||||||
|
path(
|
||||||
|
"/<str:alpha2>",
|
||||||
|
api.countries.views.CountryByAlpha2View.as_view(),
|
||||||
|
name="country_by_alpha2",
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -2,8 +2,8 @@ from django.conf import settings
|
|||||||
from rest_framework.exceptions import ValidationError
|
from rest_framework.exceptions import ValidationError
|
||||||
from rest_framework.generics import ListAPIView, RetrieveAPIView
|
from rest_framework.generics import ListAPIView, RetrieveAPIView
|
||||||
|
|
||||||
from countries.models import Country
|
from api.countries.models import Country
|
||||||
from countries.serializers import CountrySerializer
|
from api.countries.serializers import CountrySerializer
|
||||||
|
|
||||||
|
|
||||||
class CountryListView(ListAPIView):
|
class CountryListView(ListAPIView):
|
||||||
@@ -3,4 +3,4 @@ from django.apps import AppConfig
|
|||||||
|
|
||||||
class PingConfig(AppConfig):
|
class PingConfig(AppConfig):
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = "ping"
|
name = "api.ping"
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
import api.ping.views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("", api.ping.views.PingView.as_view(), name="ping"),
|
||||||
|
]
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from django.urls import include, path
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("ping", include("api.ping.urls")),
|
||||||
|
path("countries", include("api.countries.urls")),
|
||||||
|
path("", include("api.users.urls")),
|
||||||
|
]
|
||||||
@@ -3,4 +3,4 @@ from django.apps import AppConfig
|
|||||||
|
|
||||||
class UsersConfig(AppConfig):
|
class UsersConfig(AppConfig):
|
||||||
default_auto_field = "django.db.models.BigAutoField"
|
default_auto_field = "django.db.models.BigAutoField"
|
||||||
name = "users"
|
name = "api.users"
|
||||||
@@ -6,7 +6,7 @@ from rest_framework.authentication import (
|
|||||||
from rest_framework.exceptions import AuthenticationFailed, NotAuthenticated
|
from rest_framework.exceptions import AuthenticationFailed, NotAuthenticated
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
|
|
||||||
from users.models import Profile
|
from api.users.models import Profile
|
||||||
|
|
||||||
|
|
||||||
class JWTAuthentication(BaseAuthentication):
|
class JWTAuthentication(BaseAuthentication):
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
# Generated by Django 4.2.10 on 2024-03-02 09:47
|
# Generated by Django 4.2.10 on 2024-03-02 10:14
|
||||||
|
|
||||||
|
import api.users.validators
|
||||||
import django.core.validators
|
import django.core.validators
|
||||||
from django.db import migrations, models
|
from django.db import migrations, models
|
||||||
import users.validators
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
@@ -20,7 +20,7 @@ class Migration(migrations.Migration):
|
|||||||
('login', models.CharField(max_length=30, validators=[django.core.validators.RegexValidator('^[a-zA-Z0-9-]+$')])),
|
('login', models.CharField(max_length=30, validators=[django.core.validators.RegexValidator('^[a-zA-Z0-9-]+$')])),
|
||||||
('email', models.EmailField(max_length=50)),
|
('email', models.EmailField(max_length=50)),
|
||||||
('password', models.CharField(max_length=100, validators=[django.core.validators.RegexValidator('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{6,100}$')])),
|
('password', models.CharField(max_length=100, validators=[django.core.validators.RegexValidator('^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{6,100}$')])),
|
||||||
('countryCode', models.CharField(max_length=2, validators=[django.core.validators.RegexValidator('[a-zA-Z]{2}'), users.validators.CountryCodeValidator()])),
|
('countryCode', models.CharField(max_length=2, validators=[django.core.validators.RegexValidator('[a-zA-Z]{2}'), api.users.validators.CountryCodeValidator()])),
|
||||||
('isPublic', models.BooleanField()),
|
('isPublic', models.BooleanField()),
|
||||||
('phone', models.CharField(blank=True, max_length=20, null=True, validators=[django.core.validators.MaxLengthValidator(20), django.core.validators.RegexValidator('\\+[\\d]+')])),
|
('phone', models.CharField(blank=True, max_length=20, null=True, validators=[django.core.validators.MaxLengthValidator(20), django.core.validators.RegexValidator('\\+[\\d]+')])),
|
||||||
('image', models.URLField(blank=True, null=True)),
|
('image', models.URLField(blank=True, null=True)),
|
||||||
@@ -4,7 +4,7 @@ from django.core.validators import (
|
|||||||
)
|
)
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from users.validators import CountryCodeValidator
|
from api.users.validators import CountryCodeValidator
|
||||||
|
|
||||||
|
|
||||||
class Profile(models.Model):
|
class Profile(models.Model):
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from users.models import Profile
|
from api.users.models import Profile
|
||||||
|
|
||||||
|
|
||||||
class ProfileSerializer(serializers.ModelSerializer):
|
class ProfileSerializer(serializers.ModelSerializer):
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
import users.views
|
import api.users.views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path(
|
path(
|
||||||
"auth/register",
|
"auth/register",
|
||||||
users.views.RegisterUserApiView.as_view(),
|
api.users.views.RegisterUserApiView.as_view(),
|
||||||
name="register",
|
name="register",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"auth/sign-in",
|
"auth/sign-in",
|
||||||
users.views.SigninUserApiView.as_view(),
|
api.users.views.SigninUserApiView.as_view(),
|
||||||
name="sign-in",
|
name="sign-in",
|
||||||
),
|
),
|
||||||
path(
|
path(
|
||||||
"me/profile",
|
"me/profile",
|
||||||
users.views.ProfileMeApiView.as_view(),
|
api.users.views.ProfileMeApiView.as_view(),
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
from countries.models import Country
|
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import BaseValidator
|
from django.core.validators import BaseValidator
|
||||||
from django.utils.deconstruct import deconstructible
|
from django.utils.deconstruct import deconstructible
|
||||||
|
|
||||||
|
from api.countries.models import Country
|
||||||
|
|
||||||
|
|
||||||
@deconstructible
|
@deconstructible
|
||||||
class CountryCodeValidator(BaseValidator):
|
class CountryCodeValidator(BaseValidator):
|
||||||
@@ -9,8 +9,8 @@ from rest_framework.permissions import IsAuthenticated
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from users.models import Profile
|
from api.users.models import Profile
|
||||||
from users.serializers import ProfileSerializer, UpdateProfileSerializer
|
from api.users.serializers import ProfileSerializer, UpdateProfileSerializer
|
||||||
|
|
||||||
|
|
||||||
class RegisterUserApiView(APIView):
|
class RegisterUserApiView(APIView):
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
from django.urls import path
|
|
||||||
|
|
||||||
import countries.views
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path("", countries.views.CountryListView.as_view(), name="countries"),
|
|
||||||
path(
|
|
||||||
"/<str:alpha2>",
|
|
||||||
countries.views.CountryByAlpha2View.as_view(),
|
|
||||||
name="country_by_alpha2",
|
|
||||||
),
|
|
||||||
]
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
from django.urls import path
|
|
||||||
|
|
||||||
import ping.views
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
path("", ping.views.PingView.as_view(), name="ping"),
|
|
||||||
]
|
|
||||||
@@ -26,9 +26,9 @@ INSTALLED_APPS = [
|
|||||||
"rest_framework",
|
"rest_framework",
|
||||||
"django_filters",
|
"django_filters",
|
||||||
# Developed apps
|
# Developed apps
|
||||||
"ping.apps.PingConfig",
|
"api.ping.apps.PingConfig",
|
||||||
"countries.apps.CountriesConfig",
|
"api.countries.apps.CountriesConfig",
|
||||||
"users.apps.UsersConfig",
|
"api.users.apps.UsersConfig",
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@@ -116,7 +116,7 @@ REST_FRAMEWORK = {
|
|||||||
"django_filters.rest_framework.DjangoFilterBackend"
|
"django_filters.rest_framework.DjangoFilterBackend"
|
||||||
],
|
],
|
||||||
"DEFAULT_AUTHENTICATION_CLASSES": (
|
"DEFAULT_AUTHENTICATION_CLASSES": (
|
||||||
"users.authentication.JWTAuthentication",
|
"api.users.authentication.JWTAuthentication",
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ urlpatterns = [
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
# API
|
# API
|
||||||
path("api/ping", include("ping.urls")),
|
path("api/", include("api.urls")),
|
||||||
path("api/countries", include("countries.urls")),
|
|
||||||
path("api/", include("users.urls")),
|
|
||||||
]
|
]
|
||||||
|
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
|
|||||||
Reference in New Issue
Block a user