diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 8dfeec4..7e36810 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -1489,9 +1489,9 @@ dependencies = [ "actix-web", "async-trait", "chrono", + "log", "serde", "sqlx", - "tokio", ] [[package]] @@ -2230,21 +2230,9 @@ dependencies = [ "pin-project-lite", "signal-hook-registry", "socket2", - "tokio-macros", "windows-sys 0.52.0", ] -[[package]] -name = "tokio-macros" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "tokio-stream" version = "0.1.17" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 1e8c7b8..5afd97e 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -13,6 +13,7 @@ chrono = "0.4.41" dotenv = "0.15.0" env_logger = "0.11.8" futures = "0.3.31" +log = "0.4.27" serde = { version = "1.0.219", features = ["derive"] } sqlx = { version = "0.8.5", features = [ "chrono", diff --git a/backend/feature/post/Cargo.toml b/backend/feature/post/Cargo.toml index 5815547..052b52c 100644 --- a/backend/feature/post/Cargo.toml +++ b/backend/feature/post/Cargo.toml @@ -7,6 +7,6 @@ edition.workspace = true actix-web.workspace = true async-trait.workspace = true chrono.workspace = true +log.workspace = true serde.workspace = true sqlx.workspace = true -tokio.workspace = true diff --git a/backend/feature/post/src/adapter/delivery.rs b/backend/feature/post/src/adapter/delivery.rs index a8f9aca..98332cd 100644 --- a/backend/feature/post/src/adapter/delivery.rs +++ b/backend/feature/post/src/adapter/delivery.rs @@ -1,3 +1,4 @@ pub mod label_response_dto; pub mod post_controller; pub mod post_info_response_dto; +pub mod post_response_dto; diff --git a/backend/feature/post/src/adapter/delivery/post_controller.rs b/backend/feature/post/src/adapter/delivery/post_controller.rs index c790e4f..b2567e2 100644 --- a/backend/feature/post/src/adapter/delivery/post_controller.rs +++ b/backend/feature/post/src/adapter/delivery/post_controller.rs @@ -3,24 +3,34 @@ use std::sync::Arc; use async_trait::async_trait; use crate::application::{ - error::post_error::PostError, use_case::get_all_post_info_use_case::GetAllPostInfoUseCase, + error::post_error::PostError, + use_case::{ + get_all_post_info_use_case::GetAllPostInfoUseCase, + get_full_post_use_case::GetFullPostUseCase, + }, }; -use super::post_info_response_dto::PostInfoResponseDto; +use super::{post_info_response_dto::PostInfoResponseDto, post_response_dto::PostResponseDto}; #[async_trait] pub trait PostController: Send + Sync { async fn get_all_post_info(&self) -> Result, PostError>; + async fn get_full_post(&self, id: i32) -> Result; } pub struct PostControllerImpl { get_all_post_info_use_case: Arc, + get_full_post_use_case: Arc, } impl PostControllerImpl { - pub fn new(get_all_post_info_use_case: Arc) -> Self { + pub fn new( + get_all_post_info_use_case: Arc, + get_full_post_use_case: Arc, + ) -> Self { Self { get_all_post_info_use_case, + get_full_post_use_case, } } } @@ -39,4 +49,10 @@ impl PostController for PostControllerImpl { post_info_response_dto_list }) } + + async fn get_full_post(&self, id: i32) -> Result { + let result = self.get_full_post_use_case.execute(id).await; + + result.map(PostResponseDto::from) + } } diff --git a/backend/feature/post/src/adapter/delivery/post_response_dto.rs b/backend/feature/post/src/adapter/delivery/post_response_dto.rs new file mode 100644 index 0000000..a4521c3 --- /dev/null +++ b/backend/feature/post/src/adapter/delivery/post_response_dto.rs @@ -0,0 +1,22 @@ +use serde::Serialize; + +use crate::domain::entity::post::Post; + +use super::post_info_response_dto::PostInfoResponseDto; + +#[derive(Serialize)] +pub struct PostResponseDto { + pub id: i32, + pub info: PostInfoResponseDto, + pub content: String, +} + +impl From for PostResponseDto { + fn from(entity: Post) -> Self { + Self { + id: entity.id, + info: PostInfoResponseDto::from(entity.info), + content: entity.content, + } + } +} diff --git a/backend/feature/post/src/adapter/gateway/post_db_service.rs b/backend/feature/post/src/adapter/gateway/post_db_service.rs index 125af5c..a075dd0 100644 --- a/backend/feature/post/src/adapter/gateway/post_db_service.rs +++ b/backend/feature/post/src/adapter/gateway/post_db_service.rs @@ -1,8 +1,12 @@ use async_trait::async_trait; -use crate::{application::error::post_error::PostError, domain::entity::post_info::PostInfo}; +use crate::{ + application::error::post_error::PostError, + domain::entity::{post::Post, post_info::PostInfo}, +}; #[async_trait] pub trait PostDbService: Send + Sync { async fn get_all_post_info(&self) -> Result, PostError>; + async fn get_full_post(&self, id: i32) -> Result; } diff --git a/backend/feature/post/src/adapter/gateway/post_repository_impl.rs b/backend/feature/post/src/adapter/gateway/post_repository_impl.rs index 46e4ea2..ca5403a 100644 --- a/backend/feature/post/src/adapter/gateway/post_repository_impl.rs +++ b/backend/feature/post/src/adapter/gateway/post_repository_impl.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use crate::{ application::{error::post_error::PostError, gateway::post_repository::PostRepository}, - domain::entity::post_info::PostInfo, + domain::entity::{post::Post, post_info::PostInfo}, }; use super::post_db_service::PostDbService; @@ -22,8 +22,10 @@ impl PostRepositoryImpl { #[async_trait] impl PostRepository for PostRepositoryImpl { async fn get_all_post_info(&self) -> Result, PostError> { - self.post_db_service - .get_all_post_info() - .await + self.post_db_service.get_all_post_info().await + } + + async fn get_full_post(&self, id: i32) -> Result { + self.post_db_service.get_full_post(id).await } } diff --git a/backend/feature/post/src/application/error/post_error.rs b/backend/feature/post/src/application/error/post_error.rs index 653e091..e4e659f 100644 --- a/backend/feature/post/src/application/error/post_error.rs +++ b/backend/feature/post/src/application/error/post_error.rs @@ -1,3 +1,4 @@ +#[derive(Debug)] pub enum PostError { DatabaseError(String), NotFound, diff --git a/backend/feature/post/src/application/gateway/post_repository.rs b/backend/feature/post/src/application/gateway/post_repository.rs index 1dd03dc..a3eac42 100644 --- a/backend/feature/post/src/application/gateway/post_repository.rs +++ b/backend/feature/post/src/application/gateway/post_repository.rs @@ -1,8 +1,12 @@ use async_trait::async_trait; -use crate::{application::error::post_error::PostError, domain::entity::post_info::PostInfo}; +use crate::{ + application::error::post_error::PostError, + domain::entity::{post::Post, post_info::PostInfo}, +}; #[async_trait] pub trait PostRepository: Send + Sync { async fn get_all_post_info(&self) -> Result, PostError>; + async fn get_full_post(&self, id: i32) -> Result; } diff --git a/backend/feature/post/src/application/use_case.rs b/backend/feature/post/src/application/use_case.rs index f69db03..2b646ba 100644 --- a/backend/feature/post/src/application/use_case.rs +++ b/backend/feature/post/src/application/use_case.rs @@ -1 +1,2 @@ pub mod get_all_post_info_use_case; +pub mod get_full_post_use_case; diff --git a/backend/feature/post/src/application/use_case/get_full_post_use_case.rs b/backend/feature/post/src/application/use_case/get_full_post_use_case.rs new file mode 100644 index 0000000..fe882b0 --- /dev/null +++ b/backend/feature/post/src/application/use_case/get_full_post_use_case.rs @@ -0,0 +1,30 @@ +use std::sync::Arc; + +use async_trait::async_trait; + +use crate::{ + application::{error::post_error::PostError, gateway::post_repository::PostRepository}, + domain::entity::post::Post, +}; + +#[async_trait] +pub trait GetFullPostUseCase: Send + Sync { + async fn execute(&self, id: i32) -> Result; +} + +pub struct GetFullPostUseCaseImpl { + post_repository: Arc, +} + +impl GetFullPostUseCaseImpl { + pub fn new(post_repository: Arc) -> Self { + Self { post_repository } + } +} + +#[async_trait] +impl GetFullPostUseCase for GetFullPostUseCaseImpl { + async fn execute(&self, id: i32) -> Result { + self.post_repository.get_full_post(id).await + } +} diff --git a/backend/feature/post/src/domain/entity/post_info.rs b/backend/feature/post/src/domain/entity/post_info.rs index ee5f7f9..f24de11 100644 --- a/backend/feature/post/src/domain/entity/post_info.rs +++ b/backend/feature/post/src/domain/entity/post_info.rs @@ -10,3 +10,4 @@ pub struct PostInfo { pub labels: Vec