From edbcf7f678f12780ef4d17452c8d5a25b90b7649 Mon Sep 17 00:00:00 2001 From: Samuel Poirier Date: Sat, 23 Mar 2024 09:55:56 -0400 Subject: [PATCH 1/2] Add missing default .env file Remove console log --- canopeum_frontend/.env | 1 + canopeum_frontend/src/services/api.ts | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 canopeum_frontend/.env diff --git a/canopeum_frontend/.env b/canopeum_frontend/.env new file mode 100644 index 000000000..0b704eacd --- /dev/null +++ b/canopeum_frontend/.env @@ -0,0 +1 @@ +VITE_API_URL="http://localhost:3000" diff --git a/canopeum_frontend/src/services/api.ts b/canopeum_frontend/src/services/api.ts index 0a8625ea1..0d26a9833 100644 --- a/canopeum_frontend/src/services/api.ts +++ b/canopeum_frontend/src/services/api.ts @@ -43,7 +43,6 @@ export class BatchClient { if (status === 200) { return response.text().then((_responseText) => { let result200: any = null; - console.log(_responseText); let resultData200 = _responseText === "" ? null : JSON.parse(_responseText); if (Array.isArray(resultData200)) { result200 = [] as any; From 0e4d0c62cddd8dba902ff0aa865ae2e565268e97 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 23 Mar 2024 14:00:12 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .vscode/launch.json | 2 +- canopeum_backend/canopeum_backend/models.py | 14 +- .../canopeum_backend/serializers.py | 158 +++++++++++++----- canopeum_backend/canopeum_backend/settings.py | 6 +- canopeum_backend/canopeum_backend/urls.py | 86 +++++----- canopeum_backend/canopeum_backend/views.py | 61 +++++-- canopeum_frontend/.vite/deps/_metadata.json | 2 +- 7 files changed, 221 insertions(+), 108 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 0e378bb1d..7db7358d2 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -20,4 +20,4 @@ "console": "integratedTerminal" } ] -} \ No newline at end of file +} diff --git a/canopeum_backend/canopeum_backend/models.py b/canopeum_backend/canopeum_backend/models.py index 26071df3f..38f58cbe6 100644 --- a/canopeum_backend/canopeum_backend/models.py +++ b/canopeum_backend/canopeum_backend/models.py @@ -30,17 +30,20 @@ class Batchmulchlayer(models.Model): class BatchSpecies(models.Model): batch = models.ForeignKey(Batch, models.DO_NOTHING, blank=True, null=True) - tree_type = models.ForeignKey('Treetype', models.DO_NOTHING, blank=True, null=True) + tree_type = models.ForeignKey("Treetype", models.DO_NOTHING, blank=True, null=True) quantity = models.IntegerField(blank=True, null=True) + class BatchSeed(models.Model): batch = models.ForeignKey(Batch, models.DO_NOTHING, blank=True, null=True) - tree_type = models.ForeignKey('Treetype', models.DO_NOTHING, blank=True, null=True) + tree_type = models.ForeignKey("Treetype", models.DO_NOTHING, blank=True, null=True) quantity = models.IntegerField(blank=True, null=True) + class BatchSupportedSpecies(models.Model): batch = models.ForeignKey(Batch, models.DO_NOTHING, blank=True, null=True) - tree_type = models.ForeignKey('Treetype', models.DO_NOTHING, blank=True, null=True) + tree_type = models.ForeignKey("Treetype", models.DO_NOTHING, blank=True, null=True) + class Comment(models.Model): body = models.TextField(blank=True, null=True) @@ -160,6 +163,7 @@ class Like(models.Model): auth_user = models.ForeignKey(settings.AUTH_USER_MODEL, models.DO_NOTHING, blank=True, null=True) post = models.ForeignKey(Post, models.DO_NOTHING, blank=True, null=True) + class Internationalization(models.Model): - en = models.TextField(db_column='EN', blank=True, null=True) - fr = models.TextField(db_column='FR', blank=True, null=True) + en = models.TextField(db_column="EN", blank=True, null=True) + fr = models.TextField(db_column="FR", blank=True, null=True) diff --git a/canopeum_backend/canopeum_backend/serializers.py b/canopeum_backend/canopeum_backend/serializers.py index 9f22862c7..303bb58c0 100644 --- a/canopeum_backend/canopeum_backend/serializers.py +++ b/canopeum_backend/canopeum_backend/serializers.py @@ -1,6 +1,27 @@ from django.contrib.auth.models import User from rest_framework import serializers -from .models import BatchSeed, BatchSpecies, BatchSupportedSpecies, Batchfertilizer, Contact, Coordinate, Internationalization, Mulchlayertype, Site, Post, Batch, Announcement, Like, Comment, Sitetreespecies, Sitetype, SitetypeInternationalization, Treetype, Widget + +from .models import ( + Announcement, + Batch, + Batchfertilizer, + BatchSeed, + BatchSpecies, + BatchSupportedSpecies, + Comment, + Contact, + Coordinate, + Internationalization, + Like, + Mulchlayertype, + Post, + Site, + Sitetreespecies, + Sitetype, + Treetype, + Widget, +) + class AuthUserSerializer(serializers.ModelSerializer): class Meta: @@ -17,17 +38,20 @@ class Meta: class CoordinatesSerializer(serializers.ModelSerializer): class Meta: model = Coordinate - fields = '__all__' + fields = "__all__" + class WidgetSerializer(serializers.ModelSerializer): class Meta: model = Widget - fields = '__all__' + fields = "__all__" + class InternationalizationSerializer(serializers.ModelSerializer): class Meta: model = Internationalization - fields = ('en', 'fr') + fields = ("en", "fr") + class SiteTypeSerializer(serializers.ModelSerializer): en = serializers.SerializerMethodField() @@ -35,49 +59,56 @@ class SiteTypeSerializer(serializers.ModelSerializer): class Meta: model = Sitetype - fields = ['id', 'en', 'fr'] + fields = ["id", "en", "fr"] def get_en(self, obj): - return InternationalizationSerializer(obj.name).data.get('en', None) + return InternationalizationSerializer(obj.name).data.get("en", None) def get_fr(self, obj): - return InternationalizationSerializer(obj.name).data.get('fr', None) + return InternationalizationSerializer(obj.name).data.get("fr", None) + class TreeTypeSerializer(serializers.ModelSerializer): en = serializers.SerializerMethodField() fr = serializers.SerializerMethodField() + class Meta: model = Treetype - fields = ['en', 'fr'] + fields = ["en", "fr"] def get_en(self, obj): - return InternationalizationSerializer(obj.name).data.get('en', None) + return InternationalizationSerializer(obj.name).data.get("en", None) def get_fr(self, obj): - return InternationalizationSerializer(obj.name).data.get('fr', None) + return InternationalizationSerializer(obj.name).data.get("fr", None) + class AnnouncementSerializer(serializers.ModelSerializer): class Meta: model = Announcement - fields = '__all__' + fields = "__all__" + class ContactSerializer(serializers.ModelSerializer): class Meta: model = Contact - fields = '__all__' + fields = "__all__" + class SitetreespeciesSerializer(serializers.ModelSerializer): en = serializers.SerializerMethodField() fr = serializers.SerializerMethodField() + class Meta: model = Sitetreespecies - fields = ('id', 'quantity', 'en', 'fr') + fields = ("id", "quantity", "en", "fr") def get_en(self, obj): - return TreeTypeSerializer(obj.tree_type).data.get('en', None) + return TreeTypeSerializer(obj.tree_type).data.get("en", None) def get_fr(self, obj): - return TreeTypeSerializer(obj.tree_type).data.get('fr', None) + return TreeTypeSerializer(obj.tree_type).data.get("fr", None) + class SiteSerializer(serializers.ModelSerializer): site_type = SiteTypeSerializer() @@ -88,11 +119,12 @@ class SiteSerializer(serializers.ModelSerializer): class Meta: model = Site - fields = '__all__' + fields = "__all__" def get_site_tree_species(self, obj): return SitetreespeciesSerializer(obj.sitetreespecies_set.all(), many=True).data + class SiteSocialSerializer(serializers.ModelSerializer): site_type = SiteTypeSerializer() contact = ContactSerializer() @@ -102,7 +134,7 @@ class SiteSocialSerializer(serializers.ModelSerializer): class Meta: model = Site - fields = ('name', 'site_type', 'image', 'description', 'contact', 'announcement', 'sponsors', 'widget') + fields = ("name", "site_type", "image", "description", "contact", "announcement", "sponsors", "widget") def get_sponsors(self, obj): return self.context.get("sponsors") @@ -110,19 +142,21 @@ def get_sponsors(self, obj): def get_widget(self, obj): return WidgetSerializer(obj.widget_set.all(), many=True).data + class BatchfertilizerSerializer(serializers.ModelSerializer): en = serializers.SerializerMethodField() fr = serializers.SerializerMethodField() class Meta: model = Batchfertilizer - fields = ['id', 'en', 'fr'] + fields = ["id", "en", "fr"] def get_en(self, obj): - return InternationalizationSerializer(obj.fertilizer_type).data.get('en', None) + return InternationalizationSerializer(obj.fertilizer_type).data.get("en", None) def get_fr(self, obj): - return InternationalizationSerializer(obj.fertilizer_type).data.get('fr', None) + return InternationalizationSerializer(obj.fertilizer_type).data.get("fr", None) + class BatchMulchLayerSerializer(serializers.ModelSerializer): en = serializers.SerializerMethodField() @@ -130,57 +164,66 @@ class BatchMulchLayerSerializer(serializers.ModelSerializer): class Meta: model = Mulchlayertype - fields = ['id', 'en', 'fr'] + fields = ["id", "en", "fr"] def get_en(self, obj): - return InternationalizationSerializer(obj.mulch_layer_type).data.get('en', None) + return InternationalizationSerializer(obj.mulch_layer_type).data.get("en", None) def get_fr(self, obj): - return InternationalizationSerializer(obj.mulch_layer_type).data.get('fr', None) + return InternationalizationSerializer(obj.mulch_layer_type).data.get("fr", None) + class BatchSupportedSpeciesSerializer(serializers.ModelSerializer): en = serializers.SerializerMethodField() fr = serializers.SerializerMethodField() + class Meta: model = BatchSupportedSpecies - fields = ['en', 'fr'] + fields = ["en", "fr"] def get_en(self, obj): - return InternationalizationSerializer(obj.tree_type).data.get('en', None) + return InternationalizationSerializer(obj.tree_type).data.get("en", None) def get_fr(self, obj): - return InternationalizationSerializer(obj.tree_type).data.get('fr', None) + return InternationalizationSerializer(obj.tree_type).data.get("fr", None) + class BatchSeedSerializer(serializers.ModelSerializer): en = serializers.SerializerMethodField() fr = serializers.SerializerMethodField() + class Meta: model = BatchSeed - fields = ['quantity', 'en', 'fr'] + fields = ["quantity", "en", "fr"] def get_en(self, obj): - return InternationalizationSerializer(obj.tree_type).data.get('en', None) + return InternationalizationSerializer(obj.tree_type).data.get("en", None) def get_fr(self, obj): - return InternationalizationSerializer(obj.tree_type).data.get('fr', None) + return InternationalizationSerializer(obj.tree_type).data.get("fr", None) + class BatchSpeciesSerializer(serializers.ModelSerializer): en = serializers.SerializerMethodField() fr = serializers.SerializerMethodField() + class Meta: model = BatchSpecies - fields = ['quantity', 'en', 'fr'] + fields = ["quantity", "en", "fr"] def get_en(self, obj): - return InternationalizationSerializer(obj.tree_type).data.get('en', None) + return InternationalizationSerializer(obj.tree_type).data.get("en", None) def get_fr(self, obj): - return InternationalizationSerializer(obj.tree_type).data.get('fr', None) + return InternationalizationSerializer(obj.tree_type).data.get("fr", None) + class BatchSerializer(serializers.ModelSerializer): class Meta: model = Batch - fields = '__all__' + fields = "__all__" + + class BatchAnalyticsSerializer(serializers.ModelSerializer): fertilizers = serializers.SerializerMethodField() mulch_layers = serializers.SerializerMethodField() @@ -191,9 +234,24 @@ class BatchAnalyticsSerializer(serializers.ModelSerializer): seed_collected_count = serializers.SerializerMethodField() seeds = serializers.SerializerMethodField() species = serializers.SerializerMethodField() + class Meta: model = Batch - fields = ('id', 'name', 'size', 'soil_condition', 'fertilizers', 'mulch_layers', 'supported_species', 'plant_count', 'survived_count', 'replace_count', 'seed_collected_count', 'seeds', 'species') + fields = ( + "id", + "name", + "size", + "soil_condition", + "fertilizers", + "mulch_layers", + "supported_species", + "plant_count", + "survived_count", + "replace_count", + "seed_collected_count", + "seeds", + "species", + ) def get_plant_count(self, obj): return self.context.get("plant_count") @@ -222,6 +280,7 @@ def get_seeds(self, obj): def get_species(self, obj): return BatchSpeciesSerializer(obj.batchspecies_set.all(), many=True).data + class SiteSummarySerializer(serializers.ModelSerializer): site_type = SiteTypeSerializer() plant_count = serializers.SerializerMethodField() @@ -229,9 +288,19 @@ class SiteSummarySerializer(serializers.ModelSerializer): propagation_count = serializers.SerializerMethodField() progress = serializers.SerializerMethodField() sponsor = serializers.SerializerMethodField() + class Meta: model = Site - fields = ('name', 'site_type', 'plant_count', 'survived_count', 'propagation_count', 'visitor_count', 'sponsor', 'progress') + fields = ( + "name", + "site_type", + "plant_count", + "survived_count", + "propagation_count", + "visitor_count", + "sponsor", + "progress", + ) def get_plant_count(self, obj): return self.context.get("plant_count") @@ -246,26 +315,31 @@ def get_progress(self, obj): return self.context.get("progress") def get_sponsor(self, obj): - return BatchSerializer(obj).data.get('sponsor', None) + return BatchSerializer(obj).data.get("sponsor", None) + class SiteMapSerializer(serializers.ModelSerializer): site_type = SiteTypeSerializer() + class Meta: model = Site - fields = ('id', 'name', 'site_type', 'coordinate', 'image') + fields = ("id", "name", "site_type", "coordinate", "image") + class SiteOverviewSerializer(serializers.ModelSerializer): class Meta: model = Site - fields = ('id', 'name') + fields = ("id", "name") + class PostSerializer(serializers.ModelSerializer): site = SiteOverviewSerializer() comment_count = serializers.SerializerMethodField() has_liked = serializers.SerializerMethodField() + class Meta: model = Post - fields = ('id', 'site', 'created_at', 'body', 'like_count', 'share_count', 'comment_count', 'has_liked') + fields = ("id", "site", "created_at", "body", "like_count", "share_count", "comment_count", "has_liked") def get_comment_count(self, obj): return self.context.get("comment_count") @@ -273,12 +347,14 @@ def get_comment_count(self, obj): def get_has_liked(self, obj): return self.context.get("has_liked") + class CommentSerializer(serializers.ModelSerializer): class Meta: model = Comment - fields = ('id', 'body', 'auth_user', 'created_at') + fields = ("id", "body", "auth_user", "created_at") + class LikeSerializer(serializers.ModelSerializer): class Meta: model = Like - fields = '__all__' + fields = "__all__" diff --git a/canopeum_backend/canopeum_backend/settings.py b/canopeum_backend/canopeum_backend/settings.py index 2c8ca6df1..ad5c3766c 100644 --- a/canopeum_backend/canopeum_backend/settings.py +++ b/canopeum_backend/canopeum_backend/settings.py @@ -81,9 +81,9 @@ WSGI_APPLICATION = "canopeum_backend.wsgi.application" REST_FRAMEWORK = { - 'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema', - 'DEFAULT_RENDERER_CLASSES': [ - 'djangorestframework_camel_case.render.CamelCaseJSONRenderer', + "DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema", + "DEFAULT_RENDERER_CLASSES": [ + "djangorestframework_camel_case.render.CamelCaseJSONRenderer", ], "DEFAULT_PARSER_CLASSES": [ "rest_framework.parsers.JSONParser", diff --git a/canopeum_backend/canopeum_backend/urls.py b/canopeum_backend/canopeum_backend/urls.py index 1c507554a..000fab83a 100644 --- a/canopeum_backend/canopeum_backend/urls.py +++ b/canopeum_backend/canopeum_backend/urls.py @@ -5,61 +5,59 @@ from . import views urlpatterns = [ - path('admin/', admin.site.urls), - - ### Auth - path('auth/login/', views.LoginAPIView.as_view(), name='login'), - path('auth/logout/', views.LogoutAPIView.as_view(), name='logout'), - path('auth/register/', views.RegisterAPIView.as_view(), name='register'), - - ### Social - + path("admin/", admin.site.urls), + # Auth + path("auth/login/", views.LoginAPIView.as_view(), name="login"), + path("auth/logout/", views.LogoutAPIView.as_view(), name="logout"), + path("auth/register/", views.RegisterAPIView.as_view(), name="register"), + # Social # Post - path('social/posts/', views.PostListAPIView.as_view(), name='post-list'), - + path("social/posts/", views.PostListAPIView.as_view(), name="post-list"), # Comment - path('social/posts//comments/', views.CommentListAPIView.as_view(), name='comment-list'), - path('social/posts//comments//', views.CommentDetailAPIView.as_view(), name='comment-detail'), - + path("social/posts//comments/", views.CommentListAPIView.as_view(), name="comment-list"), + path( + "social/posts//comments//", + views.CommentDetailAPIView.as_view(), + name="comment-detail", + ), # Like - path('social/posts//likes/', views.LikeListAPIView.as_view(), name='like-list'), - + path("social/posts//likes/", views.LikeListAPIView.as_view(), name="like-list"), # Site - path('social/sites/', views.SiteSocialDetailAPIView.as_view(), name='site-list'), - path('social/sites//', views.SiteSocialDetailAPIView.as_view(), name='site-detail'), - + path("social/sites/", views.SiteSocialDetailAPIView.as_view(), name="site-list"), + path("social/sites//", views.SiteSocialDetailAPIView.as_view(), name="site-detail"), # Announcement - path('social/sites//announcements/', views.AnnouncementDetailAPIView.as_view(), name='announcement-detail'), - + path( + "social/sites//announcements/", + views.AnnouncementDetailAPIView.as_view(), + name="announcement-detail", + ), # Contact - path('social/sites//contacts//', views.ContactDetailAPIView.as_view(), name='contact-detail'), - + path( + "social/sites//contacts//", + views.ContactDetailAPIView.as_view(), + name="contact-detail", + ), # Widget - path('social/sites//widgets/', views.WidgetListAPIView.as_view(), name='widget-list'), - path('social/sites//widgets//', views.WidgetDetailAPIView.as_view(), name='widget-detail'), - - ### Analytics - + path("social/sites//widgets/", views.WidgetListAPIView.as_view(), name="widget-list"), + path( + "social/sites//widgets//", views.WidgetDetailAPIView.as_view(), name="widget-detail" + ), + # Analytics # Site - path('analytics/sites/', views.SiteListAPIView.as_view(), name='site-list'), - path('analytics/sites//', views.SiteDetailAPIView.as_view(), name='site-detail'), - path('analytics/sites/summary', views.SiteSummaryListAPIView.as_view(), name='site-summary-list'), - path('analytics/sites//summary', views.SiteSummaryDetailAPIView.as_view(), name='site-summary-detail'), - + path("analytics/sites/", views.SiteListAPIView.as_view(), name="site-list"), + path("analytics/sites//", views.SiteDetailAPIView.as_view(), name="site-detail"), + path("analytics/sites/summary", views.SiteSummaryListAPIView.as_view(), name="site-summary-list"), + path("analytics/sites//summary", views.SiteSummaryDetailAPIView.as_view(), name="site-summary-detail"), # Batches - path('analytics/batches/', views.BatchListAPIView.as_view(), name='batch-list'), - path('analytics/batches//', views.BatchDetailAPIView.as_view(), name='batch-detail'), - - ## Map - + path("analytics/batches/", views.BatchListAPIView.as_view(), name="batch-list"), + path("analytics/batches//", views.BatchDetailAPIView.as_view(), name="batch-detail"), + # Map # Coordinate - path('map/sites/', views.SiteMapListAPIView.as_view(), name='coordinate-list-sites'), - + path("map/sites/", views.SiteMapListAPIView.as_view(), name="coordinate-list-sites"), # User - path('users/', views.UserListAPIView.as_view(), name='user-list'), - path('users//', views.UserDetailAPIView.as_view(), name='user-detail'), - path('users/current_user/', views.UserCurrentUserAPIView.as_view(), name='current-user'), - + path("users/", views.UserListAPIView.as_view(), name="user-list"), + path("users//", views.UserDetailAPIView.as_view(), name="user-detail"), + path("users/current_user/", views.UserCurrentUserAPIView.as_view(), name="current-user"), # SWAGGER path("api/schema/", SpectacularAPIView.as_view(), name="schema"), path("api/schema/swagger-ui/", SpectacularSwaggerView.as_view(url_name="schema"), name="swagger-ui"), diff --git a/canopeum_backend/canopeum_backend/views.py b/canopeum_backend/canopeum_backend/views.py index 02fa553d4..64e162032 100644 --- a/canopeum_backend/canopeum_backend/views.py +++ b/canopeum_backend/canopeum_backend/views.py @@ -1,9 +1,5 @@ from typing import ClassVar -from rest_framework import status -from rest_framework.views import APIView -from rest_framework.response import Response -from .models import Contact, Coordinate, Site, Post, Batch, Announcement, Like, Comment, Sitetype, Widget -from .serializers import AuthUserSerializer, BatchAnalyticsSerializer, ContactSerializer, CoordinatesSerializer, SiteMapSerializer, SiteSocialSerializer, SiteSummarySerializer, SiteTypeSerializer, UserSerializer, SiteSerializer, PostSerializer, BatchSerializer, AnnouncementSerializer, LikeSerializer, CommentSerializer, WidgetSerializer + from django.contrib.auth.models import User from drf_spectacular.utils import extend_schema from rest_framework import status @@ -12,17 +8,22 @@ from rest_framework.response import Response from rest_framework.views import APIView - -from .models import Announcement, Batch, Comment, Like, Post, Site +from .models import Announcement, Batch, Comment, Contact, Post, Site, Widget from .serializers import ( AnnouncementSerializer, AuthUserSerializer, + BatchAnalyticsSerializer, BatchSerializer, CommentSerializer, + ContactSerializer, LikeSerializer, PostSerializer, + SiteMapSerializer, SiteSerializer, + SiteSocialSerializer, + SiteSummarySerializer, UserSerializer, + WidgetSerializer, ) @@ -60,6 +61,7 @@ def post(self, request): request.user.auth_token.delete() return Response(status=status.HTTP_200_OK) + class SiteListAPIView(APIView): @extend_schema(responses=SiteSerializer(many=True), operation_id="site_all") def get(self, request): @@ -67,7 +69,6 @@ def get(self, request): serializer = SiteSerializer(sites, many=True) return Response(serializer.data) - @extend_schema(request=SiteSerializer, responses=SiteSerializer, operation_id="site_create") def post(self, request): serializer = SiteSerializer(data=request.data) @@ -76,6 +77,7 @@ def post(self, request): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class SiteDetailAPIView(APIView): @extend_schema(request=SiteSerializer, responses=SiteSerializer, operation_id="site_detail") def get(self, request, siteId): @@ -119,9 +121,19 @@ def get(self, request): survived_count = 0 propagation_count = 0 progress = 0 - serializer = SiteSummarySerializer(sites, many=True, context={'plant_count': plant_count, 'survived_count': survived_count, 'progress': progress, 'propagation_count': propagation_count}) + serializer = SiteSummarySerializer( + sites, + many=True, + context={ + "plant_count": plant_count, + "survived_count": survived_count, + "progress": progress, + "propagation_count": propagation_count, + }, + ) return Response(serializer.data) + class SiteSummaryDetailAPIView(APIView): @extend_schema(responses=SiteSummarySerializer, operation_id="site_summarydetail") def get(self, request, siteId): @@ -133,9 +145,18 @@ def get(self, request, siteId): survived_count = 0 propagation_count = 0 progress = 0 - serializer = SiteSummarySerializer(site, context={'plant_count': plant_count, 'survived_count': survived_count, 'progress': progress, 'propagation_count': propagation_count}) + serializer = SiteSummarySerializer( + site, + context={ + "plant_count": plant_count, + "survived_count": survived_count, + "progress": progress, + "propagation_count": propagation_count, + }, + ) return Response(serializer.data) + class SiteSocialDetailAPIView(APIView): @extend_schema(request=SiteSocialSerializer, responses=SiteSocialSerializer, operation_id="site_social") def get(self, request, siteId): @@ -147,9 +168,10 @@ def get(self, request, siteId): batches = Batch.objects.filter(site=siteId) sponsors = [batch.sponsor for batch in batches] - serializer = SiteSocialSerializer(site, context={'sponsors': sponsors}) + serializer = SiteSocialSerializer(site, context={"sponsors": sponsors}) return Response(serializer.data) + class SiteMapListAPIView(APIView): @extend_schema(responses=SiteMapSerializer, operation_id="site_map") def get_site_map(self): @@ -157,16 +179,17 @@ def get_site_map(self): serializer = SiteMapSerializer(sites, many=True) return Response(serializer.data) + class PostListAPIView(APIView): @extend_schema(responses=PostSerializer(many=True), operation_id="post_all") def get(self, request): try: - comment_count = Comment.objects.get(post=request.data.get('id')).count() + comment_count = Comment.objects.get(post=request.data.get("id")).count() except Comment.DoesNotExist: comment_count = 0 has_liked = 0 posts = Post.objects.all() - serializer = PostSerializer(posts, many=True, context={'comment_count': comment_count, 'has_liked': has_liked}) + serializer = PostSerializer(posts, many=True, context={"comment_count": comment_count, "has_liked": has_liked}) return Response(serializer.data) @extend_schema(request=PostSerializer, responses=PostSerializer, operation_id="post_create") @@ -177,6 +200,7 @@ def post(self, request): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class CommentListAPIView(APIView): @extend_schema(responses=CommentSerializer(many=True), operation_id="comment_all") def get(self, request, postId): @@ -197,6 +221,7 @@ def post(self, request, postId): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class CommentDetailAPIView(APIView): @extend_schema(operation_id="comment_delete") def delete(self, request, pk): @@ -208,6 +233,7 @@ def delete(self, request, pk): comment.delete() return Response(status=status.HTTP_204_NO_CONTENT) + class AnnouncementDetailAPIView(APIView): @extend_schema(request=AnnouncementSerializer, responses=AnnouncementSerializer, operation_id="announcement_update") def put(self, request, siteId): @@ -222,6 +248,7 @@ def put(self, request, siteId): return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class ContactDetailAPIView(APIView): @extend_schema(request=ContactSerializer, responses=ContactSerializer, operation_id="contact_update") def put(self, request, pk): @@ -236,6 +263,7 @@ def put(self, request, pk): return Response(serializer.data) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class WidgetListAPIView(APIView): @extend_schema(request=WidgetSerializer, responses=WidgetSerializer, operation_id="widget_all") def post(self, request): @@ -245,6 +273,7 @@ def post(self, request): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class WidgetDetailAPIView(APIView): @extend_schema(request=WidgetSerializer, responses=WidgetSerializer, operation_id="widget_detail") def put(self, request, pk): @@ -269,6 +298,7 @@ def delete(self, request, pk): widget.delete() return Response(status=status.HTTP_204_NO_CONTENT) + class LikeListAPIView(APIView): @extend_schema(request=LikeSerializer, responses=LikeSerializer, operation_id="like_all") def post(self, request): @@ -278,6 +308,7 @@ def post(self, request): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class BatchListAPIView(APIView): @extend_schema(responses=BatchAnalyticsSerializer(many=True), operation_id="batch_all") def get(self, request): @@ -293,6 +324,7 @@ def post(self, request): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class BatchDetailAPIView(APIView): @extend_schema(request=BatchSerializer, responses=BatchSerializer, operation_id="batch_detail") def put(self, request, batchId): @@ -317,6 +349,7 @@ def delete(self, request, batchId): batch.delete() return Response(status=status.HTTP_204_NO_CONTENT) + class UserListAPIView(APIView): @extend_schema(request=UserSerializer, responses=UserSerializer, operation_id="user_all") def post(self, request): @@ -326,6 +359,7 @@ def post(self, request): return Response(serializer.data, status=status.HTTP_201_CREATED) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + class UserDetailAPIView(APIView): @extend_schema(request=UserSerializer, responses=UserSerializer, operation_id="user_detail") def get(self, request, pk): @@ -360,6 +394,7 @@ def delete(self, request, pk): user.delete() return Response(status=status.HTTP_204_NO_CONTENT) + class UserCurrentUserAPIView(APIView): @extend_schema(responses=UserSerializer, operation_id="user_current_user") def get(self, request): diff --git a/canopeum_frontend/.vite/deps/_metadata.json b/canopeum_frontend/.vite/deps/_metadata.json index 8b03faefc..2544221e2 100644 --- a/canopeum_frontend/.vite/deps/_metadata.json +++ b/canopeum_frontend/.vite/deps/_metadata.json @@ -5,4 +5,4 @@ "browserHash": "d492fda6", "optimized": {}, "chunks": {} -} \ No newline at end of file +}