BLOG-43 feat: post info usecase
All checks were successful
Frontend CI / build (push) Successful in 1m29s

This commit is contained in:
SquidSpirit 2025-05-05 06:40:03 +08:00
parent 74d709b036
commit c08bc659b9
34 changed files with 705 additions and 5 deletions

View File

@ -1,6 +1,11 @@
{
"cSpell.words": [
"actix",
"chrono",
"serde",
"squidspirit"
],
"java.project.sourcePaths": [
"backend/feature/post/src"
]
}

368
backend/Cargo.lock generated
View File

@ -224,6 +224,82 @@ dependencies = [
"alloc-no-stdlib",
]
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
dependencies = [
"anstyle",
"once_cell",
"windows-sys 0.59.0",
]
[[package]]
name = "async-trait"
version = "0.1.88"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "autocfg"
version = "1.4.0"
@ -287,6 +363,12 @@ dependencies = [
"alloc-stdlib",
]
[[package]]
name = "bumpalo"
version = "3.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
[[package]]
name = "bytes"
version = "1.10.1"
@ -319,6 +401,26 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-link",
]
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "cookie"
version = "0.16.2"
@ -330,6 +432,12 @@ dependencies = [
"version_check",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "cpufeatures"
version = "0.2.17"
@ -418,6 +526,29 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "env_filter"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.11.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"jiff",
"log",
]
[[package]]
name = "equivalent"
version = "1.0.2"
@ -561,6 +692,30 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
[[package]]
name = "iana-time-zone"
version = "0.1.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"log",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "icu_collections"
version = "1.5.0"
@ -716,12 +871,42 @@ dependencies = [
"hashbrown",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itoa"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
[[package]]
name = "jiff"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07d8d955d798e7a4d6f9c58cd1f1916e790b42b092758a9ef6e16fef9f1b3fd"
dependencies = [
"jiff-static",
"log",
"portable-atomic",
"portable-atomic-util",
"serde",
]
[[package]]
name = "jiff-static"
version = "0.2.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f244cfe006d98d26f859c7abd1318d85327e1882dc9cef80f62daeeb0adcf300"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "jobserver"
version = "0.1.33"
@ -732,6 +917,16 @@ dependencies = [
"libc",
]
[[package]]
name = "js-sys"
version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [
"once_cell",
"wasm-bindgen",
]
[[package]]
name = "language-tags"
version = "0.3.2"
@ -813,7 +1008,7 @@ dependencies = [
"libc",
"log",
"wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@ -822,6 +1017,15 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
[[package]]
name = "num-traits"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "object"
version = "0.36.7"
@ -884,11 +1088,29 @@ version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]]
name = "portable-atomic"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
[[package]]
name = "portable-atomic-util"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507"
dependencies = [
"portable-atomic",
]
[[package]]
name = "post"
version = "0.1.1"
dependencies = [
"actix-web",
"async-trait",
"chrono",
"serde",
]
[[package]]
@ -1009,6 +1231,12 @@ version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "rustversion"
version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
[[package]]
name = "ryu"
version = "1.0.20"
@ -1070,6 +1298,8 @@ name = "server"
version = "0.1.1"
dependencies = [
"actix-web",
"env_logger",
"post",
]
[[package]]
@ -1120,7 +1350,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef"
dependencies = [
"libc",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@ -1206,7 +1436,7 @@ dependencies = [
"pin-project-lite",
"signal-hook-registry",
"socket2",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@ -1295,6 +1525,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "version_check"
version = "0.9.5"
@ -1316,6 +1552,123 @@ dependencies = [
"wit-bindgen-rt",
]
[[package]]
name = "wasm-bindgen"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [
"cfg-if",
"once_cell",
"rustversion",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
]
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
dependencies = [
"unicode-ident",
]
[[package]]
name = "windows-core"
version = "0.61.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link",
"windows-result",
"windows-strings",
]
[[package]]
name = "windows-implement"
version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-interface"
version = "0.59.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-link"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
[[package]]
name = "windows-result"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-strings"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
@ -1325,6 +1678,15 @@ dependencies = [
"windows-targets",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets",
]
[[package]]
name = "windows-targets"
version = "0.52.6"

View File

@ -8,3 +8,10 @@ edition = "2024"
[workspace.dependencies]
actix-web = "4.10.2"
async-trait = "0.1.88"
chrono = "0.4.41"
env_logger = "0.11.8"
serde = { version = "1.0.219", features = ["derive"] }
server.path = "server"
post.path = "feature/post"

View File

@ -5,3 +5,6 @@ edition.workspace = true
[dependencies]
actix-web.workspace = true
async-trait.workspace = true
chrono.workspace = true
serde.workspace = true

View File

@ -0,0 +1,2 @@
pub mod controller;
pub mod gateway;

View File

@ -0,0 +1,3 @@
pub mod label_response_dto;
pub mod post_controller;
pub mod post_info_response_dto;

View File

@ -0,0 +1,21 @@
use serde::Serialize;
use crate::domain::entity::label::Label;
#[derive(Serialize)]
pub struct LabelResponseDto {
pub id: u32,
pub name: String,
pub color: String,
}
impl From<Label> for LabelResponseDto {
fn from(entity: Label) -> Self {
Self {
id: entity.id,
name: entity.name,
color: entity.color,
}
}
}

View File

@ -0,0 +1,42 @@
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,
};
use super::post_info_response_dto::PostInfoResponseDto;
#[async_trait]
pub trait PostController: Send + Sync {
async fn get_all_post_info(&self) -> Result<Vec<PostInfoResponseDto>, PostError>;
}
pub struct PostControllerImpl {
get_all_post_info_use_case: Arc<dyn GetAllPostInfoUseCase>,
}
impl PostControllerImpl {
pub fn new(get_all_post_info_use_case: Arc<dyn GetAllPostInfoUseCase>) -> Self {
Self {
get_all_post_info_use_case,
}
}
}
#[async_trait]
impl PostController for PostControllerImpl {
async fn get_all_post_info(&self) -> Result<Vec<PostInfoResponseDto>, PostError> {
let result = self.get_all_post_info_use_case.execute().await;
result.map(|post_info_list| {
let post_info_response_dto_list: Vec<PostInfoResponseDto> = post_info_list
.into_iter()
.map(|post_info| PostInfoResponseDto::from(post_info))
.collect();
post_info_response_dto_list
})
}
}

View File

@ -0,0 +1,32 @@
use serde::Serialize;
use crate::domain::entity::post_info::PostInfo;
use super::label_response_dto::LabelResponseDto;
#[derive(Serialize)]
pub struct PostInfoResponseDto {
pub id: u32,
pub title: String,
pub description: String,
pub preview_image_url: String,
pub labels: Vec<LabelResponseDto>,
pub published_time: i64,
}
impl From<PostInfo> for PostInfoResponseDto {
fn from(entity: PostInfo) -> Self {
Self {
id: entity.id,
title: entity.title,
description: entity.description,
preview_image_url: entity.preview_image_url,
labels: entity
.labels
.into_iter()
.map(LabelResponseDto::from)
.collect(),
published_time: entity.published_time.timestamp_micros(),
}
}
}

View File

@ -0,0 +1,2 @@
pub mod post_db_service;
pub mod post_repository_impl;

View File

@ -0,0 +1,8 @@
use async_trait::async_trait;
use crate::{application::error::post_error::PostError, domain::entity::post_info::PostInfo};
#[async_trait]
pub trait PostDbService: Send + Sync {
async fn get_all_post_info(&self) -> Result<Vec<PostInfo>, PostError>;
}

View File

@ -0,0 +1,29 @@
use std::sync::Arc;
use async_trait::async_trait;
use crate::{
application::{error::post_error::PostError, gateway::post_repository::PostRepository},
domain::entity::post_info::PostInfo,
};
use super::post_db_service::PostDbService;
pub struct PostRepositoryImpl {
post_db_service: Arc<dyn PostDbService>,
}
impl PostRepositoryImpl {
pub fn new(post_db_service: Arc<dyn PostDbService>) -> Self {
Self { post_db_service }
}
}
#[async_trait]
impl PostRepository for PostRepositoryImpl {
async fn get_all_post_info(&self) -> Result<Vec<PostInfo>, PostError> {
self.post_db_service
.get_all_post_info()
.await
}
}

View File

@ -0,0 +1,3 @@
pub mod error;
pub mod gateway;
pub mod use_case;

View File

@ -0,0 +1 @@
pub mod post_error;

View File

@ -0,0 +1 @@
pub enum PostError {}

View File

@ -0,0 +1 @@
pub mod post_repository;

View File

@ -0,0 +1,8 @@
use async_trait::async_trait;
use crate::{application::error::post_error::PostError, domain::entity::post_info::PostInfo};
#[async_trait]
pub trait PostRepository: Send + Sync {
async fn get_all_post_info(&self) -> Result<Vec<PostInfo>, PostError>;
}

View File

@ -0,0 +1 @@
pub mod get_all_post_info_use_case;

View File

@ -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_info::PostInfo,
};
#[async_trait]
pub trait GetAllPostInfoUseCase: Send + Sync {
async fn execute(&self) -> Result<Vec<PostInfo>, PostError>;
}
pub struct GetAllPostInfoUseCaseImpl {
post_repository: Arc<dyn PostRepository>,
}
impl GetAllPostInfoUseCaseImpl {
pub fn new(post_repository: Arc<dyn PostRepository>) -> Self {
Self { post_repository }
}
}
#[async_trait]
impl GetAllPostInfoUseCase for GetAllPostInfoUseCaseImpl {
async fn execute(&self) -> Result<Vec<PostInfo>, PostError> {
self.post_repository.get_all_post_info().await
}
}

View File

@ -0,0 +1 @@
pub mod entity;

View File

@ -0,0 +1,3 @@
pub mod label;
pub mod post_info;
pub mod post;

View File

@ -0,0 +1,5 @@
pub struct Label {
pub id: u32,
pub name: String,
pub color: String,
}

View File

@ -0,0 +1,7 @@
use super::post_info::PostInfo;
pub struct Post {
pub id: u32,
pub info: PostInfo,
pub content: String,
}

View File

@ -0,0 +1,12 @@
use chrono::{DateTime, Utc};
use super::label::Label;
pub struct PostInfo {
pub id: u32,
pub title: String,
pub description: String,
pub preview_image_url: String,
pub labels: Vec<Label>,
pub published_time: DateTime<Utc>,
}

View File

@ -0,0 +1,2 @@
pub mod db;
pub mod web;

View File

@ -0,0 +1 @@
pub mod post_db_service_impl;

View File

@ -0,0 +1,31 @@
use std::str::FromStr;
use async_trait::async_trait;
use chrono::DateTime;
use crate::{
adapter::gateway::post_db_service::PostDbService, application::error::post_error::PostError,
domain::entity::post_info::PostInfo,
};
pub struct PostDbServiceImpl {}
impl PostDbServiceImpl {
pub fn new() -> Self {
Self {}
}
}
#[async_trait]
impl PostDbService for PostDbServiceImpl {
async fn get_all_post_info(&self) -> Result<Vec<PostInfo>, PostError> {
Ok(vec![PostInfo {
id: 1,
title: "Post 1".to_string(),
description: "Description of post 1".to_string(),
preview_image_url: "http://example.com/image1.jpg".to_string(),
labels: vec![],
published_time: DateTime::from_str("2023-10-01T12:00:00Z").unwrap(),
}])
}
}

View File

@ -0,0 +1 @@
pub mod post_web_routes;

View File

@ -0,0 +1,18 @@
use std::sync::Arc;
use actix_web::{HttpResponse, Responder, web};
use crate::adapter::controller::post_controller::PostController;
pub fn configure_post_routes(cfg: &mut web::ServiceConfig) {
cfg.service(web::resource("/post_info").route(web::get().to(get_all_post_info)));
}
async fn get_all_post_info(post_controller: web::Data<Arc<dyn PostController>>) -> impl Responder {
let result = post_controller.get_all_post_info().await;
match result {
Ok(post_info_list) => HttpResponse::Ok().json(post_info_list),
Err(_) => HttpResponse::InternalServerError().finish(),
}
}

View File

@ -0,0 +1,4 @@
pub mod adapter;
pub mod application;
pub mod domain;
pub mod framework;

View File

@ -5,3 +5,6 @@ edition.workspace = true
[dependencies]
actix-web.workspace = true
env_logger.workspace = true
post.workspace = true

View File

@ -0,0 +1,25 @@
use std::sync::Arc;
use post::{
adapter::{
controller::post_controller::{PostController, PostControllerImpl},
gateway::post_repository_impl::PostRepositoryImpl,
},
application::use_case::get_all_post_info_use_case::GetAllPostInfoUseCaseImpl,
framework::db::post_db_service_impl::PostDbServiceImpl,
};
pub struct Controllers {
pub post_controller: Arc<dyn PostController>,
}
impl Controllers {
pub fn new() -> Self {
let post_db_service = Arc::new(PostDbServiceImpl::new());
let post_repository = Arc::new(PostRepositoryImpl::new(post_db_service));
let get_all_post_info_use_case = Arc::new(GetAllPostInfoUseCaseImpl::new(post_repository));
let post_controller = Arc::new(PostControllerImpl::new(get_all_post_info_use_case));
Self { post_controller }
}
}

View File

@ -0,0 +1 @@
pub mod controllers;

View File

@ -1,9 +1,34 @@
use actix_web::{App, HttpResponse, HttpServer, web};
use actix_web::{
App, Error, HttpServer,
body::MessageBody,
dev::{ServiceFactory, ServiceRequest, ServiceResponse},
web,
};
use post::framework::web::post_web_routes::configure_post_routes;
use server::controllers::Controllers;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new().route("/", web::get().to(HttpResponse::Ok)))
env_logger::init();
HttpServer::new(create_app)
.bind(("127.0.0.1", 8080))?
.run()
.await
}
fn create_app() -> App<
impl ServiceFactory<
ServiceRequest,
Response = ServiceResponse<impl MessageBody>,
Config = (),
InitError = (),
Error = Error,
>,
> {
let controllers = Controllers::new();
App::new()
.app_data(web::Data::new(controllers.post_controller))
.configure(configure_post_routes)
}