def get(self, zero_or_one): """Endpoint to retrieve campaigns by active or inactive.""" campaigns = get_campaigns_by_type('is_active', zero_or_one) if campaigns or campaigns == []: schema = CampaignSchema(many=True) return schema.dump(campaigns).data return None, status.HTTP_500_INTERNAL_SERVER_ERROR
def get(self, campaign_id): """Endpoint to retrieve campaign its id.""" campaign = get_campaign_by_id(campaign_id) if campaign: schema = CampaignSchema() result = schema.dump(campaign).data return result, status.HTTP_200_OK if not campaign: return None, status.HTTP_404_NOT_FOUND return None, status.HTTP_500_INTERNAL_SERVER_ERROR
def get(self, zero_or_one): """Endpoint to retrieve campaigns by filter criteria.""" campaigns = get_campaigns_by_type('is_default', zero_or_one) if campaigns or campaigns == []: schema = CampaignSchema(many=True) result = schema.dump(campaigns).data if not result: # pylint: disable=no-else-return # Return the empty list. return [] elif len(result) == 1: # If there is one campaign then return the object. return result[0] # Handle the case where there are multiple campaigns to return. if not zero_or_one: # If asking for non-default campaigns return the list. return result # If asking for default campaign and there is more than one: raise the error. raise CampaignIsDefaultError return None, status.HTTP_500_INTERNAL_SERVER_ERROR