From b58654fd70958d89b344a6f7acac204f67ae9879 Mon Sep 17 00:00:00 2001 From: Tyler Murphy Date: Sat, 28 Jan 2023 18:04:00 -0500 Subject: fmt --- src/types/post.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/types/post.rs') diff --git a/src/types/post.rs b/src/types/post.rs index 95aed0e..90eada2 100644 --- a/src/types/post.rs +++ b/src/types/post.rs @@ -1,10 +1,10 @@ use core::fmt; -use std::collections::HashSet; use serde::Serialize; +use std::collections::HashSet; use tracing::instrument; use crate::database; -use crate::types::http::{Result, ResponseCode}; +use crate::types::http::{ResponseCode, Result}; #[derive(Serialize)] pub struct Post { @@ -13,19 +13,18 @@ pub struct Post { pub content: String, pub likes: HashSet, pub comments: Vec<(u64, String)>, - pub date: u64 + pub date: u64, } impl fmt::Debug for Post { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Post") - .field("post_id", &self.post_id) - .finish() + .field("post_id", &self.post_id) + .finish() } } impl Post { - #[instrument()] pub fn from_post_id(post_id: u64) -> Result { let Ok(Some(post)) = database::posts::get_post(post_id) else { @@ -64,10 +63,10 @@ impl Post { #[instrument()] pub fn comment(&mut self, user_id: u64, content: String) -> Result<()> { self.comments.push((user_id, content)); - + if database::posts::update_post(self.post_id, &self.likes, &self.comments).is_err() { tracing::error!("Failed to comment on post"); - return Err(ResponseCode::InternalServerError.text("Failed to comment on post")) + return Err(ResponseCode::InternalServerError.text("Failed to comment on post")); } Ok(()) @@ -75,19 +74,19 @@ impl Post { #[instrument()] pub fn like(&mut self, user_id: u64, state: bool) -> Result<()> { - if state { self.likes.insert(user_id); } else { self.likes.remove(&user_id); } - + if database::posts::update_post(self.post_id, &self.likes, &self.comments).is_err() { tracing::error!("Failed to change like state on post"); - return Err(ResponseCode::InternalServerError.text("Failed to change like state on post")) + return Err( + ResponseCode::InternalServerError.text("Failed to change like state on post") + ); } Ok(()) } - -} \ No newline at end of file +} -- cgit v1.2.3-freya