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