diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/domain/entity/metric/DashboardEntity.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/domain/entity/metric/DashboardEntity.java index fe06612c..524131df 100644 --- a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/domain/entity/metric/DashboardEntity.java +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/domain/entity/metric/DashboardEntity.java @@ -9,6 +9,7 @@ import lombok.Getter; import lombok.NoArgsConstructor; import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.Validable; +import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.metric.MetricEnum; import org.springframework.data.domain.Persistable; @Getter @@ -16,7 +17,7 @@ @AllArgsConstructor @Builder @Entity -@Table(name = "dashboard") +@Table(name = "accounting_core_dashboards") public class DashboardEntity{ @Id @@ -25,5 +26,10 @@ public class DashboardEntity{ private String name; private String description; - private String userID; + private Double xPos; + private Double yPos; + private Double width; + private Double height; + private MetricEnum metric; + private MetricEnum.SubMetric subMetric; } diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/mapper/DashboardViewToEntity.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/mapper/DashboardViewToEntity.java new file mode 100644 index 00000000..9e829bdf --- /dev/null +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/mapper/DashboardViewToEntity.java @@ -0,0 +1,16 @@ +package org.cardanofoundation.lob.app.accounting_reporting_core.mapper; + +import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.metric.DashboardEntity; +import org.cardanofoundation.lob.app.accounting_reporting_core.resource.views.metric.DashboardView; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(componentModel = "spring") +public interface DashboardViewToEntity { + + @Mapping(target = "id", ignore = true) + @Mapping(target = "xPos", source = "dashboardView.XPos") + @Mapping(target = "yPos", source = "dashboardView.YPos") + DashboardEntity mapToDashboardEntity(DashboardView dashboardView, String organisationID); + +} diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/repository/DashboardRepository.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/repository/DashboardRepository.java index 4e71e745..e94ff427 100644 --- a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/repository/DashboardRepository.java +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/repository/DashboardRepository.java @@ -1,4 +1,7 @@ package org.cardanofoundation.lob.app.accounting_reporting_core.repository; -public interface DashboardRepository { +import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.metric.DashboardEntity; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface DashboardRepository extends JpaRepository { } diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/MetricController.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/MetricController.java index 8597e9ec..e881ad34 100644 --- a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/MetricController.java +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/resource/MetricController.java @@ -46,7 +46,7 @@ public ResponseEntity getDashboardData(@RequestBody GetMetri @Tag(name = "Save Dashboards", description = "Save Dashboards") @PostMapping(value = "/saveDashboard", produces = "application/json") public ResponseEntity saveDashboard(@RequestBody SaveDashboardRequest saveDashboardRequest) { - metricService.saveDashboard(saveDashboardRequest.getDashboards()); + metricService.saveDashboard(saveDashboardRequest.getDashboards(), saveDashboardRequest.getOrganisationID()); return ResponseEntity.ok().build(); } } diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/service/internal/metrics/MetricService.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/service/internal/metrics/MetricService.java index 25d6cb94..3e53188d 100644 --- a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/service/internal/metrics/MetricService.java +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/service/internal/metrics/MetricService.java @@ -13,5 +13,5 @@ public interface MetricService { Map> getAvailableMetrics(); Map> getData(Map> metrics, String organisationID, Optional startDate, Optional endDate); - boolean saveDashboard(List dashboards); + boolean saveDashboard(List dashboards, String organisationID); } diff --git a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/service/internal/metrics/MetricServiceImpl.java b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/service/internal/metrics/MetricServiceImpl.java index 080bb84c..e9c5a8ad 100644 --- a/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/service/internal/metrics/MetricServiceImpl.java +++ b/accounting_reporting_core/src/main/java/org/cardanofoundation/lob/app/accounting_reporting_core/service/internal/metrics/MetricServiceImpl.java @@ -2,7 +2,10 @@ import lombok.RequiredArgsConstructor; import org.cardanofoundation.lob.app.accounting_reporting_core.domain.core.metric.MetricEnum; +import org.cardanofoundation.lob.app.accounting_reporting_core.domain.entity.metric.DashboardEntity; import org.cardanofoundation.lob.app.accounting_reporting_core.exception.MetricNotFoundException; +import org.cardanofoundation.lob.app.accounting_reporting_core.mapper.DashboardViewToEntity; +import org.cardanofoundation.lob.app.accounting_reporting_core.repository.DashboardRepository; import org.cardanofoundation.lob.app.accounting_reporting_core.resource.views.metric.DashboardView; import org.springframework.stereotype.Service; @@ -18,7 +21,8 @@ public class MetricServiceImpl implements MetricService{ private final List metricExecutors; - private final + private final DashboardRepository dashboardRepository; + private final DashboardViewToEntity dashboardViewToEntity; @Override public Map> getAvailableMetrics() { @@ -40,8 +44,13 @@ public Map> getData(Map dashboards) { - return false; + public boolean saveDashboard(List dashboards, String organisationID) { + List dashboardsEntities = dashboards.stream() + .map(dashboardView -> dashboardViewToEntity.mapToDashboardEntity(dashboardView, organisationID)) + .toList(); + + List dashboardEntities = dashboardRepository.saveAll(dashboardsEntities); + return dashboardEntities.size() == dashboards.size(); } private MetricExecutor getMetricExecutor(MetricEnum metricName) { diff --git a/accounting_reporting_core/src/main/resources/db/migration/postgresql/common/V4__adding_dashboard_saving.sql b/accounting_reporting_core/src/main/resources/db/migration/postgresql/common/V4__adding_dashboard_saving.sql new file mode 100644 index 00000000..7c0cdb9b --- /dev/null +++ b/accounting_reporting_core/src/main/resources/db/migration/postgresql/common/V4__adding_dashboard_saving.sql @@ -0,0 +1,24 @@ +CREATE TYPE accounting_core_metric_type AS ENUM ( + 'BALANCE_SHEET', + 'INCOME_STATEMENT' +); + +CREATE TYPE account_core_submetric_type AS ENUM ( + 'ASSET_CATEGORIES', + 'BALANCE_SHEET_OVERVIEW', + 'TOTAL_EXPENSES', + 'INCOME_STREAMS' +); + +CREATE TABLE IF NOT EXISTS accounting_core_dashboards ( + id BIGINT PRIMARY KEY, + organisation_id VARCHAR(255) NOT NULL, + name VARCHAR(255) NOT NULL, + description TEXT, + x_pos DOUBLE PRECISION, + y_pos DOUBLE PRECISION, + width DOUBLE PRECISION, + height DOUBLE PRECISION, + metric accounting_core_metric_type NOT NULL, + submetric account_core_submetric_type NOT NULL +); \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0451012c..39301ade 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -118,6 +118,10 @@ subprojects { implementation("com.bloxbean.cardano:cardano-client-backend-blockfrost:0.6.0") implementation("com.bloxbean.cardano:cardano-client-quicktx:0.6.0") + implementation("org.mapstruct:mapstruct:1.5.5.Final") + annotationProcessor("org.mapstruct:mapstruct-processor:1.5.5.Final") + annotationProcessor("org.projectlombok:lombok-mapstruct-binding:0.2.0") + compileOnly("org.projectlombok:lombok:1.18.32") annotationProcessor("org.projectlombok:lombok:1.18.32") implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0")