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