Skip to content

Commit

Permalink
chore: derive Default trait (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
tipogi authored Jan 2, 2025
1 parent fae1d6d commit 31fe413
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 40 deletions.
12 changes: 1 addition & 11 deletions src/models/post/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,12 @@ impl StreamSource {
}
}

#[derive(Serialize, Deserialize, ToSchema, Debug)]
#[derive(Serialize, Deserialize, ToSchema, Debug, Default)]
pub struct PostStream(pub Vec<PostView>);

impl RedisOps for PostStream {}

impl Default for PostStream {
fn default() -> Self {
Self::new()
}
}

impl PostStream {
pub fn new() -> Self {
Self(Vec::new())
}

pub async fn get_posts(
source: StreamSource,
pagination: Pagination,
Expand Down
32 changes: 3 additions & 29 deletions src/models/user/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,22 @@ use serde::{Deserialize, Serialize};
use utoipa::ToSchema;

/// Represents a tag with its tag label, count, and author sources.
#[derive(Serialize, Deserialize, ToSchema)]
#[derive(Serialize, Deserialize, ToSchema, Default)]
pub struct ProfileTag {
label: String,
count: u32,
by: Vec<UserDetails>,
}

impl Default for ProfileTag {
fn default() -> Self {
Self::new()
}
}

impl ProfileTag {
pub fn new() -> Self {
Self {
label: String::new(),
count: 0,
by: vec![UserDetails::default()],
}
}
}

/// Represents a collection of ProfileTag.
#[derive(Serialize, Deserialize, ToSchema)]
#[derive(Serialize, Deserialize, ToSchema, Default)]
pub struct UserTags {
tags: Vec<ProfileTag>,
}

impl Default for UserTags {
fn default() -> Self {
Self::new()
}
}

impl UserTags {
pub fn new() -> Self {
Self { tags: Vec::new() }
}

/// TODO: Retrieves tags by user ID, currently returns an empty instance.
pub async fn get_by_id(_user_id: &str) -> Result<Option<Self>, Box<dyn std::error::Error>> {
Ok(Some(Self::new()))
Ok(Some(Self::default()))
}
}

0 comments on commit 31fe413

Please sign in to comment.