Skip to content

Commit

Permalink
Merge pull request #224 from Enraged-Dun-Cookie-Development-Team/fix-…
Browse files Browse the repository at this point in the history
…后台公告列表格式错误

🐛 修复后台公告列表格式错误
  • Loading branch information
Goodjooy authored Dec 19, 2024
2 parents 79d8e2b + 2c0b567 commit ab4029b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 14 deletions.
12 changes: 6 additions & 6 deletions logic/ceobe_operation_logic/src/impletements/announcement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ use persistence::{
ceobe_operate::{announcement, ToCeobe, ToCeobeOperation},
mysql::SqlDatabaseOperate,
};
use serde::Serialize;
use tencent_cloud_server::{
cdn::purge_urls_cache::PurgeCachePath, cloud_manager::TencentCloudManager,
};

use super::CeobeOperateLogic;
use crate::{
error::LogicResult,
view::{AnnouncementResp, OperationTcCdnPath},
};
use crate::{error::LogicResult, view::OperationTcCdnPath};

impl CeobeOperateLogic {
/// 获取公告列表
pub async fn get_announcement_list(
pub async fn get_announcement_list<
T: Serialize + From<announcement::Model>,
>(
sql: SqlDatabaseOperate,
) -> LogicResult<Vec<AnnouncementResp>> {
) -> LogicResult<Vec<T>> {
Ok(sql
.ceobe()
.operation()
Expand Down
38 changes: 36 additions & 2 deletions logic/ceobe_operation_logic/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ impl TryInto<ToolLinkResp> for FrontendToolLink {
}

#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
pub struct AnnouncementResp {
pub struct AnnouncementFrontResp {
pub start_time: String,
pub over_time: String,
pub html: String,
pub notice: bool,
}

impl From<announcement::Model> for AnnouncementResp {
impl From<announcement::Model> for AnnouncementFrontResp {
fn from(
announcement::Model {
start_time,
Expand All @@ -104,6 +104,40 @@ impl From<announcement::Model> for AnnouncementResp {
}
}

#[derive(Debug, Clone, Serialize, Deserialize, TypedBuilder)]
pub struct AnnouncementBackResp {
pub start_time: String,
pub over_time: String,
pub content: String,
pub img_url: String,
pub notice: bool,
}

impl From<announcement::Model> for AnnouncementBackResp {
fn from(
announcement::Model {
start_time,
over_time,
content,
img_url,
notice,
..
}: announcement::Model,
) -> Self {
let image = Url::parse(&img_url)
.map(|url| url.to_string())
.unwrap_or_else(|_| format!(r#"/assets/image/{img_url}.png"#));

Self {
start_time: naive_date_time_format(start_time),
over_time: naive_date_time_format(over_time),
content,
img_url: image,
notice,
}
}
}

#[derive(Debug, Clone, Serialize)]
pub struct Resource {
#[serde(rename = "resources")]
Expand Down
11 changes: 8 additions & 3 deletions src/serves/backend/ceobe_operation/announcement/controllers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum_resp_result::resp_try;
use ceobe_operation_logic::{
impletements::CeobeOperateLogic, view::AnnouncementResp,
impletements::CeobeOperateLogic, view::AnnouncementBackResp,
};
use checker::{
prefabs::collect_checkers::iter_checkers::IntoIterChecker, CheckExtract,
Expand Down Expand Up @@ -29,9 +29,14 @@ impl CeobeOperationAnnouncement {
#[instrument(ret, skip(db))]
pub async fn get_announcement_list(
db: SqlDatabaseOperate,
) -> AnnouncementRespResult<Vec<AnnouncementResp>> {
) -> AnnouncementRespResult<Vec<AnnouncementBackResp>> {
resp_try(async {
Ok(CeobeOperateLogic::get_announcement_list(db).await?)
Ok(
CeobeOperateLogic::get_announcement_list::<
AnnouncementBackResp,
>(db)
.await?,
)
})
.await
}
Expand Down
9 changes: 6 additions & 3 deletions src/serves/cdn/ceobe/operation/announcement/controllers.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use axum_resp_result::resp_try;
use ceobe_operation_logic::{
impletements::CeobeOperateLogic, view::AnnouncementResp,
impletements::CeobeOperateLogic, view::AnnouncementFrontResp,
};
use persistence::mysql::SqlDatabaseOperate;
use tracing::instrument;
Expand All @@ -13,9 +13,12 @@ impl CdnOperationAnnouncementFrontend {
#[instrument(ret, skip(db))]
pub async fn get_announcement_list(
db: SqlDatabaseOperate,
) -> AnnouncementRespResult<Vec<AnnouncementResp>> {
) -> AnnouncementRespResult<Vec<AnnouncementFrontResp>> {
resp_try(async {
Ok(CeobeOperateLogic::get_announcement_list(db).await?)
Ok(CeobeOperateLogic::get_announcement_list::<
AnnouncementFrontResp,
>(db)
.await?)
})
.await
}
Expand Down

0 comments on commit ab4029b

Please sign in to comment.