feat(themes): Create APIs for managing themes (#6658)

Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
Mani Chandra
2024-12-04 15:04:13 +05:30
committed by GitHub
parent 248be9c73e
commit 3a3e93cb3b
26 changed files with 946 additions and 52 deletions

View File

@ -8,7 +8,7 @@ readme = "README.md"
license.workspace = true
[features]
errors = ["dep:actix-web", "dep:reqwest"]
errors = ["dep:reqwest"]
dummy_connector = ["euclid/dummy_connector", "common_enums/dummy_connector"]
detailed_errors = []
payouts = ["common_enums/payouts"]
@ -23,7 +23,8 @@ payment_methods_v2 = ["common_utils/payment_methods_v2"]
dynamic_routing = []
[dependencies]
actix-web = { version = "4.5.1", optional = true }
actix-multipart = "0.6.1"
actix-web = "4.5.1"
error-stack = "0.4.1"
indexmap = "2.3.0"
mime = "0.3.17"

View File

@ -6,6 +6,7 @@ use crate::user::{
dashboard_metadata::{
GetMetaDataRequest, GetMetaDataResponse, GetMultipleMetaDataPayload, SetMetaDataRequest,
},
theme::{CreateThemeRequest, GetThemeResponse, UpdateThemeRequest, UploadFileRequest},
AcceptInviteFromEmailRequest, AuthSelectRequest, AuthorizeResponse, BeginTotpResponse,
ChangePasswordRequest, ConnectAccountRequest, CreateInternalUserRequest,
CreateUserAuthenticationMethodRequest, ForgotPasswordRequest, GetSsoAuthUrlRequest,
@ -61,7 +62,11 @@ common_utils::impl_api_event_type!(
UpdateUserAuthenticationMethodRequest,
GetSsoAuthUrlRequest,
SsoSignInRequest,
AuthSelectRequest
AuthSelectRequest,
GetThemeResponse,
UploadFileRequest,
CreateThemeRequest,
UpdateThemeRequest
)
);

View File

@ -8,6 +8,7 @@ use crate::user_role::UserStatus;
pub mod dashboard_metadata;
#[cfg(feature = "dummy_connector")]
pub mod sample_data;
pub mod theme;
#[derive(serde::Deserialize, Debug, Clone, serde::Serialize)]
pub struct SignUpWithMerchantIdRequest {

View File

@ -0,0 +1,125 @@
use actix_multipart::form::{bytes::Bytes, text::Text, MultipartForm};
use common_enums::EntityType;
use common_utils::{id_type, types::theme::ThemeLineage};
use masking::Secret;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize)]
pub struct GetThemeResponse {
pub theme_id: String,
pub theme_name: String,
pub entity_type: EntityType,
pub tenant_id: id_type::TenantId,
pub org_id: Option<id_type::OrganizationId>,
pub merchant_id: Option<id_type::MerchantId>,
pub profile_id: Option<id_type::ProfileId>,
pub theme_data: ThemeData,
}
#[derive(Debug, MultipartForm)]
pub struct UploadFileAssetData {
pub asset_name: Text<String>,
#[multipart(limit = "10MB")]
pub asset_data: Bytes,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct UploadFileRequest {
pub lineage: ThemeLineage,
pub asset_name: String,
pub asset_data: Secret<Vec<u8>>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct CreateThemeRequest {
pub lineage: ThemeLineage,
pub theme_name: String,
pub theme_data: ThemeData,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct UpdateThemeRequest {
pub lineage: ThemeLineage,
pub theme_data: ThemeData,
}
// All the below structs are for the theme.json file,
// which will be used by frontend to style the dashboard.
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ThemeData {
settings: Settings,
urls: Option<Urls>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Settings {
colors: Colors,
typography: Option<Typography>,
buttons: Buttons,
borders: Option<Borders>,
spacing: Option<Spacing>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Colors {
primary: String,
sidebar: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Typography {
font_family: Option<String>,
font_size: Option<String>,
heading_font_size: Option<String>,
text_color: Option<String>,
link_color: Option<String>,
link_hover_color: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Buttons {
primary: PrimaryButton,
secondary: Option<SecondaryButton>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct PrimaryButton {
background_color: Option<String>,
text_color: Option<String>,
hover_background_color: String,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct SecondaryButton {
background_color: Option<String>,
text_color: Option<String>,
hover_background_color: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Borders {
default_radius: Option<String>,
border_color: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Spacing {
padding: Option<String>,
margin: Option<String>,
}
#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
struct Urls {
favicon_url: Option<String>,
logo_url: Option<String>,
}