Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add create retrieve and update api endpoints for organization resource #5361

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
144 changes: 141 additions & 3 deletions api-reference/openapi_spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,111 @@
]
}
},
"/organization": {
"post": {
"tags": [
"Organization"
],
"summary": "Organization - Create",
"description": "Organization - Create\n\nCreate a new organization",
"operationId": "Create an Organization",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OrganizationRequest"
},
"examples": {
"Create an organization with organization_name": {
"value": {
"organization_name": "organization_abc"
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Organization Created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OrganizationResponse"
}
}
}
},
"400": {
"description": "Invalid data"
}
},
"security": [
{
"admin_api_key": []
}
]
}
},
"/organization/{organization_id}": {
"post": {
"tags": [
"Organization"
],
"summary": "Organization - Update",
"description": "Organization - Update\n\nCreate a new organization for .",
"operationId": "Create an Organization",
"parameters": [
{
"name": "organization_id",
"in": "path",
"description": "The unique identifier for the Organization",
"required": true,
"schema": {
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OrganizationRequest"
},
"examples": {
"Update organization_name of the organization": {
"value": {
"organization_name": "organization_abcd"
}
}
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Organization Created",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/OrganizationResponse"
}
}
}
},
"400": {
"description": "Invalid data"
}
},
"security": [
{
"admin_api_key": []
}
]
}
},
"/accounts": {
"post": {
"tags": [
Expand Down Expand Up @@ -11158,7 +11263,8 @@
"MerchantAccountCreate": {
"type": "object",
"required": [
"merchant_id"
"merchant_id",
"organization_id"
],
"properties": {
"merchant_id": {
Expand Down Expand Up @@ -11271,7 +11377,9 @@
"organization_id": {
"type": "string",
"description": "The id of the organization to which the merchant belongs to, if not passed an organization is created",
"nullable": true
"example": "org_q98uSGAYbjEwqs0mJwnz",
"maxLength": 64,
"minLength": 1
},
"pm_collect_link_config": {
"allOf": [
Expand Down Expand Up @@ -11488,7 +11596,10 @@
},
"organization_id": {
"type": "string",
"description": "The organization id merchant is associated with"
"description": "The organization id merchant is associated with",
"example": "org_q98uSGAYbjEwqs0mJwnz",
"maxLength": 64,
"minLength": 1
},
"is_recon_enabled": {
"type": "boolean",
Expand Down Expand Up @@ -12876,6 +12987,33 @@
}
}
},
"OrganizationRequest": {
"type": "object",
"properties": {
"organization_name": {
"type": "string",
"nullable": true
}
}
},
"OrganizationResponse": {
"type": "object",
"required": [
"organization_id"
],
"properties": {
"organization_id": {
"type": "string",
"example": "org_q98uSGAYbjEwqs0mJwnz",
"maxLength": 64,
"minLength": 1
},
"organization_name": {
"type": "string",
"nullable": true
}
}
},
"OutgoingWebhook": {
"type": "object",
"required": [
Expand Down
12 changes: 8 additions & 4 deletions crates/api_models/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ pub struct MerchantAccountCreate {
pub frm_routing_algorithm: Option<serde_json::Value>,

/// The id of the organization to which the merchant belongs to, if not passed an organization is created
pub organization_id: Option<String>,
#[schema(value_type = String, max_length = 64, min_length = 1, example = "org_q98uSGAYbjEwqs0mJwnz")]
hrithikesh026 marked this conversation as resolved.
Show resolved Hide resolved
pub organization_id: Option<id_type::OrganizationId>,

/// Default payment method collect link config
#[schema(value_type = Option<BusinessCollectLinkConfig>)]
Expand Down Expand Up @@ -198,7 +199,8 @@ pub struct MerchantAccountCreate {
pub metadata: Option<MerchantAccountMetadata>,

/// The id of the organization to which the merchant belongs to. Please use the organization endpoint to create an organization
pub organization_id: String,
#[schema(value_type = String, max_length = 64, min_length = 1, example = "org_q98uSGAYbjEwqs0mJwnz")]
pub organization_id: id_type::OrganizationId,
}

#[cfg(feature = "v2")]
Expand Down Expand Up @@ -401,7 +403,8 @@ pub struct MerchantAccountResponse {
pub frm_routing_algorithm: Option<serde_json::Value>,

/// The organization id merchant is associated with
pub organization_id: String,
#[schema(value_type = String, max_length = 64, min_length = 1, example = "org_q98uSGAYbjEwqs0mJwnz")]
pub organization_id: id_type::OrganizationId,

/// A boolean value to indicate if the merchant has recon service is enabled or not, by default value is false
pub is_recon_enabled: bool,
Expand Down Expand Up @@ -443,7 +446,8 @@ pub struct MerchantAccountResponse {
pub metadata: Option<pii::SecretSerdeValue>,

/// The id of the organization which the merchant is associated with
pub organization_id: String,
#[schema(value_type = String, max_length = 64, min_length = 1, example = "org_q98uSGAYbjEwqs0mJwnz")]
pub organization_id: id_type::OrganizationId,

/// A boolean value to indicate if the merchant has recon service is enabled or not, by default value is false
pub is_recon_enabled: bool,
Expand Down
6 changes: 5 additions & 1 deletion crates/api_models/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::{
disputes::*,
files::*,
mandates::*,
organization::{OrganizationId, OrganizationRequest, OrganizationResponse},
payment_methods::*,
payments::*,
verifications::*,
Expand Down Expand Up @@ -125,7 +126,10 @@ impl_misc_api_event_type!(
GetSearchRequestWithIndex,
GetDisputeFilterRequest,
DisputeFiltersResponse,
GetDisputeMetricRequest
GetDisputeMetricRequest,
OrganizationResponse,
OrganizationRequest,
OrganizationId
);

#[cfg(feature = "stripe")]
Expand Down
23 changes: 21 additions & 2 deletions crates/api_models/src/organization.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
use common_utils::id_type;
use utoipa::ToSchema;
pub struct OrganizationNew {
pub org_id: String,
pub org_id: id_type::OrganizationId,
pub org_name: Option<String>,
}

impl OrganizationNew {
pub fn new(org_name: Option<String>) -> Self {
Self {
org_id: common_utils::generate_id_with_default_len("org"),
org_id: id_type::OrganizationId::default(),
org_name,
}
}
}

#[derive(Clone, Debug, serde::Serialize)]
pub struct OrganizationId {
pub organization_id: id_type::OrganizationId,
}

#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct OrganizationRequest {
pub organization_name: Option<String>,
}

#[derive(Debug, serde::Serialize, Clone, ToSchema)]
pub struct OrganizationResponse {
#[schema(value_type = String, max_length = 64, min_length = 1, example = "org_q98uSGAYbjEwqs0mJwnz")]
pub organization_id: id_type::OrganizationId,
pub organization_name: Option<String>,
}
6 changes: 3 additions & 3 deletions crates/api_models/src/user.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use common_enums::{PermissionGroup, RoleScope, TokenPurpose};
use common_utils::{crypto::OptionalEncryptableName, pii};
use common_utils::{crypto::OptionalEncryptableName, id_type, pii};
use masking::Secret;

use crate::user_role::UserStatus;
Expand Down Expand Up @@ -164,7 +164,7 @@ pub struct GetUserDetailsResponse {
// This field is added for audit/debug reasons
#[serde(skip_serializing)]
pub user_id: String,
pub org_id: String,
pub org_id: id_type::OrganizationId,
pub is_two_factor_auth_setup: bool,
pub recovery_codes_left: Option<usize>,
}
Expand Down Expand Up @@ -206,7 +206,7 @@ pub struct UserMerchantAccount {
pub is_active: bool,
pub role_id: String,
pub role_name: String,
pub org_id: String,
pub org_id: id_type::OrganizationId,
}

#[cfg(feature = "recon")]
Expand Down
21 changes: 10 additions & 11 deletions crates/common_utils/src/id_type.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
//! Common ID types
//! The id type can be used to create specific id types with custom behaviour

use std::{
borrow::Cow,
fmt::{Debug, Display},
};
use std::{borrow::Cow, fmt::Debug};

mod customer;
mod merchant;
mod organization;

pub use customer::CustomerId;
use diesel::{
Expand All @@ -18,6 +16,7 @@ use diesel::{
sql_types,
};
pub use merchant::MerchantId;
pub use organization::OrganizationId;
use serde::{Deserialize, Serialize};
use thiserror::Error;

Expand All @@ -37,7 +36,7 @@ fn get_invalid_input_character(input_string: Cow<'static, str>) -> Option<char>
.find(|char| !is_valid_id_character(char))
}

#[derive(Debug, PartialEq, Serialize, Clone, Eq)]
#[derive(Debug, PartialEq, Serialize, Clone, Eq, Hash)]
/// A type for alphanumeric ids
pub(crate) struct AlphaNumericId(String);

Expand Down Expand Up @@ -83,7 +82,7 @@ impl AlphaNumericId {
}

/// A common type of id that can be used for reference ids with length constraint
#[derive(Debug, Clone, Serialize, PartialEq, Eq, AsExpression)]
#[derive(Debug, Clone, Serialize, PartialEq, Eq, AsExpression, Hash)]
#[diesel(sql_type = sql_types::Text)]
pub(crate) struct LengthId<const MAX_LENGTH: u8, const MIN_LENGTH: u8>(AlphaNumericId);

Expand Down Expand Up @@ -168,11 +167,11 @@ where
}
}

impl<const MAX_LENGTH: u8, const MIN_LENGTH: u8> Display for LengthId<MAX_LENGTH, MIN_LENGTH> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0 .0)
}
}
// impl<const MAX_LENGTH: u8, const MIN_LENGTH: u8> Display for LengthId<MAX_LENGTH, MIN_LENGTH> {
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// write!(f, "{}", self.0. 0)
// }
// }
hrithikesh026 marked this conversation as resolved.
Show resolved Hide resolved

impl<DB, const MAX_LENGTH: u8, const MIN_LENGTH: u8> FromSql<sql_types::Text, DB>
for LengthId<MAX_LENGTH, MIN_LENGTH>
Expand Down
Loading
Loading