Skip to content

Commit

Permalink
feat(core:api): add experience_count in user api (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
MagneticNeedle authored Dec 15, 2024
2 parents 2a0b6e7 + 7b2f8d8 commit a2170c3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bfportal/bfportal/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
"BACKEND": "wagtail.search.backends.database",
}
}

WAGTAILAPI_LIMIT_MAX = None
# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
EMAIL_BACKEND = "django.core.mail.backends.dummy.EmailBackend"
Expand Down
2 changes: 1 addition & 1 deletion bfportal/core/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def check_query_parameters(self, queryset):
"""
Checks if all the parameters are valid,
Overriden here so that we can send custom params in our requests
Override here so that we can send custom params in our requests
see `UserFilter` class
"""
Expand Down
7 changes: 7 additions & 0 deletions bfportal/core/serializers/users.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from rest_framework import serializers

from ..models.experience import ExperiencePage
Expand All @@ -23,6 +24,7 @@ class UserModelSerializer(serializers.ModelSerializer):
"""Serializer for User model."""

social_account = serializers.SerializerMethodField()
experience_count = serializers.SerializerMethodField()

class Meta:
model = get_user_model()
Expand All @@ -31,6 +33,7 @@ class Meta:
"username",
"first_name",
"last_name",
"experience_count",
"social_account",
]
depth = 1
Expand All @@ -46,6 +49,10 @@ def get_social_account(self, obj):
# no provider internal account
return {}

def get_experience_count(self, obj: User):
"""Return the count of exp pages a user has created."""
return len(ExperiencePage.objects.filter(owner_id=obj.id))


class ProfileSerializer(serializers.ModelSerializer):
"""Serializer for Profile model."""
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.7"

services:

# Dev environment services (on local machine)
Expand Down

0 comments on commit a2170c3

Please sign in to comment.