-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4791 add report versioning #5533
Changes from 31 commits
e6c170b
841e2f3
1d1548d
50d3403
7d3ed26
9cb8f7c
3bc4682
9cf6c6b
5a8975c
1e94997
deeae60
834f2a2
d9240a8
c7ba894
8b3bed3
920bd33
f494a95
aefe758
df99155
2a11c29
a5ccccc
2ee5a38
89a2a20
2808db6
fd484a0
700e1a4
916974f
516f705
0c66f6a
9503c67
14afadc
b618482
1ce0ac4
06635a0
914c673
0556fae
682b122
751ac3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
use super::{ | ||
form_schema_row, | ||
form_schema_row::form_schema::dsl as form_schema_dsl, | ||
report_row::{report, report::dsl as report_dsl}, | ||
ContextType, ReportRow, ReportType, StorageConnection, | ||
form_schema_row::{self, form_schema::dsl as form_schema_dsl}, | ||
report_row::report::{self, dsl as report_dsl}, | ||
ContextType, ReportMetaDataRow, ReportRow, ReportType, StorageConnection, | ||
}; | ||
|
||
use crate::{ | ||
diesel_macros::{apply_equal_filter, apply_sort_no_case}, | ||
schema_from_row, FormSchema, FormSchemaRow, | ||
}; | ||
use crate::{EqualFilter, Pagination, Sort, StringFilter}; | ||
use crate::{EqualFilter, Sort, StringFilter}; | ||
|
||
use crate::{diesel_macros::apply_string_filter, DBType, RepositoryError}; | ||
|
||
|
@@ -22,13 +21,20 @@ pub struct Report { | |
pub argument_schema: Option<FormSchema>, | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct ReportMetaData { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. our domain object are composites atm, we don't really copy them (a bit less mapping and less to change when new fields are added) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So should just have Version as another key (of type Version) |
||
pub report_data_row: ReportMetaDataRow, | ||
} | ||
|
||
#[derive(Debug, Clone, Default)] | ||
pub struct ReportFilter { | ||
pub id: Option<EqualFilter<String>>, | ||
pub name: Option<StringFilter>, | ||
pub r#type: Option<EqualFilter<ReportType>>, | ||
pub context: Option<EqualFilter<ContextType>>, | ||
pub sub_context: Option<EqualFilter<String>>, | ||
pub code: Option<EqualFilter<String>>, | ||
pub is_custom: Option<bool>, | ||
} | ||
|
||
#[derive(PartialEq, Debug)] | ||
|
@@ -63,6 +69,16 @@ impl ReportFilter { | |
self.context = Some(filter); | ||
self | ||
} | ||
|
||
pub fn code(mut self, filter: EqualFilter<String>) -> Self { | ||
self.code = Some(filter); | ||
self | ||
} | ||
|
||
pub fn is_custom(mut self, value: bool) -> Self { | ||
self.is_custom = Some(value); | ||
self | ||
} | ||
} | ||
|
||
impl ReportType { | ||
|
@@ -98,12 +114,11 @@ impl<'a> ReportRepository<'a> { | |
} | ||
|
||
pub fn query_by_filter(&self, filter: ReportFilter) -> Result<Vec<Report>, RepositoryError> { | ||
self.query(Pagination::new(), Some(filter), None) | ||
self.query(Some(filter), None) | ||
} | ||
|
||
pub fn query( | ||
&self, | ||
pagination: Pagination, | ||
filter: Option<ReportFilter>, | ||
sort: Option<ReportSort>, | ||
) -> Result<Vec<Report>, RepositoryError> { | ||
|
@@ -118,16 +133,34 @@ impl<'a> ReportRepository<'a> { | |
} | ||
} | ||
} | ||
let result = query | ||
.offset(pagination.offset as i64) | ||
.limit(pagination.limit as i64) | ||
.load::<ReportJoin>(self.connection.lock().connection())?; | ||
let result = query.load::<ReportJoin>(self.connection.lock().connection())?; | ||
|
||
result | ||
.into_iter() | ||
.map(map_report_row_join_to_report) | ||
.collect::<Result<Vec<Report>, RepositoryError>>() | ||
} | ||
|
||
pub fn query_meta_data( | ||
&self, | ||
filter: Option<ReportFilter>, | ||
sort: Option<ReportSort>, | ||
) -> Result<Vec<ReportMetaDataRow>, RepositoryError> { | ||
let mut query = create_filtered_query(filter); | ||
if let Some(sort) = sort { | ||
match sort.key { | ||
ReportSortField::Id => { | ||
apply_sort_no_case!(query, sort, report_dsl::id); | ||
} | ||
ReportSortField::Name => { | ||
apply_sort_no_case!(query, sort, report_dsl::name); | ||
} | ||
} | ||
} | ||
Ok(query | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's so good ! |
||
.select(ReportMetaDataRow::as_select()) | ||
.load::<ReportMetaDataRow>(self.connection.lock().connection())?) | ||
} | ||
} | ||
|
||
type BoxedStoreQuery = | ||
|
@@ -145,13 +178,19 @@ fn create_filtered_query(filter: Option<ReportFilter>) -> BoxedStoreQuery { | |
r#type, | ||
context, | ||
sub_context, | ||
code, | ||
is_custom, | ||
} = f; | ||
|
||
apply_equal_filter!(query, id, report_dsl::id); | ||
apply_string_filter!(query, name, report_dsl::name); | ||
apply_equal_filter!(query, r#type, report_dsl::type_); | ||
apply_equal_filter!(query, context, report_dsl::context); | ||
apply_equal_filter!(query, sub_context, report_dsl::sub_context); | ||
apply_equal_filter!(query, code, report_dsl::code); | ||
if let Some(is_custom) = is_custom { | ||
query = query.filter(report_dsl::is_custom.eq(is_custom)); | ||
} | ||
} | ||
|
||
query | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,26 @@ impl Default for ReportRow { | |
} | ||
} | ||
|
||
#[derive(Clone, Insertable, Queryable, Debug, PartialEq, Eq, AsChangeset, Selectable)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can default here so you don't need to impl default (: |
||
#[diesel(table_name = report)] | ||
pub struct ReportMetaDataRow { | ||
pub id: String, | ||
pub is_custom: bool, | ||
pub version: String, | ||
pub code: String, | ||
} | ||
|
||
impl Default for ReportMetaDataRow { | ||
fn default() -> Self { | ||
Self { | ||
id: Default::default(), | ||
is_custom: true, | ||
version: Default::default(), | ||
code: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
pub struct ReportRowRepository<'a> { | ||
connection: &'a StorageConnection, | ||
} | ||
|
@@ -110,19 +130,6 @@ impl<'a> ReportRowRepository<'a> { | |
Ok(result) | ||
} | ||
|
||
pub fn find_one_by_code_and_version( | ||
&self, | ||
code: &str, | ||
version: &str, | ||
) -> Result<Option<ReportRow>, RepositoryError> { | ||
let result = report_dsl::report | ||
.filter(report_dsl::code.eq(code)) | ||
.filter(report_dsl::version.eq(version)) | ||
.first(self.connection.lock().connection()) | ||
.optional()?; | ||
Ok(result) | ||
} | ||
|
||
Comment on lines
-113
to
-125
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing as not anymore |
||
pub fn upsert_one(&self, row: &ReportRow) -> Result<(), RepositoryError> { | ||
diesel::insert_into(report_dsl::report) | ||
.values(row) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed pagination as we won't use it for these queries.