feat: implement record commands
This commit is contained in:
1 parent
54346ff20f
commit
56b5abc1d1
6 files changed
+2101
-15
No files matched your search
+262
-1
@@ -1,5 +1,7 @@
|
||||
use onspring::{
|
||||
App, CollectionResponse, Field, OnspringClient, OnspringError, PagedResponse, PagingRequest,
|
||||
App, BatchDeleteRecordsRequest, BatchGetRecordsRequest, CollectionResponse, DataFormat, Field,
|
||||
OnspringClient, OnspringError, PagedResponse, PagingRequest, QueryRecordsRequest, Record,
|
||||
SaveRecordRequest, SaveRecordResponse,
|
||||
};
|
||||
|
||||
pub trait OnspringRunner {
|
||||
@@ -35,6 +37,49 @@ pub trait OnspringRunner {
|
||||
&self,
|
||||
ids: &[i32],
|
||||
) -> impl std::future::Future<Output = Result<CollectionResponse<Field>, OnspringError>> + Send;
|
||||
|
||||
fn list_records(
|
||||
&self,
|
||||
app_id: i32,
|
||||
paging: Option<PagingRequest>,
|
||||
field_ids: Option<&[i32]>,
|
||||
data_format: Option<DataFormat>,
|
||||
) -> impl std::future::Future<Output = Result<PagedResponse<Record>, OnspringError>> + Send;
|
||||
|
||||
fn get_record(
|
||||
&self,
|
||||
app_id: i32,
|
||||
record_id: i32,
|
||||
field_ids: Option<&[i32]>,
|
||||
data_format: Option<DataFormat>,
|
||||
) -> impl std::future::Future<Output = Result<Record, OnspringError>> + Send;
|
||||
|
||||
fn save_record(
|
||||
&self,
|
||||
request: SaveRecordRequest,
|
||||
) -> impl std::future::Future<Output = Result<SaveRecordResponse, OnspringError>> + Send;
|
||||
|
||||
fn delete_record(
|
||||
&self,
|
||||
app_id: i32,
|
||||
record_id: i32,
|
||||
) -> impl std::future::Future<Output = Result<(), OnspringError>> + Send;
|
||||
|
||||
fn batch_get_records(
|
||||
&self,
|
||||
request: BatchGetRecordsRequest,
|
||||
) -> impl std::future::Future<Output = Result<CollectionResponse<Record>, OnspringError>> + Send;
|
||||
|
||||
fn query_records(
|
||||
&self,
|
||||
request: QueryRecordsRequest,
|
||||
paging: Option<PagingRequest>,
|
||||
) -> impl std::future::Future<Output = Result<PagedResponse<Record>, OnspringError>> + Send;
|
||||
|
||||
fn batch_delete_records(
|
||||
&self,
|
||||
request: BatchDeleteRecordsRequest,
|
||||
) -> impl std::future::Future<Output = Result<(), OnspringError>> + Send;
|
||||
}
|
||||
|
||||
impl OnspringRunner for OnspringClient {
|
||||
@@ -72,6 +117,59 @@ impl OnspringRunner for OnspringClient {
|
||||
async fn batch_get_fields(&self, ids: &[i32]) -> Result<CollectionResponse<Field>, OnspringError> {
|
||||
self.batch_get_fields(ids).await
|
||||
}
|
||||
|
||||
async fn list_records(
|
||||
&self,
|
||||
app_id: i32,
|
||||
paging: Option<PagingRequest>,
|
||||
field_ids: Option<&[i32]>,
|
||||
data_format: Option<DataFormat>,
|
||||
) -> Result<PagedResponse<Record>, OnspringError> {
|
||||
self.list_records(app_id, paging, field_ids, data_format).await
|
||||
}
|
||||
|
||||
async fn get_record(
|
||||
&self,
|
||||
app_id: i32,
|
||||
record_id: i32,
|
||||
field_ids: Option<&[i32]>,
|
||||
data_format: Option<DataFormat>,
|
||||
) -> Result<Record, OnspringError> {
|
||||
self.get_record(app_id, record_id, field_ids, data_format).await
|
||||
}
|
||||
|
||||
async fn save_record(
|
||||
&self,
|
||||
request: SaveRecordRequest,
|
||||
) -> Result<SaveRecordResponse, OnspringError> {
|
||||
self.save_record(request).await
|
||||
}
|
||||
|
||||
async fn delete_record(&self, app_id: i32, record_id: i32) -> Result<(), OnspringError> {
|
||||
self.delete_record(app_id, record_id).await
|
||||
}
|
||||
|
||||
async fn batch_get_records(
|
||||
&self,
|
||||
request: BatchGetRecordsRequest,
|
||||
) -> Result<CollectionResponse<Record>, OnspringError> {
|
||||
self.batch_get_records(request).await
|
||||
}
|
||||
|
||||
async fn query_records(
|
||||
&self,
|
||||
request: QueryRecordsRequest,
|
||||
paging: Option<PagingRequest>,
|
||||
) -> Result<PagedResponse<Record>, OnspringError> {
|
||||
self.query_records(request, paging).await
|
||||
}
|
||||
|
||||
async fn batch_delete_records(
|
||||
&self,
|
||||
request: BatchDeleteRecordsRequest,
|
||||
) -> Result<(), OnspringError> {
|
||||
self.batch_delete_records(request).await
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -95,6 +193,32 @@ pub mod testing {
|
||||
pub list_fields_paging: Mutex<Option<Option<PagingRequest>>>,
|
||||
pub get_field_id: Mutex<Option<i32>>,
|
||||
pub batch_get_fields_ids: Mutex<Option<Vec<i32>>>,
|
||||
|
||||
pub list_records_result: Result<PagedResponse<Record>, OnspringError>,
|
||||
pub get_record_result: Result<Record, OnspringError>,
|
||||
pub save_record_result: Result<SaveRecordResponse, OnspringError>,
|
||||
pub delete_record_result: Result<(), OnspringError>,
|
||||
pub batch_get_records_result: Result<CollectionResponse<Record>, OnspringError>,
|
||||
pub query_records_result: Result<PagedResponse<Record>, OnspringError>,
|
||||
pub batch_delete_records_result: Result<(), OnspringError>,
|
||||
|
||||
pub list_records_app_id: Mutex<Option<i32>>,
|
||||
pub list_records_paging: Mutex<Option<Option<PagingRequest>>>,
|
||||
pub list_records_field_ids: Mutex<Option<Option<Vec<i32>>>>,
|
||||
pub list_records_data_format: Mutex<Option<Option<DataFormat>>>,
|
||||
|
||||
pub get_record_app_id: Mutex<Option<i32>>,
|
||||
pub get_record_record_id: Mutex<Option<i32>>,
|
||||
pub get_record_field_ids: Mutex<Option<Option<Vec<i32>>>>,
|
||||
pub get_record_data_format: Mutex<Option<Option<DataFormat>>>,
|
||||
|
||||
pub save_record_request: Mutex<Option<SaveRecordRequest>>,
|
||||
pub delete_record_app_id: Mutex<Option<i32>>,
|
||||
pub delete_record_record_id: Mutex<Option<i32>>,
|
||||
pub batch_get_records_request: Mutex<Option<BatchGetRecordsRequest>>,
|
||||
pub query_records_request: Mutex<Option<QueryRecordsRequest>>,
|
||||
pub query_records_paging: Mutex<Option<Option<PagingRequest>>>,
|
||||
pub batch_delete_records_request: Mutex<Option<BatchDeleteRecordsRequest>>,
|
||||
}
|
||||
|
||||
impl Default for MockClient {
|
||||
@@ -150,6 +274,54 @@ pub mod testing {
|
||||
list_fields_paging: Mutex::new(None),
|
||||
get_field_id: Mutex::new(None),
|
||||
batch_get_fields_ids: Mutex::new(None),
|
||||
|
||||
list_records_result: Ok(PagedResponse {
|
||||
page_number: None,
|
||||
page_size: None,
|
||||
total_pages: None,
|
||||
total_records: None,
|
||||
items: None,
|
||||
}),
|
||||
get_record_result: Ok(Record {
|
||||
app_id: 1,
|
||||
record_id: 1,
|
||||
field_data: None,
|
||||
}),
|
||||
save_record_result: Ok(SaveRecordResponse {
|
||||
id: 1,
|
||||
warnings: None,
|
||||
}),
|
||||
delete_record_result: Ok(()),
|
||||
batch_get_records_result: Ok(CollectionResponse {
|
||||
count: None,
|
||||
items: None,
|
||||
}),
|
||||
query_records_result: Ok(PagedResponse {
|
||||
page_number: None,
|
||||
page_size: None,
|
||||
total_pages: None,
|
||||
total_records: None,
|
||||
items: None,
|
||||
}),
|
||||
batch_delete_records_result: Ok(()),
|
||||
|
||||
list_records_app_id: Mutex::new(None),
|
||||
list_records_paging: Mutex::new(None),
|
||||
list_records_field_ids: Mutex::new(None),
|
||||
list_records_data_format: Mutex::new(None),
|
||||
|
||||
get_record_app_id: Mutex::new(None),
|
||||
get_record_record_id: Mutex::new(None),
|
||||
get_record_field_ids: Mutex::new(None),
|
||||
get_record_data_format: Mutex::new(None),
|
||||
|
||||
save_record_request: Mutex::new(None),
|
||||
delete_record_app_id: Mutex::new(None),
|
||||
delete_record_record_id: Mutex::new(None),
|
||||
batch_get_records_request: Mutex::new(None),
|
||||
query_records_request: Mutex::new(None),
|
||||
query_records_paging: Mutex::new(None),
|
||||
batch_delete_records_request: Mutex::new(None),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -235,5 +407,94 @@ pub mod testing {
|
||||
Err(err) => Err(clone_onspring_error(err)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn list_records(
|
||||
&self,
|
||||
app_id: i32,
|
||||
paging: Option<PagingRequest>,
|
||||
field_ids: Option<&[i32]>,
|
||||
data_format: Option<DataFormat>,
|
||||
) -> Result<PagedResponse<Record>, OnspringError> {
|
||||
*self.list_records_app_id.lock().unwrap() = Some(app_id);
|
||||
*self.list_records_paging.lock().unwrap() = Some(paging);
|
||||
*self.list_records_field_ids.lock().unwrap() = Some(field_ids.map(|ids| ids.to_vec()));
|
||||
*self.list_records_data_format.lock().unwrap() = Some(data_format);
|
||||
match &self.list_records_result {
|
||||
Ok(res) => Ok(res.clone()),
|
||||
Err(err) => Err(clone_onspring_error(err)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn get_record(
|
||||
&self,
|
||||
app_id: i32,
|
||||
record_id: i32,
|
||||
field_ids: Option<&[i32]>,
|
||||
data_format: Option<DataFormat>,
|
||||
) -> Result<Record, OnspringError> {
|
||||
*self.get_record_app_id.lock().unwrap() = Some(app_id);
|
||||
*self.get_record_record_id.lock().unwrap() = Some(record_id);
|
||||
*self.get_record_field_ids.lock().unwrap() = Some(field_ids.map(|ids| ids.to_vec()));
|
||||
*self.get_record_data_format.lock().unwrap() = Some(data_format);
|
||||
match &self.get_record_result {
|
||||
Ok(res) => Ok(res.clone()),
|
||||
Err(err) => Err(clone_onspring_error(err)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn save_record(
|
||||
&self,
|
||||
request: SaveRecordRequest,
|
||||
) -> Result<SaveRecordResponse, OnspringError> {
|
||||
*self.save_record_request.lock().unwrap() = Some(request);
|
||||
match &self.save_record_result {
|
||||
Ok(res) => Ok(res.clone()),
|
||||
Err(err) => Err(clone_onspring_error(err)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn delete_record(&self, app_id: i32, record_id: i32) -> Result<(), OnspringError> {
|
||||
*self.delete_record_app_id.lock().unwrap() = Some(app_id);
|
||||
*self.delete_record_record_id.lock().unwrap() = Some(record_id);
|
||||
match &self.delete_record_result {
|
||||
Ok(()) => Ok(()),
|
||||
Err(err) => Err(clone_onspring_error(err)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn batch_get_records(
|
||||
&self,
|
||||
request: BatchGetRecordsRequest,
|
||||
) -> Result<CollectionResponse<Record>, OnspringError> {
|
||||
*self.batch_get_records_request.lock().unwrap() = Some(request);
|
||||
match &self.batch_get_records_result {
|
||||
Ok(res) => Ok(res.clone()),
|
||||
Err(err) => Err(clone_onspring_error(err)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn query_records(
|
||||
&self,
|
||||
request: QueryRecordsRequest,
|
||||
paging: Option<PagingRequest>,
|
||||
) -> Result<PagedResponse<Record>, OnspringError> {
|
||||
*self.query_records_request.lock().unwrap() = Some(request);
|
||||
*self.query_records_paging.lock().unwrap() = Some(paging);
|
||||
match &self.query_records_result {
|
||||
Ok(res) => Ok(res.clone()),
|
||||
Err(err) => Err(clone_onspring_error(err)),
|
||||
}
|
||||
}
|
||||
|
||||
async fn batch_delete_records(
|
||||
&self,
|
||||
request: BatchDeleteRecordsRequest,
|
||||
) -> Result<(), OnspringError> {
|
||||
*self.batch_delete_records_request.lock().unwrap() = Some(request);
|
||||
match &self.batch_delete_records_result {
|
||||
Ok(()) => Ok(()),
|
||||
Err(err) => Err(clone_onspring_error(err)),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user