use http::Method;
use serde::{Deserialize, Serialize};
use crate::{api, auth::Unauthenticated, query::DefaultModel, Endpoint};
#[derive(Clone, Debug, Eq, Ord, Hash, PartialEq, PartialOrd, Serialize)]
pub struct Signup {
pub name: String,
pub email: String,
pub password: String,
}
impl Signup {
pub fn new(
name: impl Into<String>,
email: impl Into<String>,
password: impl Into<String>,
) -> Self {
Self {
name: name.into(),
password: password.into(),
email: email.into(),
}
}
}
impl Endpoint for Signup {
type AccessControl = Unauthenticated;
fn method(&self) -> Method {
Method::POST
}
fn endpoint(&self) -> std::borrow::Cow<'static, str> {
"auth/signup".into()
}
fn body(&self) -> Result<Option<(&'static str, Vec<u8>)>, crate::BodyError> {
Ok(Some((
api::mime_types::JSON,
serde_json::to_string(self)?.into_bytes(),
)))
}
}
impl DefaultModel for Signup {
type Model = NewUser;
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[serde(rename_all = "camelCase")]
pub struct NewUser {
pub id: api::UserId,
pub name: String,
pub email: String,
pub access_token: api::AccessToken,
}