Files
notifications-api/app/dao/inbound_sms_dao.py
Leo Hemsted ef52337d85 add inbound sms api
two endpoints:
* get all inbound sms for a service (you can limit to the X most
  recent, or filter by user's phone number [which will be normalised])
* get a summary of inbound sms for a service - returns the count of
  inbound sms in the database, and the date that the most recent was
  sent
2017-06-02 15:20:18 +01:00

31 lines
694 B
Python

from app import db
from app.dao.dao_utils import transactional
from app.models import InboundSms
@transactional
def dao_create_inbound_sms(inbound_sms):
db.session.add(inbound_sms)
def dao_get_inbound_sms_for_service(service_id, limit=None, user_number=None):
q = InboundSms.query.filter(
InboundSms.service_id == service_id
).order_by(
InboundSms.created_at.desc()
)
if user_number:
q = q.filter(InboundSms.user_number == user_number)
if limit:
q = q.limit(limit)
return q.all()
def dao_count_inbound_sms_for_service(service_id):
return InboundSms.query.filter(
InboundSms.service_id == service_id
).count()