Skip to content

Commit

Permalink
🚚 yank更名为delete和mark-deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodjooy committed Oct 31, 2024
1 parent 3192240 commit d141914
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where

fn route(self) -> Router<S> {
Router::new()
.route("/yank", post(Self::yank_version))
.route("/markDelete", post(Self::make_delete_version))
.route("/create", post(Self::new_version))
.route("/all", get(Self::all_version))
.route("/modify", post(Self::modify_description))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
impl crate::ReleaseVersionController {
#[resp_result]
#[instrument(skip_all,fields(version = %arg_1.0))]
pub async fn yank_version(
pub async fn make_delete_version(
logic: CeobeOperationLogic<ReleaseVersionLogic>,
MapReject(QueryReleaseVersion {
version: ValueField(version),
Expand All @@ -34,7 +34,7 @@ impl crate::ReleaseVersionController {
Query<QueryReleaseVersion<ValueField<semver::Version>>>,
>,
) -> Result<()> {
logic.yank(&version, &platform).await?;
logic.mark_deleted(&version, &platform).await?;
Ok(())
}

Expand All @@ -48,9 +48,9 @@ impl crate::ReleaseVersionController {
>,
MapReject(filter): MapRejecter<Json<Option<QueryVersionFilter>>>,
) -> Result<ListWithPageInfo<ReleaseVersion>> {
let QueryVersionFilter { platform, yanked } =
let QueryVersionFilter { platform, deleted } =
filter.unwrap_or_default();
let ret = logic.all(paginator, platform, yanked).await?;
let ret = logic.all(paginator, platform, deleted).await?;

Ok(ret)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ impl Display for QueryReleaseVersion<OptionField<Version>> {
#[derive(Debug, Deserialize, Default)]
pub struct QueryVersionFilter {
pub platform: Option<ReleasePlatform>,
pub yanked: bool,
pub deleted: bool,
}

impl Display for QueryVersionFilter {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match &self.platform {
None => {
write!(f, "{{yanked: {} }}", self.yanked)
write!(f, "{{deleted: {} }}", self.deleted)
}
Some(plat) => {
write!(f, "{{yanked: {}, platform: {}}}", self.yanked, plat)
write!(f, "{{deleted: {}, platform: {}}}", self.deleted, plat)
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions logic/ceobe_operation_logic/src/release_version/implement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ use semver::Version;
use super::{LogicResult, ReleaseVersionLogic, TencentCDNPath};

impl ReleaseVersionLogic {
pub async fn yank(
pub async fn mark_deleted(
&self, version: &Version, platform: &ReleasePlatform,
) -> LogicResult<()> {
self.mongodb
.ceobe()
.operation()
.release_version()
.update()
.yank(platform, version)
.mark_deleted(platform, version)
.await?;

self.tencent_cloud
Expand All @@ -34,36 +34,36 @@ impl ReleaseVersionLogic {

pub async fn all(
&self, paginator: Option<Paginator>,
platform: Option<ReleasePlatform>, yanked: bool,
platform: Option<ReleasePlatform>, deleted: bool,
) -> LogicResult<ListWithPageInfo<ReleaseVersion>> {
let msg = self
.mongodb
.ceobe()
.operation()
.release_version()
.retrieve()
.all(platform, paginator, yanked)
.all(platform, paginator, deleted)
.await?;

match paginator {
Some(paginator) => {
let total = self.count(platform, yanked).await?;
let total = self.count(platform, deleted).await?;
Ok(msg.with_page_info(paginator, total as _))
}
None => Ok(msg.with_plain()),
}
}

async fn count(
&self, platform: Option<ReleasePlatform>, yanked: bool,
&self, platform: Option<ReleasePlatform>, deleted: bool,
) -> LogicResult<usize> {
let count = self
.mongodb
.ceobe()
.operation()
.release_version()
.retrieve()
.total_num(platform, yanked)
.total_num(platform, deleted)
.await?;
Ok(count)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ where
let collection = self.get_collection()?;
let filter = doc! {
"platform":to_bson(&platform)?,
"yanked": false
"deleted": false
};
let sort = doc! {
"$natural": -1i32
Expand All @@ -68,10 +68,10 @@ where

pub async fn all(
&'db self, platform: Option<ReleasePlatform>,
paginate: impl Into<Option<Paginator>>, yanked: bool,
paginate: impl Into<Option<Paginator>>, deleted: bool,
) -> Result<Vec<ReleaseVersion>> {
let collection = self.get_collection()?;
let filter = generate_platform_filter_document(platform, yanked)?;
let filter = generate_platform_filter_document(platform, deleted)?;
let sort = doc! {
"$natural": -1i32
};
Expand Down Expand Up @@ -99,10 +99,10 @@ where
}

pub async fn total_num(
&'db self, platform: Option<ReleasePlatform>, yanked: bool,
&'db self, platform: Option<ReleasePlatform>, deleted: bool,
) -> Result<usize> {
let collection = self.get_collection()?;
let filter = generate_platform_filter_document(platform, yanked)?;
let filter = generate_platform_filter_document(platform, deleted)?;

let ret = collection
.doing(|collection| collection.count_documents(filter, None))
Expand All @@ -113,16 +113,16 @@ where
}

fn generate_platform_filter_document(
platform: Option<ReleasePlatform>, yanked: bool,
platform: Option<ReleasePlatform>, deleted: bool,
) -> Result<Document> {
Ok(match platform {
None => {
doc! {"yanked": yanked}
doc! {"deleted": deleted}
}
Some(plat) => {
doc! {
"platform":to_bson(&plat)?,
"yanked": yanked
"deleted": deleted
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ where
}

/// 撤回一个已经发布的版本
pub async fn yank(
pub async fn mark_deleted(
&'db self, platform: &ReleasePlatform, version: &Version,
) -> Result<()> {
let collection = self.get_collection()?;
let filter = doc! {
"platform": to_bson(platform)?,
"version": to_bson(version)?,
"yanked":false
"deleted":false
};
collection
.doing(|collection| {
collection.find_one_and_update(
filter,
doc! {
"$set":{
"yanked": true
"deleted": true
}
},
None,
Expand Down
1 change: 1 addition & 0 deletions persistence/database/mongo_connection/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl Default for MongoDbConfig {
host: host_default(),
port: port_default(),
db_name: "ceobe_canteen".into(),
query: Default::default(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct ReleaseVersion {
#[builder(via_mutators)]
download_source: Vec<DownloadSourceItem>,
#[builder(default = false)]
yanked: bool,
deleted: bool,
}

#[cfg(test)]
Expand Down

0 comments on commit d141914

Please sign in to comment.