lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

nostr_profile.rs (4763B)


      1 use radroots_types::types::{IResult, IResultList};
      2 use serde::{Deserialize, Serialize};
      3 use serde_json::Value;
      4 #[derive(Serialize, Deserialize)]
      5 pub struct NostrProfile {
      6     pub id: String,
      7     pub created_at: String,
      8     pub updated_at: String,
      9     pub public_key: String,
     10     pub profile_type: String,
     11     pub name: String,
     12     pub display_name: Option<String>,
     13     pub about: Option<String>,
     14     pub website: Option<String>,
     15     pub picture: Option<String>,
     16     pub banner: Option<String>,
     17     pub nip05: Option<String>,
     18     pub lud06: Option<String>,
     19     pub lud16: Option<String>,
     20 }
     21 #[derive(Clone, Deserialize, Serialize)]
     22 pub struct INostrProfileFields {
     23     pub public_key: String,
     24     pub profile_type: String,
     25     pub name: String,
     26     pub display_name: Option<String>,
     27     pub about: Option<String>,
     28     pub website: Option<String>,
     29     pub picture: Option<String>,
     30     pub banner: Option<String>,
     31     pub nip05: Option<String>,
     32     pub lud06: Option<String>,
     33     pub lud16: Option<String>,
     34 }
     35 #[derive(Clone, Deserialize, Serialize)]
     36 pub struct INostrProfileFieldsPartial {
     37     pub public_key: Option<serde_json::Value>,
     38     pub profile_type: Option<serde_json::Value>,
     39     pub name: Option<serde_json::Value>,
     40     pub display_name: Option<serde_json::Value>,
     41     pub about: Option<serde_json::Value>,
     42     pub website: Option<serde_json::Value>,
     43     pub picture: Option<serde_json::Value>,
     44     pub banner: Option<serde_json::Value>,
     45     pub nip05: Option<serde_json::Value>,
     46     pub lud06: Option<serde_json::Value>,
     47     pub lud16: Option<serde_json::Value>,
     48 }
     49 #[derive(Clone, Deserialize, Serialize)]
     50 pub struct INostrProfileFieldsFilter {
     51     pub id: Option<String>,
     52     pub created_at: Option<String>,
     53     pub updated_at: Option<String>,
     54     pub public_key: Option<String>,
     55     pub profile_type: Option<String>,
     56     pub name: Option<String>,
     57     pub display_name: Option<String>,
     58     pub about: Option<String>,
     59     pub website: Option<String>,
     60     pub picture: Option<String>,
     61     pub banner: Option<String>,
     62     pub nip05: Option<String>,
     63     pub lud06: Option<String>,
     64     pub lud16: Option<String>,
     65 }
     66 #[derive(Clone, Deserialize, Serialize)]
     67 #[serde(untagged)]
     68 pub enum NostrProfileQueryBindValues {
     69     Id { id: String },
     70     PublicKey { public_key: String },
     71 }
     72 impl NostrProfileQueryBindValues {
     73     pub fn to_filter_param(&self) -> (&'static str, Value) {
     74         match self {
     75             Self::Id { id } => ("id", Value::from(id.clone())),
     76             Self::PublicKey { public_key } => ("public_key", Value::from(public_key.clone())),
     77         }
     78     }
     79 
     80     pub fn primary_key(&self) -> Option<String> {
     81         match self {
     82             Self::Id { id } => Some(id.clone()),
     83             _ => None,
     84         }
     85     }
     86 
     87     pub fn lookup_key(&self) -> String {
     88         match self {
     89             Self::Id { id } => id.clone(),
     90             Self::PublicKey { public_key } => public_key.clone(),
     91         }
     92     }
     93 }
     94 #[derive(Clone, Deserialize, Serialize)]
     95 pub struct NostrProfileRelayArgs {
     96     pub id: String,
     97 }
     98 
     99 #[derive(Clone, Deserialize, Serialize)]
    100 pub enum NostrProfileFindManyRel {
    101     #[serde(rename = "on_relay")]
    102     OnRelay(NostrProfileRelayArgs),
    103     #[serde(rename = "off_relay")]
    104     OffRelay(NostrProfileRelayArgs),
    105 }
    106 
    107 pub struct INostrProfileCreateTs;
    108 pub type INostrProfileCreate = INostrProfileFields;
    109 pub struct INostrProfileCreateResolveTs;
    110 pub type INostrProfileCreateResolve = IResult<NostrProfile>;
    111 #[derive(Deserialize, Serialize)]
    112 pub struct INostrProfileFindOneArgs {
    113     pub on: NostrProfileQueryBindValues,
    114 }
    115 
    116 #[derive(Deserialize, Serialize)]
    117 pub struct INostrProfileFindOneRelArgs {
    118     pub rel: NostrProfileFindManyRel,
    119 }
    120 
    121 #[derive(Deserialize, Serialize)]
    122 #[serde(untagged)]
    123 pub enum INostrProfileFindOne {
    124     On(INostrProfileFindOneArgs),
    125     Rel(INostrProfileFindOneRelArgs),
    126 }
    127 
    128 pub struct INostrProfileFindOneResolveTs;
    129 pub type INostrProfileFindOneResolve = IResult<Option<NostrProfile>>;
    130 #[derive(Deserialize, Serialize)]
    131 #[serde(untagged)]
    132 pub enum INostrProfileFindMany {
    133     Filter {
    134         filter: Box<Option<INostrProfileFieldsFilter>>,
    135     },
    136     Rel {
    137         rel: NostrProfileFindManyRel,
    138     },
    139 }
    140 pub struct INostrProfileFindManyResolveTs;
    141 pub type INostrProfileFindManyResolve = IResultList<NostrProfile>;
    142 pub struct INostrProfileDeleteTs;
    143 pub type INostrProfileDelete = INostrProfileFindOne;
    144 pub struct INostrProfileDeleteResolveTs;
    145 pub type INostrProfileDeleteResolve = IResult<String>;
    146 #[derive(Deserialize, Serialize)]
    147 pub struct INostrProfileUpdateArgs {
    148     pub on: NostrProfileQueryBindValues,
    149     pub fields: INostrProfileFieldsPartial,
    150 }
    151 pub type INostrProfileUpdate = INostrProfileUpdateArgs;
    152 pub struct INostrProfileUpdateResolveTs;
    153 pub type INostrProfileUpdateResolve = IResult<NostrProfile>;