modified serialized method and schema

This commit is contained in:
venusbb
2017-10-26 13:25:11 +01:00
parent e88b311c8e
commit c10cde6b22
5 changed files with 31 additions and 14 deletions

View File

@@ -8,7 +8,7 @@ create_or_update_free_sms_fragment_limit_schema = {
"title": "Create",
"properties": {
"free_sms_fragment_limit": {"type": "integer", "minimum": 1},
"financial_year_start": {"type": "integer", "minimum": 1}
"financial_year_start": {"type": "integer", "minimum": 2016}
},
"required": ["free_sms_fragment_limit", "financial_year_start"]
}

View File

@@ -105,13 +105,13 @@ def get_free_sms_fragment_limit(service_id):
if len(results) == 0:
raise InvalidRequest('no annual billing information for this service', status_code=404)
return jsonify(data=[row.serialize() for row in results]), 200
return jsonify(data=[row.serialize_free_sms_items() for row in results]), 200
else:
result = dao_get_free_sms_fragment_limit_for_year(service_id, financial_year_start)
if result is None:
raise InvalidRequest('no free-sms-fragment-limit-info for this service and year', status_code=404)
return jsonify(data=result.serialize()), 200
return jsonify(data=result.serialize_free_sms_items()), 200
@billing_blueprint.route('/free-sms-fragment-limit', methods=["POST"])

View File

@@ -278,12 +278,29 @@ class AnnualBilling(db.Model):
UniqueConstraint('financial_year_start', 'service_id', name='ix_annual_billing_service_id')
service = db.relationship(Service, backref=db.backref("annual_billing", uselist=True))
def serialize(self):
def serialize_free_sms_items(self):
return {
'free_sms_fragment_limit': self.free_sms_fragment_limit,
'financial_year_start': self.financial_year_start,
}
def serialize(self):
def serialize_service():
return {
"id": str(self.service_id),
"name": self.service.name
}
return{
"id": str(self.id),
'free_sms_fragment_limit': self.free_sms_fragment_limit,
'service_id': self.service_id,
'financial_year_start': self.financial_year_start,
"created_at": self.created_at.strftime(DATETIME_FORMAT),
"updated_at": self.updated_at.strftime(DATETIME_FORMAT) if self.updated_at else None,
"service": serialize_service() if self.service else None,
}
class InboundNumber(db.Model):
__tablename__ = "inbound_numbers"