Skip to content

Commit

Permalink
feat(server): implement invite_to_context endpoint (#820)
Browse files Browse the repository at this point in the history
  • Loading branch information
fbozic authored Oct 18, 2024
1 parent c8a1db7 commit 43782e3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
38 changes: 38 additions & 0 deletions crates/server-primitives/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,44 @@ impl CreateContextRequest {
}
}
}
#[derive(Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct InviteToContextRequest {
pub context_id: ContextId,
pub inviter_id: PublicKey,
pub invitee_id: PublicKey,
}

impl InviteToContextRequest {
#[must_use]
pub const fn new(context_id: ContextId, inviter_id: PublicKey, invitee_id: PublicKey) -> Self {
Self {
context_id,
inviter_id,
invitee_id,
}
}
}

#[derive(Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct InviteToContextResponse {
pub invitation_payload: Option<ContextInvitationPayload>,
}

impl InviteToContextResponse {
#[must_use]
pub const fn new(invitation_payload: Option<ContextInvitationPayload>) -> Self {
Self { invitation_payload }
}
}

#[derive(Debug, Deserialize, Serialize)]
#[non_exhaustive]
pub struct InviteToContextResponseData {
pub context_id: ContextId,
pub invitee_public_key: PublicKey,
}

#[derive(Debug, Deserialize, Serialize)]
#[non_exhaustive]
Expand Down
1 change: 1 addition & 0 deletions crates/server/src/admin/handlers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ pub mod get_context_identities;
pub mod get_context_storage;
pub mod get_context_users;
pub mod get_contexts;
pub mod invite_to_context;
pub mod join_context;
pub mod update_application_id;
27 changes: 27 additions & 0 deletions crates/server/src/admin/handlers/context/invite_to_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::sync::Arc;

use axum::response::IntoResponse;
use axum::{Extension, Json};
use calimero_server_primitives::admin::{InviteToContextRequest, InviteToContextResponse};

use crate::admin::service::{parse_api_error, ApiResponse};
use crate::AdminState;

pub async fn handler(
Extension(state): Extension<Arc<AdminState>>,
Json(req): Json<InviteToContextRequest>,
) -> impl IntoResponse {
let result = state

This comment has been minimized.

Copy link
@MatejVukosav

MatejVukosav Oct 18, 2024

Member

You are missing req validation

.ctx_manager
.invite_to_context(req.context_id, req.inviter_id, req.invitee_id)
.await
.map_err(parse_api_error);

match result {
Ok(invitation_payload) => ApiResponse {
payload: InviteToContextResponse::new(invitation_payload),
}
.into_response(),
Err(err) => err.into_response(),
}
}

0 comments on commit 43782e3

Please sign in to comment.