mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-23 17:01:35 -05:00
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
31 lines
694 B
Python
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()
|