Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: derive Default trait #274

Merged
merged 2 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()))
}
}
Loading