parent
fc835dc982
commit
1ed0cfb38c
4 changed files with 47 additions and 9 deletions
|
|
@ -6,7 +6,11 @@ Endpoints:
|
|||
- Endpoints: Description
|
||||
"""
|
||||
from fastapi import APIRouter, status
|
||||
from psycopg.errors import UniqueViolation
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from auth.exceptions import UnauthorizedException
|
||||
from exceptions import Conflict
|
||||
from src.database import db_dependency
|
||||
from src.auth.service import claims_dependency
|
||||
from src.auth.dependencies import super_admin_dependency, org_model_root_claim_query_dependency, org_model_root_claim_body_dependency
|
||||
|
|
@ -34,7 +38,12 @@ async def register_service(db: db_dependency, su: super_admin_dependency, servic
|
|||
service_model = Service(name=service_request.name, api_key=key)
|
||||
|
||||
db.add(service_model)
|
||||
db.flush()
|
||||
try:
|
||||
db.flush()
|
||||
except IntegrityError as e:
|
||||
if isinstance(e.orig, UniqueViolation):
|
||||
raise Conflict(message="Service with this name already exists")
|
||||
db.commit()
|
||||
response = ServiceWithKeyResponse(**service_model.__dict__)
|
||||
db.commit()
|
||||
return {"service": response}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue