feat: add visibility feature to thoughts, including new enum, database migration, and update related endpoints and tests
This commit is contained in:
@@ -1,4 +1,19 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use utoipa::ToSchema;
|
||||
|
||||
#[derive(
|
||||
Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, ToSchema,
|
||||
)]
|
||||
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "thought_visibility")]
|
||||
pub enum Visibility {
|
||||
#[sea_orm(string_value = "public")]
|
||||
Public,
|
||||
#[sea_orm(string_value = "friends_only")]
|
||||
FriendsOnly,
|
||||
#[sea_orm(string_value = "private")]
|
||||
Private,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "thought")]
|
||||
@@ -8,6 +23,7 @@ pub struct Model {
|
||||
pub author_id: Uuid,
|
||||
pub content: String,
|
||||
pub reply_to_id: Option<Uuid>,
|
||||
pub visibility: Visibility,
|
||||
pub created_at: DateTimeWithTimeZone,
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,8 @@ use utoipa::ToSchema;
|
||||
use uuid::Uuid;
|
||||
use validator::Validate;
|
||||
|
||||
use crate::domains::thought::Visibility;
|
||||
|
||||
#[derive(Deserialize, Validate, ToSchema)]
|
||||
pub struct CreateThoughtParams {
|
||||
#[validate(length(
|
||||
@@ -11,6 +13,6 @@ pub struct CreateThoughtParams {
|
||||
message = "Content must be between 1 and 128 characters"
|
||||
))]
|
||||
pub content: String,
|
||||
|
||||
pub visibility: Option<Visibility>,
|
||||
pub reply_to_id: Option<Uuid>,
|
||||
}
|
||||
|
@@ -1,4 +1,7 @@
|
||||
use crate::domains::{thought, user};
|
||||
use crate::domains::{
|
||||
thought::{self, Visibility},
|
||||
user,
|
||||
};
|
||||
use common::DateTimeWithTimeZoneWrapper;
|
||||
use sea_orm::FromQueryResult;
|
||||
use serde::Serialize;
|
||||
@@ -12,6 +15,7 @@ pub struct ThoughtSchema {
|
||||
pub author_username: String,
|
||||
#[schema(example = "This is my first thought! #welcome")]
|
||||
pub content: String,
|
||||
pub visibility: Visibility,
|
||||
pub reply_to_id: Option<Uuid>,
|
||||
pub created_at: DateTimeWithTimeZoneWrapper,
|
||||
}
|
||||
@@ -22,6 +26,7 @@ impl ThoughtSchema {
|
||||
id: thought.id,
|
||||
author_username: author.username.clone(),
|
||||
content: thought.content.clone(),
|
||||
visibility: thought.visibility.clone(),
|
||||
reply_to_id: thought.reply_to_id,
|
||||
created_at: thought.created_at.into(),
|
||||
}
|
||||
@@ -44,6 +49,7 @@ pub struct ThoughtWithAuthor {
|
||||
pub id: Uuid,
|
||||
pub content: String,
|
||||
pub created_at: sea_orm::prelude::DateTimeWithTimeZone,
|
||||
pub visibility: Visibility,
|
||||
pub author_id: Uuid,
|
||||
pub author_username: String,
|
||||
pub reply_to_id: Option<Uuid>,
|
||||
@@ -57,6 +63,7 @@ impl From<ThoughtWithAuthor> for ThoughtSchema {
|
||||
content: model.content,
|
||||
created_at: model.created_at.into(),
|
||||
reply_to_id: model.reply_to_id,
|
||||
visibility: model.visibility,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user