|
9 | 9 | import rest_framework_simplejwt.token_blacklist.models as tb_models |
10 | 10 | import rest_framework_simplejwt.tokens |
11 | 11 |
|
| 12 | +import business.models |
12 | 13 | import user.constants |
13 | 14 | import user.models |
14 | 15 | import user.validators |
@@ -244,3 +245,64 @@ def to_representation(self, instance): |
244 | 245 | if not instance.avatar_url: |
245 | 246 | data.pop('avatar_url', None) |
246 | 247 | return data |
| 248 | + |
| 249 | + |
| 250 | +class UserPromoDetailSerializer(rest_framework.serializers.ModelSerializer): |
| 251 | + """ |
| 252 | + Serializer for detailed promo-code information |
| 253 | + (without revealing the code value). |
| 254 | + The output format matches the given example. |
| 255 | + """ |
| 256 | + |
| 257 | + promo_id = rest_framework.serializers.UUIDField( |
| 258 | + source='id', |
| 259 | + read_only=True, |
| 260 | + ) |
| 261 | + company_id = rest_framework.serializers.UUIDField( |
| 262 | + source='company.id', |
| 263 | + read_only=True, |
| 264 | + ) |
| 265 | + company_name = rest_framework.serializers.CharField( |
| 266 | + source='company.name', |
| 267 | + read_only=True, |
| 268 | + ) |
| 269 | + active = rest_framework.serializers.BooleanField( |
| 270 | + source='is_active', |
| 271 | + read_only=True, |
| 272 | + ) |
| 273 | + is_activated_by_user = rest_framework.serializers.SerializerMethodField() |
| 274 | + like_count = rest_framework.serializers.SerializerMethodField() |
| 275 | + is_liked_by_user = rest_framework.serializers.SerializerMethodField() |
| 276 | + comment_count = rest_framework.serializers.SerializerMethodField() |
| 277 | + |
| 278 | + class Meta: |
| 279 | + model = business.models.Promo |
| 280 | + fields = ( |
| 281 | + 'promo_id', |
| 282 | + 'company_id', |
| 283 | + 'company_name', |
| 284 | + 'description', |
| 285 | + 'image_url', |
| 286 | + 'active', |
| 287 | + 'is_activated_by_user', |
| 288 | + 'like_count', |
| 289 | + 'is_liked_by_user', |
| 290 | + 'comment_count', |
| 291 | + ) |
| 292 | + read_only_fields = fields |
| 293 | + |
| 294 | + def get_is_activated_by_user(self, obj) -> bool: |
| 295 | + # TODO: |
| 296 | + return False |
| 297 | + |
| 298 | + def get_like_count(self, obj) -> int: |
| 299 | + # TODO: |
| 300 | + return 0 |
| 301 | + |
| 302 | + def get_is_liked_by_user(self, obj) -> bool: |
| 303 | + # TODO: |
| 304 | + return False |
| 305 | + |
| 306 | + def get_comment_count(self, obj) -> int: |
| 307 | + # TODO: |
| 308 | + return 0 |
0 commit comments