Skip to content
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

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e6c170b
Add versioning sort to ReportRepo
fergie-nz Nov 21, 2024
841e2f3
Add code and is_custom filters
fergie-nz Nov 21, 2024
1d1548d
Add only upsert standard reports
fergie-nz Nov 22, 2024
50d3403
Also add check for don't upsert old report versions
fergie-nz Nov 22, 2024
7d3ed26
Fix loop logic
fergie-nz Nov 22, 2024
9cb8f7c
Add code to report node api
fergie-nz Nov 22, 2024
3bc4682
Add version to schema
fergie-nz Nov 22, 2024
9cf6c6b
Add front end mapping
fergie-nz Nov 22, 2024
5a8975c
Add version compare package
fergie-nz Nov 24, 2024
1e94997
Add version compare when comparing version strings
fergie-nz Nov 24, 2024
deeae60
Merge branch 'v2.4.0' into 4791-add-report-versioning
fergie-nz Nov 26, 2024
834f2a2
Remove front end report filtering
fergie-nz Nov 26, 2024
d9240a8
Add get latest report version to service layer
fergie-nz Nov 26, 2024
c7ba894
Remove unnecessary changes
fergie-nz Nov 27, 2024
8b3bed3
Simplify upsert logic
fergie-nz Nov 27, 2024
920bd33
Remove unused repo function
fergie-nz Nov 27, 2024
f494a95
Remove unused imports
fergie-nz Nov 27, 2024
aefe758
Reset formatting
fergie-nz Nov 27, 2024
df99155
Rename to count
fergie-nz Nov 27, 2024
2a11c29
Add mock reports
fergie-nz Nov 27, 2024
a5ccccc
Format reports
fergie-nz Nov 27, 2024
2ee5a38
Add basic filter method scaffold
fergie-nz Nov 27, 2024
89a2a20
Add check for correct version to show
fergie-nz Nov 27, 2024
2808db6
Add sub query for metadata only
fergie-nz Nov 27, 2024
fd484a0
minimise changes in cli
fergie-nz Nov 27, 2024
700e1a4
remove unwanted changes
fergie-nz Nov 27, 2024
916974f
remove unwanted changes
fergie-nz Nov 27, 2024
516f705
Remove unused pagination
fergie-nz Nov 27, 2024
0c66f6a
Rename fields
fergie-nz Nov 27, 2024
9503c67
Add clippy recommendations
fergie-nz Nov 27, 2024
14afadc
Rename variable for ease of understanding
fergie-nz Nov 27, 2024
b618482
Remove unused struct
fergie-nz Nov 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,10 @@ async fn main() -> anyhow::Result<()> {
let version = manifest.version;
let id_version = str::replace(&version, ".", "_");

let id = format!("{code}_{id_version}");
let context = manifest.context;
let report_name = manifest.name;
let is_custom = manifest.is_custom;
let id = format!("{code}_{id_version}_{is_custom}");
let sub_context = manifest.sub_context;
let arguments_path = manifest
.arguments
Expand Down
3 changes: 1 addition & 2 deletions server/graphql/reports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ impl ReportQueries {
&self,
ctx: &Context<'_>,
store_id: String,
page: Option<PaginationInput>,
filter: Option<ReportFilterInput>,
sort: Option<Vec<ReportSortInput>>,
) -> Result<ReportsResponse> {
reports(ctx, store_id, page, filter, sort)
reports(ctx, store_id, filter, sort)
}

/// Creates a generated report.
Expand Down
9 changes: 4 additions & 5 deletions server/graphql/reports/src/reports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ use async_graphql::*;
use graphql_core::standard_graphql_error::StandardGraphqlError;
use graphql_core::{
generic_filters::{EqualFilterStringInput, StringFilterInput},
pagination::PaginationInput,
standard_graphql_error::validate_auth,
};
use graphql_core::{map_filter, ContextExt};
use graphql_types::types::FormSchemaNode;
use repository::{
ContextType as ReportContextDomain, EqualFilter, PaginationOption, Report, ReportFilter,
ReportSort, ReportSortField, StringFilter,
ContextType as ReportContextDomain, EqualFilter, Report, ReportFilter, ReportSort,
ReportSortField, StringFilter,
};
use service::auth::{Resource, ResourceAccessRequest};

Expand Down Expand Up @@ -137,7 +136,6 @@ pub fn report(ctx: &Context<'_>, store_id: String, id: String) -> Result<ReportR
pub fn reports(
ctx: &Context<'_>,
store_id: String,
page: Option<PaginationInput>,
filter: Option<ReportFilterInput>,
sort: Option<Vec<ReportSortInput>>,
) -> Result<ReportsResponse> {
Expand All @@ -156,7 +154,6 @@ pub fn reports(
.report_service
.query_reports(
&service_context,
page.map(PaginationOption::from),
filter.map(|f| f.to_domain()),
sort.and_then(|mut sort_list| sort_list.pop())
.map(|sort| sort.to_domain()),
Expand All @@ -178,6 +175,8 @@ impl ReportFilterInput {
.context
.map(|t| map_filter!(t, ReportContext::to_domain)),
sub_context: self.sub_context.map(EqualFilter::from),
code: None,
is_custom: None,
}
}
}
Expand Down
56 changes: 45 additions & 11 deletions server/repository/src/db_diesel/report.rs
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};
Copy link
Contributor Author

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.

use crate::{EqualFilter, Sort, StringFilter};

use crate::{diesel_macros::apply_string_filter, DBType, RepositoryError};

Expand All @@ -29,6 +28,8 @@ pub struct ReportFilter {
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)]
Expand Down Expand Up @@ -63,6 +64,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 {
Expand Down Expand Up @@ -98,12 +109,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> {
Expand All @@ -118,16 +128,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
.select(ReportMetaDataRow::as_select())
.load::<ReportMetaDataRow>(self.connection.lock().connection())?)
}
}

type BoxedStoreQuery =
Expand All @@ -145,13 +173,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
Expand Down
33 changes: 20 additions & 13 deletions server/repository/src/db_diesel/report_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ impl Default for ReportRow {
}
}

#[derive(Clone, Insertable, Queryable, Debug, PartialEq, Eq, AsChangeset, Selectable)]
#[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,
}
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)
Expand Down
8 changes: 4 additions & 4 deletions server/repository/src/migrations/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ impl PackageJsonAsset {

#[derive(Debug, Clone, PartialEq)]
pub struct Version {
major: i16,
minor: i16,
patch: i16,
pub major: i16,
pub minor: i16,
pub patch: i16,
// RC or TEST etc
pre_release: Option<String>,
}
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Version {
Self::from_str(&PackageJsonAsset::version())
}

pub(crate) fn from_str(version: &str) -> Self {
pub fn from_str(version: &str) -> Self {
let mut version_split = version.split('.');
let major = version_split.next().unwrap();
let minor = version_split.next().unwrap();
Expand Down
28 changes: 24 additions & 4 deletions server/repository/src/mock/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ mod program_indicator;
mod program_order_types;
mod program_requisition_settings;
mod property;
mod reports;
mod rnr_form;
mod sensor;
mod stock_line;
Expand Down Expand Up @@ -100,6 +101,7 @@ pub use program_indicator::*;
pub use program_order_types::*;
pub use program_requisition_settings::*;
pub use property::*;
pub use reports::*;
pub use rnr_form::*;
pub use sensor::*;
pub use stock_line::*;
Expand Down Expand Up @@ -156,10 +158,10 @@ use crate::{
ProgramEnrolmentRowRepository, ProgramIndicatorRow, ProgramIndicatorRowRepository,
ProgramRequisitionOrderTypeRow, ProgramRequisitionOrderTypeRowRepository,
ProgramRequisitionSettingsRow, ProgramRequisitionSettingsRowRepository, ProgramRow,
ProgramRowRepository, PropertyRow, PropertyRowRepository, RequisitionLineRow,
RequisitionLineRowRepository, RequisitionRow, RequisitionRowRepository, ReturnReasonRow,
ReturnReasonRowRepository, RnRFormLineRow, RnRFormLineRowRepository, RnRFormRow,
RnRFormRowRepository, SensorRow, SensorRowRepository, StockLineRowRepository,
ProgramRowRepository, PropertyRow, PropertyRowRepository, ReportRowRepository,
RequisitionLineRow, RequisitionLineRowRepository, RequisitionRow, RequisitionRowRepository,
ReturnReasonRow, ReturnReasonRowRepository, RnRFormLineRow, RnRFormLineRowRepository,
RnRFormRow, RnRFormRowRepository, SensorRow, SensorRowRepository, StockLineRowRepository,
StocktakeLineRowRepository, StocktakeRowRepository, SyncBufferRow, SyncBufferRowRepository,
SyncLogRow, SyncLogRowRepository, TemperatureBreachConfigRow,
TemperatureBreachConfigRowRepository, TemperatureBreachRow, TemperatureBreachRowRepository,
Expand Down Expand Up @@ -245,6 +247,7 @@ pub struct MockData {
pub indicator_columns: Vec<IndicatorColumnRow>,
pub indicator_values: Vec<IndicatorValueRow>,
pub options: Vec<ReasonOptionRow>,
pub reports: Vec<crate::ReportRow>,
}

impl MockData {
Expand Down Expand Up @@ -326,6 +329,7 @@ pub struct MockDataInserts {
pub indicator_columns: bool,
pub indicator_values: bool,
pub options: bool,
pub reports: bool,
}

impl MockDataInserts {
Expand Down Expand Up @@ -396,6 +400,7 @@ impl MockDataInserts {
indicator_columns: true,
indicator_values: true,
options: true,
reports: true,
}
}

Expand Down Expand Up @@ -719,6 +724,11 @@ impl MockDataInserts {
self.options = true;
self
}

pub fn reports(mut self) -> Self {
self.reports = true;
self
}
}

#[derive(Default)]
Expand Down Expand Up @@ -810,6 +820,7 @@ pub(crate) fn all_mock_data() -> MockDataCollection {
indicator_columns: mock_indicator_columns(),
indicator_values: mock_indicator_values(),
options: mock_options(),
reports: mock_reports(),
..Default::default()
},
);
Expand Down Expand Up @@ -1328,6 +1339,13 @@ pub fn insert_mock_data(
repo.upsert_one(row).unwrap();
}
}

if inserts.reports {
let repo = ReportRowRepository::new(connection);
for row in &mock_data.reports {
repo.upsert_one(row).unwrap();
}
}
}
mock_data
}
Expand Down Expand Up @@ -1402,6 +1420,7 @@ impl MockData {
mut indicator_columns,
mut indicator_values,
mut options,
mut reports,
} = other;

self.user_accounts.append(&mut user_accounts);
Expand Down Expand Up @@ -1472,6 +1491,7 @@ impl MockData {
self.indicator_columns.append(&mut indicator_columns);
self.indicator_values.append(&mut indicator_values);
self.options.append(&mut options);
self.reports.append(&mut reports);
self
}
}
Loading