Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/dispatch/service/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from fastapi import APIRouter, Body, HTTPException, status, Query
from fastapi import APIRouter, Body, HTTPException, Query, status
from pydantic import ValidationError

from sqlalchemy.exc import IntegrityError

from dispatch.database.core import DbSession
Expand All @@ -9,15 +8,14 @@

from .models import ServiceCreate, ServicePagination, ServiceRead, ServiceUpdate
from .service import (
get,
create,
update,
delete,
get_by_external_id_and_project_name,
get,
get_all_by_external_ids,
get_by_external_id_and_project_name,
update,
)


router = APIRouter()


Expand Down Expand Up @@ -59,7 +57,7 @@ def create_service(
raise ValidationError(
[
{
"msg": "A service with this external id already exists.",
"msg": "An oncall service with this external id already exists.",
"loc": "external_id",
}
],
Expand All @@ -75,7 +73,7 @@ def update_service(db_session: DbSession, service_id: PrimaryKey, service_in: Se
if not service:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=[{"msg": "A service with this id does not exist."}],
detail=[{"msg": "An oncall service with this id does not exist."}],
)

try:
Expand All @@ -84,7 +82,7 @@ def update_service(db_session: DbSession, service_id: PrimaryKey, service_in: Se
raise ValidationError(
[
{
"msg": "A service with this name already exists.",
"msg": "An oncall service with this name already exists.",
"loc": "name",
}
],
Expand All @@ -100,7 +98,7 @@ def get_service(db_session: DbSession, service_id: PrimaryKey):
if not service:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=[{"msg": "A service with this id does not exist."}],
detail=[{"msg": "An oncall service with this id does not exist."}],
)
return service

Expand All @@ -112,16 +110,18 @@ def delete_service(db_session: DbSession, service_id: PrimaryKey):
if not service:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=[{"msg": "A service with this id does not exist."}],
detail=[{"msg": "An oncall service with this id does not exist."}],
)

try:
delete(db_session=db_session, service_id=service_id)
except IntegrityError:
raise HTTPException(
status_code=status.HTTP_409_CONFLICT,
detail=[
{
"msg": "Unable to delete service because it is referenced by an incident `Role`. Remove this reference before deletion."
"msg": f"Unable to delete oncall service {service.name} with id {service.id}. Contact your administrator",
"loc": "service_id",
}
],
) from None
Loading