use http::Method;
use serde::Serialize;
use super::ProjectLocale;
use crate::{
api::{self, locales::LocaleCode, ProjectId},
auth::Authenticated,
query::DefaultModel,
Endpoint,
};
#[derive(Clone, Debug, Eq, Ord, Hash, PartialEq, PartialOrd, Serialize)]
pub struct CreateLocale {
#[serde(skip_serializing)]
pub project: ProjectId,
pub code: LocaleCode,
}
impl CreateLocale {
#[must_use]
pub const fn new(project: ProjectId, code: LocaleCode) -> Self {
Self { project, code }
}
}
impl Endpoint for CreateLocale {
type AccessControl = Authenticated;
fn method(&self) -> Method {
Method::POST
}
fn endpoint(&self) -> std::borrow::Cow<'static, str> {
format!("projects/{}/translations", self.project).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 CreateLocale {
type Model = ProjectLocale;
}