use crate::Date;
use async_graphql::MaybeUndefined;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use crate::auth::UserGroup;
#[derive(Clone, Eq, PartialEq, Hash, Serialize, Deserialize, Debug, async_graphql::NewType)]
pub struct UserId(pub String);
impl From<Uuid> for UserId {
fn from(id: Uuid) -> Self {
UserId(id.to_string())
}
}
impl From<UserId> for Uuid {
fn from(id: UserId) -> Self {
Uuid::parse_str(&id.0).unwrap()
}
}
impl From<&UserId> for Uuid {
fn from(id: &UserId) -> Self {
Uuid::parse_str(&id.0).unwrap()
}
}
#[derive(Clone, Serialize, Deserialize, Debug, async_graphql::SimpleObject)]
#[serde(rename_all = "camelCase")]
pub struct User {
pub id: UserId,
pub display_name: String,
pub created_at: Option<Date>,
pub avatar_url: Option<String>,
pub bio: Option<String>,
pub organization: Option<String>,
pub location: Option<String>,
pub role: Option<UserGroup>,
}
#[derive(async_graphql::InputObject)]
pub struct UserUpdate {
pub id: UserId,
pub display_name: MaybeUndefined<String>,
pub avatar_url: MaybeUndefined<String>,
pub bio: MaybeUndefined<String>,
pub organization: MaybeUndefined<String>,
pub location: MaybeUndefined<String>,
pub role: MaybeUndefined<UserGroup>,
}