Merge pull request #1373 from alphagov/ken-get-inbound_sms-api

Get inbound SMS API
This commit is contained in:
kentsanggds
2017-11-10 10:25:02 +00:00
committed by GitHub
12 changed files with 483 additions and 15 deletions

View File

@@ -2,7 +2,8 @@ from datetime import (
timedelta,
datetime
)
from flask import current_app
from sqlalchemy import desc
from app import db
from app.dao.dao_utils import transactional
@@ -31,6 +32,28 @@ def dao_get_inbound_sms_for_service(service_id, limit=None, user_number=None):
return q.all()
def dao_get_paginated_inbound_sms_for_service(
service_id,
older_than=None,
page_size=None
):
if page_size is None:
page_size = current_app.config['PAGE_SIZE']
filters = [InboundSms.service_id == service_id]
if older_than:
older_than_created_at = db.session.query(
InboundSms.created_at).filter(InboundSms.id == older_than).as_scalar()
filters.append(InboundSms.created_at < older_than_created_at)
query = InboundSms.query.filter(*filters)
return query.order_by(desc(InboundSms.created_at)).paginate(
per_page=page_size
).items
def dao_count_inbound_sms_for_service(service_id):
return InboundSms.query.filter(
InboundSms.service_id == service_id