Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Open API with backend and camelCase everything #55

Merged
merged 3 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion canopeum_backend/canopeum_backend/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,28 @@ def get_progress(self, obj):
def get_sponsor(self, obj):
return BatchSerializer(obj).data.get('sponsor', None)

class CoordinatesMapSerializer(serializers.ModelSerializer):
latitude = serializers.SerializerMethodField()
longitude = serializers.SerializerMethodField()
class Meta:
model = Coordinate
fields = ('latitude', 'longitude', 'address')

def get_latitude(self, obj):
return obj.dd_latitude

def get_longitude(self, obj):
return obj.dd_longitude

class SiteMapSerializer(serializers.ModelSerializer):
site_type = SiteTypeSerializer()
coordinates = serializers.SerializerMethodField()
class Meta:
model = Site
fields = ('id', 'name', 'site_type', 'coordinate', 'image')
fields = ('id', 'name', 'site_type', 'coordinates', 'image')

def get_coordinates(self, obj):
return CoordinatesMapSerializer(obj.coordinate).data

class SiteOverviewSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
5 changes: 5 additions & 0 deletions canopeum_backend/canopeum_backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
"COMPONENT_NO_READ_ONLY_REQUIRED": False,
# Create separate components for PATCH endpoints (without required list)
"COMPONENT_SPLIT_PATCH": True,
'CAMELIZE_NAMES': True,
'POSTPROCESSING_HOOKS': [
'drf_spectacular.contrib.djangorestframework_camel_case.camelize_serializer_fields',
'drf_spectacular.hooks.postprocess_schema_enums'
],
}


Expand Down
2 changes: 1 addition & 1 deletion canopeum_backend/canopeum_backend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def get(self, request, siteId):

class SiteMapListAPIView(APIView):
@extend_schema(responses=SiteMapSerializer, operation_id="site_map")
def get_site_map(self):
def get(self, request):
sites = Site.objects.all()
serializer = SiteMapSerializer(sites, many=True)
return Response(serializer.data)
Expand Down
Loading