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