From 180b71c0f0cf91e33008e00b702b79603c5b8d25 Mon Sep 17 00:00:00 2001 From: stepan323446 Date: Fri, 21 Nov 2025 11:50:54 +0100 Subject: [PATCH] Updated migrations, added swagger --- .env.example | 3 +++ project/settings/base.py | 27 +++++++++++++++++++++++++++ project/urls.py | 9 ++++++++- requirements.txt | 16 ++++++++++++++++ weather/migrations/0001_initial.py | 25 +++++++++++++++++++++++++ weather/models.py | 10 +++++++--- weather/urls.py | 0 7 files changed, 86 insertions(+), 4 deletions(-) create mode 100644 .env.example create mode 100644 requirements.txt create mode 100644 weather/migrations/0001_initial.py create mode 100644 weather/urls.py diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a5fbd1a --- /dev/null +++ b/.env.example @@ -0,0 +1,3 @@ +SECRET_KEY= +ENVIRONMENT= +MIKRO_SECRET_KEY= \ No newline at end of file diff --git a/project/settings/base.py b/project/settings/base.py index 0b86cd5..d4fae57 100644 --- a/project/settings/base.py +++ b/project/settings/base.py @@ -40,9 +40,17 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + + 'corsheaders', + 'rest_framework', + 'django_filters', + 'drf_spectacular', + + 'weather.apps.WeatherConfig' ] MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -54,6 +62,25 @@ MIDDLEWARE = [ ROOT_URLCONF = 'project.urls' +SPECTACULAR_SETTINGS = { + 'TITLE': 'Weather Mikro API', + 'DESCRIPTION': 'Weather stats by weather', + 'VERSION': '1.0.0', + 'COMPONENT_SPLIT_REQUEST': True +} + +CORS_ALLOW_ALL_ORIGINS = True + +REST_FRAMEWORK = { + 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', + 'PAGE_SIZE': 20, + 'DEFAULT_AUTHENTICATION_CLASSES': [ + + ], + 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema', + 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'], +} + TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', diff --git a/project/urls.py b/project/urls.py index d1d4e61..aac0d51 100644 --- a/project/urls.py +++ b/project/urls.py @@ -14,9 +14,16 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView + from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('api/schema/', SpectacularAPIView.as_view(), name='schema'), + path('swagger/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), + path('api/', include([ + # path('', include('weather.urls')), + ])), ] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..81fd029 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,16 @@ +asgiref==3.11.0 +attrs==25.4.0 +Django==5.2.8 +django-filter==25.2 +django-rest-framework==0.1.0 +djangorestframework==3.16.1 +drf-spectacular==0.29.0 +inflection==0.5.1 +jsonschema==4.25.1 +jsonschema-specifications==2025.9.1 +python-dotenv==1.2.1 +PyYAML==6.0.3 +referencing==0.37.0 +rpds-py==0.29.0 +sqlparse==0.5.3 +uritemplate==4.2.0 diff --git a/weather/migrations/0001_initial.py b/weather/migrations/0001_initial.py new file mode 100644 index 0000000..b2bb527 --- /dev/null +++ b/weather/migrations/0001_initial.py @@ -0,0 +1,25 @@ +# Generated by Django 5.2.8 on 2025-11-21 10:39 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='WeatherStats', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('humidityAir', models.FloatField(default=0)), + ('humidityGround', models.FloatField(default=0)), + ('temperature', models.FloatField(default=0)), + ('light', models.FloatField(default=0)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ], + ), + ] diff --git a/weather/models.py b/weather/models.py index a5b541f..93ba297 100644 --- a/weather/models.py +++ b/weather/models.py @@ -2,7 +2,11 @@ from django.db import models # Create your models here. class WeatherStats(models.Model): - - humidity = models.FloatField(default=0) + humidityAir = models.FloatField(default=0) + humidityGround = models.FloatField(default=0) temperature = models.FloatField(default=0) - created_at = models.DateTimeField(auto_now_add=True) \ No newline at end of file + light = models.FloatField(default=0) + created_at = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return 'Weather data by ' + self.created_at \ No newline at end of file diff --git a/weather/urls.py b/weather/urls.py new file mode 100644 index 0000000..e69de29