mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-28 12:15:40 +08:00
feat(core): api ,domain and diesel model changes for extended authorization (#6607)
Co-authored-by: Gnanasundari24 <118818938+Gnanasundari24@users.noreply.github.com> Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -6,6 +6,9 @@ pub mod authentication;
|
||||
/// Enum for Theme Lineage
|
||||
pub mod theme;
|
||||
|
||||
/// types that are wrappers around primitive types
|
||||
pub mod primitive_wrappers;
|
||||
|
||||
use std::{
|
||||
borrow::Cow,
|
||||
fmt::Display,
|
||||
@ -26,6 +29,10 @@ use diesel::{
|
||||
AsExpression, FromSqlRow, Queryable,
|
||||
};
|
||||
use error_stack::{report, ResultExt};
|
||||
pub use primitive_wrappers::bool_wrappers::{
|
||||
AlwaysRequestExtendedAuthorization, ExtendedAuthorizationAppliedBool,
|
||||
RequestExtendedAuthorizationBool,
|
||||
};
|
||||
use rust_decimal::{
|
||||
prelude::{FromPrimitive, ToPrimitive},
|
||||
Decimal,
|
||||
|
||||
107
crates/common_utils/src/types/primitive_wrappers.rs
Normal file
107
crates/common_utils/src/types/primitive_wrappers.rs
Normal file
@ -0,0 +1,107 @@
|
||||
pub(crate) mod bool_wrappers {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Bool that represents if Extended Authorization is Applied or not
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, diesel::expression::AsExpression,
|
||||
)]
|
||||
#[diesel(sql_type = diesel::sql_types::Bool)]
|
||||
pub struct ExtendedAuthorizationAppliedBool(bool);
|
||||
impl From<bool> for ExtendedAuthorizationAppliedBool {
|
||||
fn from(value: bool) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
impl<DB> diesel::serialize::ToSql<diesel::sql_types::Bool, DB> for ExtendedAuthorizationAppliedBool
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
bool: diesel::serialize::ToSql<diesel::sql_types::Bool, DB>,
|
||||
{
|
||||
fn to_sql<'b>(
|
||||
&'b self,
|
||||
out: &mut diesel::serialize::Output<'b, '_, DB>,
|
||||
) -> diesel::serialize::Result {
|
||||
self.0.to_sql(out)
|
||||
}
|
||||
}
|
||||
impl<DB> diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>
|
||||
for ExtendedAuthorizationAppliedBool
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
bool: diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>,
|
||||
{
|
||||
fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
|
||||
bool::from_sql(value).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Bool that represents if Extended Authorization is Requested or not
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize, diesel::expression::AsExpression,
|
||||
)]
|
||||
#[diesel(sql_type = diesel::sql_types::Bool)]
|
||||
pub struct RequestExtendedAuthorizationBool(bool);
|
||||
impl From<bool> for RequestExtendedAuthorizationBool {
|
||||
fn from(value: bool) -> Self {
|
||||
Self(value)
|
||||
}
|
||||
}
|
||||
impl RequestExtendedAuthorizationBool {
|
||||
/// returns the inner bool value
|
||||
pub fn is_true(&self) -> bool {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
impl<DB> diesel::serialize::ToSql<diesel::sql_types::Bool, DB> for RequestExtendedAuthorizationBool
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
bool: diesel::serialize::ToSql<diesel::sql_types::Bool, DB>,
|
||||
{
|
||||
fn to_sql<'b>(
|
||||
&'b self,
|
||||
out: &mut diesel::serialize::Output<'b, '_, DB>,
|
||||
) -> diesel::serialize::Result {
|
||||
self.0.to_sql(out)
|
||||
}
|
||||
}
|
||||
impl<DB> diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>
|
||||
for RequestExtendedAuthorizationBool
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
bool: diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>,
|
||||
{
|
||||
fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
|
||||
bool::from_sql(value).map(Self)
|
||||
}
|
||||
}
|
||||
|
||||
/// Bool that represents if Extended Authorization is always Requested or not
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Eq, PartialEq, diesel::expression::AsExpression, Serialize, Deserialize,
|
||||
)]
|
||||
#[diesel(sql_type = diesel::sql_types::Bool)]
|
||||
pub struct AlwaysRequestExtendedAuthorization(bool);
|
||||
impl<DB> diesel::serialize::ToSql<diesel::sql_types::Bool, DB>
|
||||
for AlwaysRequestExtendedAuthorization
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
bool: diesel::serialize::ToSql<diesel::sql_types::Bool, DB>,
|
||||
{
|
||||
fn to_sql<'b>(
|
||||
&'b self,
|
||||
out: &mut diesel::serialize::Output<'b, '_, DB>,
|
||||
) -> diesel::serialize::Result {
|
||||
self.0.to_sql(out)
|
||||
}
|
||||
}
|
||||
impl<DB> diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>
|
||||
for AlwaysRequestExtendedAuthorization
|
||||
where
|
||||
DB: diesel::backend::Backend,
|
||||
bool: diesel::deserialize::FromSql<diesel::sql_types::Bool, DB>,
|
||||
{
|
||||
fn from_sql(value: DB::RawValue<'_>) -> diesel::deserialize::Result<Self> {
|
||||
bool::from_sql(value).map(Self)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user