-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add user id model
1 parent
61202a4
commit 631f51b
Showing
7 changed files
with
68 additions
and
28 deletions.
There are no files selected for viewing
Submodule pubky
updated
from a5dfff to 9131ce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use pkarr::PublicKey; | ||
use serde::{Deserialize, Serialize}; | ||
use std::fmt; | ||
use utoipa::ToSchema; | ||
|
||
/// Represents user data with name, bio, image, links, and status. | ||
#[derive(Serialize, Deserialize, ToSchema, Default, Clone, Debug)] | ||
pub struct UserId(pub String); | ||
|
||
impl UserId { | ||
pub fn try_from(str: &str) -> Result<Self, Box<dyn std::error::Error + Send + Sync>> { | ||
// Validate string is a valid Pkarr public key | ||
PublicKey::try_from(str)?; | ||
Ok(UserId(str.to_string())) | ||
} | ||
} | ||
|
||
impl fmt::Display for UserId { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
impl std::ops::Deref for UserId { | ||
type Target = String; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} | ||
|
||
impl AsRef<str> for UserId { | ||
fn as_ref(&self) -> &str { | ||
&self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters