发布数据版本表添加options列
All checks were successful
build / build-rust (push) Successful in 2m30s

调整草稿及发布数据接口定义
添加发布数据查询和修改接口
This commit is contained in:
soul-walker 2024-09-20 12:31:18 +08:00
parent ed45a08ad7
commit 6ddc4fd110
7 changed files with 237 additions and 65 deletions

View File

@ -38,9 +38,10 @@ impl DraftDataQuery {
&self, &self,
ctx: &Context<'ctx>, ctx: &Context<'ctx>,
paging: PageQueryDto, paging: PageQueryDto,
query: UserDraftDataFilterDto<IscsDataOptions>, mut query: UserDraftDataFilterDto<IscsDataOptions>,
) -> async_graphql::Result<PageDto<DraftIscsDataDto>> { ) -> async_graphql::Result<PageDto<DraftIscsDataDto>> {
let db_accessor = ctx.data::<RtssDbAccessor>()?; let db_accessor = ctx.data::<RtssDbAccessor>()?;
query.data_type = Some(DataType::Iscs);
let paging_result = db_accessor let paging_result = db_accessor
.query_draft_data(query.into(), paging.into()) .query_draft_data(query.into(), paging.into())
.await?; .await?;
@ -51,9 +52,10 @@ impl DraftDataQuery {
&self, &self,
ctx: &Context<'ctx>, ctx: &Context<'ctx>,
paging: PageQueryDto, paging: PageQueryDto,
query: SharedDraftDataFilterDto<IscsDataOptions>, mut query: SharedDraftDataFilterDto<IscsDataOptions>,
) -> async_graphql::Result<PageDto<DraftIscsDataDto>> { ) -> async_graphql::Result<PageDto<DraftIscsDataDto>> {
let db_accessor = ctx.data::<RtssDbAccessor>()?; let db_accessor = ctx.data::<RtssDbAccessor>()?;
query.data_type = Some(DataType::Iscs);
let paging_result = db_accessor let paging_result = db_accessor
.query_draft_data(query.into(), paging.into()) .query_draft_data(query.into(), paging.into())
.await?; .await?;
@ -187,6 +189,7 @@ impl<T: DataOptions> From<CreateDraftDataDto<T>> for rtss_db::CreateDraftData {
pub struct UserDraftDataFilterDto<T: DataOptions> { pub struct UserDraftDataFilterDto<T: DataOptions> {
pub user_id: i32, pub user_id: i32,
pub name: Option<String>, pub name: Option<String>,
/// 数据类型,在某个具体类型查询时不传,传了也不生效
pub data_type: Option<rtss_dto::common::DataType>, pub data_type: Option<rtss_dto::common::DataType>,
pub options: Option<T>, pub options: Option<T>,
pub is_shared: Option<bool>, pub is_shared: Option<bool>,
@ -211,7 +214,8 @@ impl<T: DataOptions> From<UserDraftDataFilterDto<T>> for rtss_db::DraftDataQuery
pub struct SharedDraftDataFilterDto<T: DataOptions> { pub struct SharedDraftDataFilterDto<T: DataOptions> {
pub user_id: Option<i32>, pub user_id: Option<i32>,
pub name: Option<String>, pub name: Option<String>,
pub data_type: Option<rtss_dto::common::DataType>, /// 数据类型,在某个具体类型查询时不传,传了也不生效
pub data_type: Option<DataType>,
pub options: Option<T>, pub options: Option<T>,
} }
@ -252,7 +256,7 @@ impl From<DraftDataFilterDto> for rtss_db::DraftDataQuery {
pub struct DraftDataDto { pub struct DraftDataDto {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
pub data_type: rtss_dto::common::DataType, pub data_type: DataType,
pub options: Option<Value>, pub options: Option<Value>,
/// base64编码的数据 /// base64编码的数据
pub data: Option<String>, pub data: Option<String>,

View File

@ -43,6 +43,10 @@ impl From<PageQueryDto> for rtss_db::common::PageQuery {
#[graphql(concrete(name = "DraftDataPageDto", params(draft_data::DraftDataDto)))] #[graphql(concrete(name = "DraftDataPageDto", params(draft_data::DraftDataDto)))]
#[graphql(concrete(name = "DraftIscsDataPageDto", params(draft_data::DraftIscsDataDto)))] #[graphql(concrete(name = "DraftIscsDataPageDto", params(draft_data::DraftIscsDataDto)))]
#[graphql(concrete(name = "ReleaseDataPageDto", params(release_data::ReleaseDataDto)))] #[graphql(concrete(name = "ReleaseDataPageDto", params(release_data::ReleaseDataDto)))]
#[graphql(concrete(
name = "ReleaseDataVersionPageDto",
params(release_data::ReleaseDataVersionDto)
))]
#[graphql(concrete( #[graphql(concrete(
name = "ReleaseIscsDataPageDto", name = "ReleaseIscsDataPageDto",
params(release_data::ReleaseIscsDataWithoutVersionDto) params(release_data::ReleaseIscsDataWithoutVersionDto)

View File

@ -6,7 +6,9 @@ use rtss_db::{model::ReleaseDataModel, ReleaseDataAccessor, RtssDbAccessor};
use rtss_dto::common::DataType; use rtss_dto::common::DataType;
use serde_json::Value; use serde_json::Value;
use super::common::IscsDataOptions; use crate::apis::draft_data::DraftDataDto;
use super::common::{DataOptions, IscsDataOptions};
use super::{PageDto, PageQueryDto}; use super::{PageDto, PageQueryDto};
#[derive(Default)] #[derive(Default)]
@ -36,16 +38,17 @@ impl ReleaseDataQuery {
&self, &self,
ctx: &Context<'_>, ctx: &Context<'_>,
page: PageQueryDto, page: PageQueryDto,
query: UserReleaseDataFilterDto, mut query: UserReleaseDataFilterDto<IscsDataOptions>,
) -> async_graphql::Result<PageDto<ReleaseIscsDataWithoutVersionDto>> { ) -> async_graphql::Result<PageDto<ReleaseIscsDataWithoutVersionDto>> {
let db_accessor = ctx.data::<RtssDbAccessor>()?; let db_accessor = ctx.data::<RtssDbAccessor>()?;
query.data_type = Some(DataType::Iscs);
let paging = db_accessor let paging = db_accessor
.query_release_data_list(query.into(), page.into()) .query_release_data_list(query.into(), page.into())
.await?; .await?;
Ok(paging.into()) Ok(paging.into())
} }
/// id查询发布数据 /// id查询发布数据及当前使用的版本数据
async fn release_data( async fn release_data(
&self, &self,
ctx: &Context<'_>, ctx: &Context<'_>,
@ -55,6 +58,33 @@ impl ReleaseDataQuery {
let model = db_accessor.query_release_data_with_used_version(id).await?; let model = db_accessor.query_release_data_with_used_version(id).await?;
Ok(model.into()) Ok(model.into())
} }
/// 查询发布数据的版本
async fn release_data_version_paging(
&self,
ctx: &Context<'_>,
data_id: i32,
page: PageQueryDto,
) -> async_graphql::Result<PageDto<ReleaseDataVersionDto>> {
let db_accessor = ctx.data::<RtssDbAccessor>()?;
let paging = db_accessor
.query_release_data_version_list(data_id, page.into())
.await?;
Ok(paging.into())
}
/// 根据id获取发布数据版本详情
async fn release_data_version(
&self,
ctx: &Context<'_>,
version_id: i32,
) -> async_graphql::Result<ReleaseDataVersionDto> {
let db_accessor = ctx.data::<RtssDbAccessor>()?;
let model = db_accessor
.query_release_data_version_by_id(version_id)
.await?;
Ok(model.into())
}
} }
#[Object] #[Object]
@ -87,6 +117,60 @@ impl ReleaseDataMutation {
.await?; .await?;
Ok(result.into()) Ok(result.into())
} }
/// 更新发布数据name
async fn update_release_data_name(
&self,
ctx: &Context<'_>,
id: i32,
name: String,
) -> async_graphql::Result<ReleaseDataDto> {
let db_accessor = ctx.data::<RtssDbAccessor>()?;
let result = db_accessor.update_release_data_name(id, &name).await?;
Ok(result.into())
}
/// 上下架发布数据
async fn update_release_data_published(
&self,
ctx: &Context<'_>,
id: i32,
is_published: bool,
) -> async_graphql::Result<ReleaseDataDto> {
let db_accessor = ctx.data::<RtssDbAccessor>()?;
let result = db_accessor
.set_release_data_published(id, is_published)
.await?;
Ok(result.into())
}
/// 更新发布数据使用的版本
async fn update_release_data_used_version(
&self,
ctx: &Context<'_>,
id: i32,
version_id: i32,
) -> async_graphql::Result<ReleaseDataDto> {
let db_accessor = ctx.data::<RtssDbAccessor>()?;
let result = db_accessor
.set_release_data_used_version(id, version_id)
.await?;
Ok(result.into())
}
/// 从发布数据版本中创建草稿数据
async fn create_draft_data_from_release_data_version(
&self,
ctx: &Context<'_>,
release_data_id: i32,
version_id: i32,
) -> async_graphql::Result<DraftDataDto> {
let db_accessor = ctx.data::<RtssDbAccessor>()?;
let result = db_accessor
.create_draft_from_release_version(release_data_id, version_id)
.await?;
Ok(result.into())
}
} }
#[derive(Debug, InputObject)] #[derive(Debug, InputObject)]
@ -98,15 +182,18 @@ pub struct ReleaseDataFilterDto {
} }
#[derive(Debug, InputObject)] #[derive(Debug, InputObject)]
pub struct UserReleaseDataFilterDto { #[graphql(concrete(name = "UserReleaseIscsDataFilterDto", params(IscsDataOptions)))]
pub struct UserReleaseDataFilterDto<T: DataOptions> {
pub user_id: i32, pub user_id: i32,
pub name: Option<String>, pub name: Option<String>,
/// 数据类型,在某个具体类型查询时不传,传了也不生效
pub data_type: Option<DataType>, pub data_type: Option<DataType>,
pub options: Option<T>,
pub is_published: Option<bool>, pub is_published: Option<bool>,
} }
impl From<UserReleaseDataFilterDto> for rtss_db::ReleaseDataQuery { impl<T: DataOptions> From<UserReleaseDataFilterDto<T>> for rtss_db::ReleaseDataQuery {
fn from(value: UserReleaseDataFilterDto) -> Self { fn from(value: UserReleaseDataFilterDto<T>) -> Self {
Self { Self {
name: value.name, name: value.name,
user_id: Some(value.user_id), user_id: Some(value.user_id),
@ -131,7 +218,7 @@ impl From<ReleaseDataFilterDto> for rtss_db::ReleaseDataQuery {
pub struct ReleaseDataDto { pub struct ReleaseDataDto {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
pub data_type: String, pub data_type: DataType,
pub options: Option<Value>, pub options: Option<Value>,
pub used_version_id: Option<i32>, pub used_version_id: Option<i32>,
pub user_id: i32, pub user_id: i32,
@ -168,6 +255,7 @@ pub struct ReleaseDataWithUsedVersionDto {
pub struct ReleaseDataVersionDto { pub struct ReleaseDataVersionDto {
pub id: i32, pub id: i32,
pub release_data_id: i32, pub release_data_id: i32,
pub options: Option<Value>,
pub description: String, pub description: String,
/// base64编码的数据 /// base64编码的数据
pub data: String, pub data: String,
@ -189,6 +277,7 @@ impl From<ReleaseDataVersionModel> for ReleaseDataVersionDto {
Self { Self {
id: model.id, id: model.id,
release_data_id: model.release_data_id, release_data_id: model.release_data_id,
options: model.options,
description: model.description, description: model.description,
data: BASE64_STANDARD.encode(model.data), data: BASE64_STANDARD.encode(model.data),
user_id: model.user_id, user_id: model.user_id,
@ -202,7 +291,7 @@ impl From<ReleaseDataModel> for ReleaseDataDto {
Self { Self {
id: model.id, id: model.id,
name: model.name, name: model.name,
data_type: model.data_type.to_string(), data_type: DataType::try_from(model.data_type).unwrap(),
options: model.options, options: model.options,
used_version_id: model.used_version_id, used_version_id: model.used_version_id,
user_id: model.user_id, user_id: model.user_id,

View File

@ -163,6 +163,11 @@ impl CreateDraftData {
} }
} }
pub fn with_option_options(mut self, options: Option<Value>) -> Self {
self.options = options;
self
}
pub fn with_options(mut self, options: Value) -> Self { pub fn with_options(mut self, options: Value) -> Self {
self.options = Some(options); self.options = Some(options);
self self

View File

@ -1,5 +1,5 @@
use rtss_dto::common::DataType; use rtss_dto::common::DataType;
use sqlx::types::chrono; use sqlx::{types::chrono, Postgres};
use crate::{ use crate::{
common::{PageQuery, PageResult, Sort, SortOrder, TableColumn}, common::{PageQuery, PageResult, Sort, SortOrder, TableColumn},
@ -41,10 +41,11 @@ pub trait ReleaseDataAccessor {
release_id: i32, release_id: i32,
) -> Result<ReleaseDataModel, DbAccessError>; ) -> Result<ReleaseDataModel, DbAccessError>;
/// 查询发布数据所有版本信息 /// 查询发布数据所有版本信息
async fn query_release_data_versions( async fn query_release_data_version_list(
&self, &self,
release_id: i32, release_id: i32,
) -> Result<Vec<ReleaseDataVersionModel>, DbAccessError>; page: PageQuery,
) -> Result<PageResult<ReleaseDataVersionModel>, DbAccessError>;
/// 根据id查询发布版本数据 /// 根据id查询发布版本数据
async fn query_release_data_version_by_id( async fn query_release_data_version_by_id(
&self, &self,
@ -68,13 +69,13 @@ pub trait ReleaseDataAccessor {
is_published: bool, is_published: bool,
) -> Result<ReleaseDataModel, DbAccessError>; ) -> Result<ReleaseDataModel, DbAccessError>;
/// 设置在使用的版本 /// 设置在使用的版本
async fn set_used_version( async fn set_release_data_used_version(
&self, &self,
release_id: i32, release_id: i32,
version_id: i32, version_id: i32,
) -> Result<ReleaseDataModel, DbAccessError>; ) -> Result<ReleaseDataModel, DbAccessError>;
/// 从指定的版本数据创建草稿 /// 从指定的版本数据创建草稿
async fn create_draft_from_version( async fn create_draft_from_release_version(
&self, &self,
version_id: i32, version_id: i32,
user_id: i32, user_id: i32,
@ -157,6 +158,49 @@ impl ReleaseDataQuery {
} }
} }
pub struct CreateReleaseVersionData {
pub release_data_id: i32,
pub options: Option<serde_json::Value>,
pub data: Vec<u8>,
pub description: String,
pub user_id: i32,
}
impl RtssDbAccessor {
async fn insert_release_data_version<'e, 'c: 'e, E>(
&self,
data: CreateReleaseVersionData,
executor: E,
) -> Result<ReleaseDataVersionModel, DbAccessError>
where
E: 'e + sqlx::Executor<'c, Database = Postgres>,
{
let rdv_table = ReleaseDataVersionColumn::Table.name();
let rdv_insert_columns = format!(
"{}, {}, {}, {}, {}",
ReleaseDataVersionColumn::ReleaseDataId.name(),
ReleaseDataVersionColumn::Options.name(),
ReleaseDataVersionColumn::Data.name(),
ReleaseDataVersionColumn::Description.name(),
ReleaseDataVersionColumn::UserId.name(),
);
let rdv_insert_clause = format!(
"INSERT INTO {rdv_table} ({rdv_insert_columns}) VALUES ($1, $2, $3, $4, $5) RETURNING *",
rdv_table = rdv_table,
rdv_insert_columns = rdv_insert_columns
);
let rdv = sqlx::query_as::<_, ReleaseDataVersionModel>(&rdv_insert_clause)
.bind(data.release_data_id)
.bind(data.options)
.bind(data.data)
.bind(data.description)
.bind(data.user_id)
.fetch_one(executor)
.await?;
Ok(rdv)
}
}
impl ReleaseDataAccessor for RtssDbAccessor { impl ReleaseDataAccessor for RtssDbAccessor {
async fn release_new_from_draft( async fn release_new_from_draft(
&self, &self,
@ -172,6 +216,9 @@ impl ReleaseDataAccessor for RtssDbAccessor {
let mut tx = self.pool.begin().await?; let mut tx = self.pool.begin().await?;
// 查询草稿数据 // 查询草稿数据
let draft = self.query_draft_data_by_id(draft_id).await?; let draft = self.query_draft_data_by_id(draft_id).await?;
if draft.data.is_none() {
return Err(DbAccessError::DataError("草稿数据为空".to_string()));
}
// 创建发布数据 // 创建发布数据
let rd_table = ReleaseDataColumn::Table.name(); let rd_table = ReleaseDataColumn::Table.name();
let rd_insert_columns = format!( let rd_insert_columns = format!(
@ -187,28 +234,22 @@ impl ReleaseDataAccessor for RtssDbAccessor {
let mut rd = sqlx::query_as::<_, ReleaseDataModel>(&rd_insert_clause) let mut rd = sqlx::query_as::<_, ReleaseDataModel>(&rd_insert_clause)
.bind(name) .bind(name)
.bind(draft.data_type as i32) .bind(draft.data_type as i32)
.bind(draft.options) .bind(draft.options.clone())
.bind(draft.user_id) .bind(draft.user_id)
.fetch_one(&mut *tx) .fetch_one(&mut *tx)
.await?; .await?;
// 创建发布数据版本 // 创建发布数据版本
let rdv_table = ReleaseDataVersionColumn::Table.name(); let rdv = self
let rdv_insert_columns = format!( .insert_release_data_version(
"{}, {}, {}, {}", CreateReleaseVersionData {
ReleaseDataVersionColumn::ReleaseDataId.name(), release_data_id: rd.id,
ReleaseDataVersionColumn::Data.name(), options: draft.options.clone(),
ReleaseDataVersionColumn::Description.name(), data: draft.data.unwrap(),
ReleaseDataVersionColumn::UserId.name(), description: description.to_string(),
); user_id: draft.user_id,
let rdv_insert_clause = format!( },
"INSERT INTO {rdv_table} ({rdv_insert_columns}) VALUES ($1, $2, $3, $4) RETURNING *" &mut *tx,
); )
let rdv = sqlx::query_as::<_, ReleaseDataVersionModel>(&rdv_insert_clause)
.bind(rd.id)
.bind(draft.data)
.bind(description)
.bind(draft.user_id)
.fetch_one(&mut *tx)
.await?; .await?;
// 更新发布数据使用的版本 // 更新发布数据使用的版本
let used_version_id = ReleaseDataColumn::UsedVersionId.name(); let used_version_id = ReleaseDataColumn::UsedVersionId.name();
@ -241,6 +282,9 @@ impl ReleaseDataAccessor for RtssDbAccessor {
"草稿未设置默认发布数据".to_string(), "草稿未设置默认发布数据".to_string(),
)); ));
} }
if draft.data.is_none() {
return Err(DbAccessError::DataError("草稿数据为空".to_string()));
}
// 查询默认发布数据 // 查询默认发布数据
let rd = self let rd = self
.query_release_data_by_id(draft.default_release_data_id.unwrap()) .query_release_data_by_id(draft.default_release_data_id.unwrap())
@ -248,23 +292,17 @@ impl ReleaseDataAccessor for RtssDbAccessor {
// 开启事务 // 开启事务
let mut tx = self.pool.begin().await?; let mut tx = self.pool.begin().await?;
// 创建发布数据版本 // 创建发布数据版本
let rdv_table = ReleaseDataVersionColumn::Table.name(); let rdv = self
let rdv_insert_columns = format!( .insert_release_data_version(
"{}, {}, {}, {}", CreateReleaseVersionData {
ReleaseDataVersionColumn::ReleaseDataId.name(), release_data_id: rd.id,
ReleaseDataVersionColumn::Data.name(), options: draft.options.clone(),
ReleaseDataVersionColumn::Description.name(), data: draft.data.unwrap(),
ReleaseDataVersionColumn::UserId.name(), description: description.to_string(),
); user_id: draft.user_id,
let rdv_insert_clause = format!( },
"INSERT INTO {rdv_table} ({rdv_insert_columns}) VALUES ($1, $2, $3, $4) RETURNING *" &mut *tx,
); )
let rdv = sqlx::query_as::<_, ReleaseDataVersionModel>(&rdv_insert_clause)
.bind(rd.id)
.bind(draft.data)
.bind(description)
.bind(draft.user_id)
.fetch_one(&mut *tx)
.await?; .await?;
// 更新发布数据使用的版本 // 更新发布数据使用的版本
let rd_table = ReleaseDataColumn::Table.name(); let rd_table = ReleaseDataColumn::Table.name();
@ -346,17 +384,29 @@ impl ReleaseDataAccessor for RtssDbAccessor {
Ok(rd) Ok(rd)
} }
async fn query_release_data_versions( async fn query_release_data_version_list(
&self, &self,
release_id: i32, release_id: i32,
) -> Result<Vec<ReleaseDataVersionModel>, DbAccessError> { page: PageQuery,
) -> Result<PageResult<ReleaseDataVersionModel>, DbAccessError> {
// 查询发布数据版本 // 查询发布数据版本
let rdv_table = ReleaseDataVersionColumn::Table.name(); let rdv_table = ReleaseDataVersionColumn::Table.name();
// let where_clause = query.build_filter();
let count_clause = format!("SELECT COUNT(*) FROM {rdv_table}");
// 查询总数
let total = sqlx::query_scalar(&count_clause)
.fetch_one(&self.pool)
.await?;
if total == 0 {
return Ok(PageResult::new(0, vec![]));
}
// 查询列除了data列 // 查询列除了data列
let rdv_columns = format!( let rdv_columns = format!(
"{}, {}, {}, {}, {}", "{}, {}, {}, {}, {}, {}",
ReleaseDataVersionColumn::Id.name(), ReleaseDataVersionColumn::Id.name(),
ReleaseDataVersionColumn::ReleaseDataId.name(), ReleaseDataVersionColumn::ReleaseDataId.name(),
ReleaseDataVersionColumn::Options.name(),
ReleaseDataVersionColumn::Description.name(), ReleaseDataVersionColumn::Description.name(),
ReleaseDataVersionColumn::UserId.name(), ReleaseDataVersionColumn::UserId.name(),
ReleaseDataVersionColumn::CreatedAt.name(), ReleaseDataVersionColumn::CreatedAt.name(),
@ -365,14 +415,15 @@ impl ReleaseDataAccessor for RtssDbAccessor {
// 按版本号倒序排序 // 按版本号倒序排序
let sort = Sort::new(ReleaseDataVersionColumn::Id, SortOrder::Desc); let sort = Sort::new(ReleaseDataVersionColumn::Id, SortOrder::Desc);
let order_by_clause = sort.to_order_by_clause(); let order_by_clause = sort.to_order_by_clause();
let paging_clause = page.to_limit_clause();
let rdv_query_clause = format!( let rdv_query_clause = format!(
"SELECT {rdv_columns} FROM {rdv_table} WHERE {rdv_release_id} = $1 {order_by_clause}", "SELECT {rdv_columns} FROM {rdv_table} WHERE {rdv_release_id} = $1 {order_by_clause} {paging_clause}",
); );
let rdv = sqlx::query_as::<_, ReleaseDataVersionModel>(&rdv_query_clause) let data = sqlx::query_as::<_, ReleaseDataVersionModel>(&rdv_query_clause)
.bind(release_id) .bind(release_id)
.fetch_all(&self.pool) .fetch_all(&self.pool)
.await?; .await?;
Ok(rdv) Ok(PageResult::new(total, data))
} }
async fn query_release_data_version_by_id( async fn query_release_data_version_by_id(
@ -456,7 +507,7 @@ impl ReleaseDataAccessor for RtssDbAccessor {
Ok(rd) Ok(rd)
} }
async fn set_used_version( async fn set_release_data_used_version(
&self, &self,
release_id: i32, release_id: i32,
version_id: i32, version_id: i32,
@ -482,7 +533,7 @@ impl ReleaseDataAccessor for RtssDbAccessor {
Ok(rd) Ok(rd)
} }
async fn create_draft_from_version( async fn create_draft_from_release_version(
&self, &self,
version_id: i32, version_id: i32,
user_id: i32, user_id: i32,
@ -497,6 +548,7 @@ impl ReleaseDataAccessor for RtssDbAccessor {
let draft = self let draft = self
.create_draft_data( .create_draft_data(
CreateDraftData::new(&name, DataType::try_from(rd.data_type).unwrap(), user_id) CreateDraftData::new(&name, DataType::try_from(rd.data_type).unwrap(), user_id)
.with_option_options(rdv.options)
.with_data(&rdv.data) .with_data(&rdv.data)
.with_default_release_data_id(rd.id), .with_default_release_data_id(rd.id),
) )
@ -643,7 +695,7 @@ mod tests {
// 设置使用的版本 // 设置使用的版本
let release_data = accessor let release_data = accessor
.set_used_version(release_data.id, version1.id) .set_release_data_used_version(release_data.id, version1.id)
.await?; .await?;
assert_eq!(release_data.used_version_id, Some(version1.id)); assert_eq!(release_data.used_version_id, Some(version1.id));
assert!(release_data.updated_at > release_data.created_at); assert!(release_data.updated_at > release_data.created_at);
@ -651,9 +703,15 @@ mod tests {
// 查询发布数据所有版本 // 查询发布数据所有版本
let versions = accessor let versions = accessor
.query_release_data_versions(release_data.id) .query_release_data_version_list(
release_data.id,
PageQuery {
page: 1,
items_per_page: 10,
},
)
.await?; .await?;
assert_eq!(versions.len(), 2); assert_eq!(versions.total, 2);
println!("查询发布数据所有版本测试成功: {:?}", versions); println!("查询发布数据所有版本测试成功: {:?}", versions);
// 查询发布数据详情 // 查询发布数据详情
@ -665,11 +723,15 @@ mod tests {
// 从版本创建草稿 // 从版本创建草稿
let draft = accessor let draft = accessor
.create_draft_from_version(used_version.id, 1) .create_draft_from_release_version(used_version.id, 1)
.await?; .await?;
assert_eq!(draft.data, Some(used_version.data)); assert_eq!(draft.data, Some(used_version.data));
assert_eq!(draft.default_release_data_id, Some(release_data.id)); assert_eq!(draft.default_release_data_id, Some(release_data.id));
println!("从版本创建草稿测试成功"); assert_eq!(draft.options, used_version.options);
println!(
"从版本创建草稿测试成功: draft_data.options = {:?}",
draft.options
);
// 构造分页查询所需发布数据4个人每人发布2个数据 // 构造分页查询所需发布数据4个人每人发布2个数据
for i in 2..6 { for i in 2..6 {

View File

@ -58,6 +58,7 @@ pub struct ReleaseDataModel {
pub id: i32, pub id: i32,
pub name: String, pub name: String,
pub data_type: i32, pub data_type: i32,
/// 从发布版本复制的选项,主要用于查询
#[sqlx(default)] #[sqlx(default)]
pub options: Option<Value>, pub options: Option<Value>,
pub used_version_id: Option<i32>, pub used_version_id: Option<i32>,
@ -73,6 +74,7 @@ pub(crate) enum ReleaseDataVersionColumn {
Table, Table,
Id, Id,
ReleaseDataId, ReleaseDataId,
Options,
Data, Data,
Description, Description,
UserId, UserId,
@ -84,6 +86,8 @@ pub struct ReleaseDataVersionModel {
pub id: i32, pub id: i32,
pub release_data_id: i32, pub release_data_id: i32,
#[sqlx(default)] #[sqlx(default)]
pub options: Option<Value>,
#[sqlx(default)]
pub data: Vec<u8>, pub data: Vec<u8>,
pub description: String, pub description: String,
pub user_id: i32, pub user_id: i32,
@ -240,6 +244,7 @@ impl TableColumn for ReleaseDataVersionColumn {
ReleaseDataVersionColumn::Table => "rtss.release_data_version", ReleaseDataVersionColumn::Table => "rtss.release_data_version",
ReleaseDataVersionColumn::Id => "id", ReleaseDataVersionColumn::Id => "id",
ReleaseDataVersionColumn::ReleaseDataId => "release_data_id", ReleaseDataVersionColumn::ReleaseDataId => "release_data_id",
ReleaseDataVersionColumn::Options => "options",
ReleaseDataVersionColumn::Data => "data", ReleaseDataVersionColumn::Data => "data",
ReleaseDataVersionColumn::Description => "description", ReleaseDataVersionColumn::Description => "description",
ReleaseDataVersionColumn::UserId => "user_id", ReleaseDataVersionColumn::UserId => "user_id",

View File

@ -89,6 +89,7 @@ CREATE TABLE
rtss.release_data_version ( rtss.release_data_version (
id SERIAL PRIMARY KEY, -- id 自增主键 id SERIAL PRIMARY KEY, -- id 自增主键
release_data_id INT NOT NULL, -- 发布数据id release_data_id INT NOT NULL, -- 发布数据id
options JSONB NULL, -- 数据相关的参数项或配置项
data BYTEA NOT NULL, -- 数据 data BYTEA NOT NULL, -- 数据
description TEXT NOT NULL, -- 版本描述 description TEXT NOT NULL, -- 版本描述
user_id INT NOT NULL, -- 发布用户id user_id INT NOT NULL, -- 发布用户id
@ -110,6 +111,8 @@ COMMENT ON COLUMN rtss.release_data_version.id IS 'id 自增主键';
COMMENT ON COLUMN rtss.release_data_version.release_data_id IS '发布数据id'; COMMENT ON COLUMN rtss.release_data_version.release_data_id IS '发布数据id';
COMMENT ON COLUMN rtss.release_data_version.options IS '数据相关的参数项或配置项';
COMMENT ON COLUMN rtss.release_data_version.data IS '数据'; COMMENT ON COLUMN rtss.release_data_version.data IS '数据';
COMMENT ON COLUMN rtss.release_data_version.description IS '版本描述'; COMMENT ON COLUMN rtss.release_data_version.description IS '版本描述';