Skip to content

Commit

Permalink
stashing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kammerlo committed Jan 15, 2025
1 parent be82eb7 commit 82086bb
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
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
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "dashboard")
@Table(name = "accounting_core_dashboards")
public class DashboardEntity{

@Id
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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);

}
Original file line number Diff line number Diff line change
@@ -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<DashboardEntity, String> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ResponseEntity<MetricDataResponse> getDashboardData(@RequestBody GetMetri
@Tag(name = "Save Dashboards", description = "Save Dashboards")
@PostMapping(value = "/saveDashboard", produces = "application/json")
public ResponseEntity<Void> saveDashboard(@RequestBody SaveDashboardRequest saveDashboardRequest) {
metricService.saveDashboard(saveDashboardRequest.getDashboards());
metricService.saveDashboard(saveDashboardRequest.getDashboards(), saveDashboardRequest.getOrganisationID());
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ public interface MetricService {
Map<MetricEnum, List<MetricEnum.SubMetric>> getAvailableMetrics();
Map<MetricEnum, List<Object>> getData(Map<MetricEnum, List<MetricEnum.SubMetric>> metrics, String organisationID, Optional<LocalDate> startDate, Optional<LocalDate> endDate);

boolean saveDashboard(List<DashboardView> dashboards);
boolean saveDashboard(List<DashboardView> dashboards, String organisationID);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,7 +21,8 @@
public class MetricServiceImpl implements MetricService{

private final List<MetricExecutor> metricExecutors;
private final
private final DashboardRepository dashboardRepository;
private final DashboardViewToEntity dashboardViewToEntity;

@Override
public Map<MetricEnum, List<MetricEnum.SubMetric>> getAvailableMetrics() {
Expand All @@ -40,8 +44,13 @@ public Map<MetricEnum, List<Object>> getData(Map<MetricEnum, List<MetricEnum.Sub
}

@Override
public boolean saveDashboard(List<DashboardView> dashboards) {
return false;
public boolean saveDashboard(List<DashboardView> dashboards, String organisationID) {
List<DashboardEntity> dashboardsEntities = dashboards.stream()
.map(dashboardView -> dashboardViewToEntity.mapToDashboardEntity(dashboardView, organisationID))
.toList();

List<DashboardEntity> dashboardEntities = dashboardRepository.saveAll(dashboardsEntities);
return dashboardEntities.size() == dashboards.size();
}

private MetricExecutor getMetricExecutor(MetricEnum metricName) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
);
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 82086bb

Please sign in to comment.