-
-
-
-
-
NostrRelay:
+async def api_create_relay(data: NostrRelay, wallet: WalletTypeInfo = Depends(require_admin_key)) -> NostrRelay:
try:
relay = await create_relay(wallet.wallet.user, data)
@@ -59,6 +59,34 @@ async def api_create_survey(data: NostrRelay, wallet: WalletTypeInfo = Depends(r
detail="Cannot create relay",
)
+@nostrrelay_ext.put("/api/v1/relay/{relay_id}")
+async def api_update_relay(relay_id: str, data: NostrRelay, wallet: WalletTypeInfo = Depends(require_admin_key)) -> NostrRelay:
+ if relay_id != data.id:
+ raise HTTPException(
+ status_code=HTTPStatus.BAD_REQUEST,
+ detail="Cannot change the relay id",
+ )
+
+ try:
+ relay = await get_relay(wallet.wallet.user, data.id)
+ if not relay:
+ raise HTTPException(
+ status_code=HTTPStatus.NOT_FOUND,
+ detail="Relay not found",
+ )
+ updated_relay = NostrRelay.parse_obj({**dict(relay), **dict(data)})
+ updated_relay = await update_relay(wallet.wallet.user, updated_relay)
+ return updated_relay
+
+ except HTTPException as ex:
+ raise ex
+ except Exception as ex:
+ logger.warning(ex)
+ raise HTTPException(
+ status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
+ detail="Cannot update relay",
+ )
+
@nostrrelay_ext.get("/api/v1/relay")
async def api_get_relays(wallet: WalletTypeInfo = Depends(require_invoice_key)) -> List[NostrRelay]: