unify post type member name

This commit is contained in:
postscriptum 2025-07-02 20:40:45 +03:00
parent abbb7f6986
commit 3aba70cb31
2 changed files with 6 additions and 6 deletions

View file

@ -4,7 +4,7 @@ mod tag;
use attachment::Attachment; use attachment::Attachment;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use ptype::Type; use ptype::Ptype;
use serde::{Deserialize, de::Error}; use serde::{Deserialize, de::Error};
use std::str::FromStr; use std::str::FromStr;
use tag::Tag; use tag::Tag;
@ -13,7 +13,7 @@ use tag::Tag;
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]
pub struct Post { pub struct Post {
#[serde(rename = "type", deserialize_with = "ptype")] #[serde(rename = "type", deserialize_with = "ptype")]
pub ptype: Type, pub ptype: Ptype,
pub attachment: Option<Vec<Attachment>>, pub attachment: Option<Vec<Attachment>>,
pub id: String, pub id: String,
#[serde(default, deserialize_with = "time")] #[serde(default, deserialize_with = "time")]
@ -27,13 +27,13 @@ pub struct Post {
impl Post { impl Post {
pub fn is_note(&self) -> bool { pub fn is_note(&self) -> bool {
matches!(self.ptype, Type::Note) matches!(self.ptype, Ptype::Note)
} }
} }
fn ptype<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Type, D::Error> { fn ptype<'de, D: serde::Deserializer<'de>>(d: D) -> Result<Ptype, D::Error> {
if String::deserialize(d)?.to_lowercase() == "note" { if String::deserialize(d)?.to_lowercase() == "note" {
return Ok(Type::Note); return Ok(Ptype::Note);
} }
Err(D::Error::custom("Invalid post type")) Err(D::Error::custom("Invalid post type"))
} }

View file

@ -1,4 +1,4 @@
#[derive(Debug)] #[derive(Debug)]
pub enum Type { pub enum Ptype {
Note, Note,
} }