2024-11-18 10:59:38 -08:00
|
|
|
from sqlalchemy import select
|
|
|
|
|
|
2021-03-10 13:55:06 +00:00
|
|
|
from app import create_uuid, db
|
2021-04-14 07:11:01 +01:00
|
|
|
from app.dao.dao_utils import autocommit, version_class
|
2017-06-15 11:32:51 +01:00
|
|
|
from app.models import ServiceInboundApi
|
2024-05-23 13:59:51 -07:00
|
|
|
from app.utils import utc_now
|
2017-06-13 15:27:13 +01:00
|
|
|
|
|
|
|
|
|
2021-04-14 07:11:01 +01:00
|
|
|
@autocommit
|
2017-06-15 11:32:51 +01:00
|
|
|
@version_class(ServiceInboundApi)
|
2017-06-13 15:27:13 +01:00
|
|
|
def save_service_inbound_api(service_inbound_api):
|
2017-06-15 11:32:51 +01:00
|
|
|
service_inbound_api.id = create_uuid()
|
2024-05-23 13:59:51 -07:00
|
|
|
service_inbound_api.created_at = utc_now()
|
2017-06-13 15:27:13 +01:00
|
|
|
db.session.add(service_inbound_api)
|
2017-06-15 11:32:51 +01:00
|
|
|
|
|
|
|
|
|
2021-04-14 07:11:01 +01:00
|
|
|
@autocommit
|
2017-06-15 11:32:51 +01:00
|
|
|
@version_class(ServiceInboundApi)
|
2023-08-29 14:54:30 -07:00
|
|
|
def reset_service_inbound_api(
|
|
|
|
|
service_inbound_api, updated_by_id, url=None, bearer_token=None
|
|
|
|
|
):
|
2017-06-19 12:25:05 +01:00
|
|
|
if url:
|
|
|
|
|
service_inbound_api.url = url
|
|
|
|
|
if bearer_token:
|
2017-06-19 14:32:22 +01:00
|
|
|
service_inbound_api.bearer_token = bearer_token
|
2017-06-19 12:25:05 +01:00
|
|
|
service_inbound_api.updated_by_id = updated_by_id
|
2024-05-23 13:59:51 -07:00
|
|
|
service_inbound_api.updated_at = utc_now()
|
2017-06-19 12:25:05 +01:00
|
|
|
|
2017-06-15 11:32:51 +01:00
|
|
|
db.session.add(service_inbound_api)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_service_inbound_api(service_inbound_api_id, service_id):
|
2024-11-18 10:59:38 -08:00
|
|
|
return (
|
|
|
|
|
db.session.execute(
|
2024-12-19 11:10:03 -08:00
|
|
|
select(ServiceInboundApi).where(
|
|
|
|
|
ServiceInboundApi.id == service_inbound_api_id,
|
|
|
|
|
ServiceInboundApi.service_id == service_id,
|
2024-11-18 10:59:38 -08:00
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
.scalars()
|
|
|
|
|
.first()
|
|
|
|
|
)
|
2017-06-19 16:35:15 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_service_inbound_api_for_service(service_id):
|
2024-11-18 10:59:38 -08:00
|
|
|
return (
|
2024-12-19 11:10:03 -08:00
|
|
|
db.session.execute(
|
|
|
|
|
select(ServiceInboundApi).where(ServiceInboundApi.service_id == service_id)
|
|
|
|
|
)
|
2024-11-18 10:59:38 -08:00
|
|
|
.scalars()
|
|
|
|
|
.first()
|
|
|
|
|
)
|
2018-07-05 11:09:17 +01:00
|
|
|
|
|
|
|
|
|
2021-04-14 07:11:01 +01:00
|
|
|
@autocommit
|
2018-07-05 11:09:17 +01:00
|
|
|
def delete_service_inbound_api(service_inbound_api):
|
|
|
|
|
db.session.delete(service_inbound_api)
|