use http::Method;
use serde::Serialize;
use super::Project;
use crate::{api, auth::Authenticated, query::DefaultModel, Endpoint};
#[derive(Clone, Debug, Eq, Ord, Hash, PartialEq, PartialOrd, Serialize)]
pub struct CreateProject {
pub name: String,
pub description: String,
}
impl CreateProject {
pub fn new(name: impl Into<String>, description: impl Into<String>) -> Self {
Self {
name: name.into(),
description: description.into(),
}
}
}
impl Endpoint for CreateProject {
type AccessControl = Authenticated;
fn method(&self) -> Method {
Method::POST
}
fn endpoint(&self) -> std::borrow::Cow<'static, str> {
"projects".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 CreateProject {
type Model = Project;
}