File tree Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Expand file tree Collapse file tree 3 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,38 @@ pub trait IdentityServiceApi: Send + Sync {
58
58
) -> Result < Vec < u8 > > ;
59
59
}
60
60
61
+ #[ repr( u8 ) ]
62
+ #[ derive(
63
+ Debug ,
64
+ Clone ,
65
+ serde_repr:: Serialize_repr ,
66
+ serde_repr:: Deserialize_repr ,
67
+ PartialEq ,
68
+ Eq ,
69
+ ToSchema ,
70
+ BorshSerialize ,
71
+ BorshDeserialize ,
72
+ ) ]
73
+ #[ borsh( use_discriminant = true ) ]
74
+ pub enum IdentityType {
75
+ Person = 0 ,
76
+ Company = 1 ,
77
+ }
78
+
79
+ impl TryFrom < u64 > for IdentityType {
80
+ type Error = super :: Error ;
81
+
82
+ fn try_from ( value : u64 ) -> std:: result:: Result < Self , Self :: Error > {
83
+ match value {
84
+ 0 => Ok ( IdentityType :: Person ) ,
85
+ 1 => Ok ( IdentityType :: Company ) ,
86
+ _ => Err ( super :: Error :: Validation ( format ! (
87
+ "Invalid identity type found: {value}"
88
+ ) ) ) ,
89
+ }
90
+ }
91
+ }
92
+
61
93
/// The identity service is responsible for managing the local identity and syncing it
62
94
/// with the dht data.
63
95
#[ derive( Clone ) ]
Original file line number Diff line number Diff line change
1
+ use crate :: service:: identity_service:: IdentityType ;
1
2
use crate :: service:: {
2
3
bill_service:: LightBitcreditBillToReturn ,
3
4
company_service:: CompanyToReturn ,
@@ -251,6 +252,8 @@ pub struct BillCombinedBitcoinKey {
251
252
252
253
#[ derive( Debug , Serialize , Deserialize , ToSchema ) ]
253
254
pub struct SwitchIdentity {
255
+ #[ serde( rename = "type" ) ]
256
+ pub t : IdentityType ,
254
257
pub node_id : String ,
255
258
}
256
259
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use std::env;
2
2
3
3
use super :: middleware:: IdentityCheck ;
4
4
use crate :: external;
5
+ use crate :: service:: identity_service:: IdentityType ;
5
6
use crate :: service:: Result ;
6
7
use crate :: util:: date:: { format_date_string, now} ;
7
8
use crate :: util:: file:: { detect_content_type_for_bytes, UploadFileHandler } ;
@@ -167,11 +168,11 @@ pub async fn change_identity(
167
168
#[ get( "/active" ) ]
168
169
pub async fn active ( state : & State < ServiceContext > ) -> Result < Json < SwitchIdentity > > {
169
170
let current_identity_state = state. get_current_identity ( ) . await ;
170
- let node_id = match current_identity_state. company {
171
- None => current_identity_state. personal ,
172
- Some ( company_node_id) => company_node_id,
171
+ let ( node_id, t ) = match current_identity_state. company {
172
+ None => ( current_identity_state. personal , IdentityType :: Person ) ,
173
+ Some ( company_node_id) => ( company_node_id, IdentityType :: Company ) ,
173
174
} ;
174
- Ok ( Json ( SwitchIdentity { node_id } ) )
175
+ Ok ( Json ( SwitchIdentity { t , node_id } ) )
175
176
}
176
177
177
178
#[ utoipa:: path(
You can’t perform that action at this time.
0 commit comments