Dashboard
This commit is contained in:
@@ -3,6 +3,7 @@ package com.peakup.dashboard.model;
|
||||
import com.peakup.activity.model.IntervalsActivity;
|
||||
import com.peakup.common.model.AbstractDataObject;
|
||||
import com.peakup.goal.model.Goal;
|
||||
import com.peakup.goal.model.GoalMetricPeriodTotal;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
@@ -18,4 +19,5 @@ public class Dashboard extends AbstractDataObject {
|
||||
private int year;
|
||||
private List<IntervalsActivity> activities;
|
||||
private List<Goal> goals;
|
||||
private List<GoalMetricPeriodTotal> goalMetricPeriodTotals;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.peakup.dashboard.service;
|
||||
|
||||
import com.peakup.activity.service.IntervalsActivityService;
|
||||
import com.peakup.dashboard.model.Dashboard;
|
||||
import com.peakup.goal.service.GoalMetricPeriodTotalService;
|
||||
import com.peakup.goal.service.GoalService;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -23,6 +24,10 @@ public class DashboardService {
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
GoalService goalService;
|
||||
|
||||
@Inject
|
||||
@SuppressWarnings("NullAway.Init")
|
||||
GoalMetricPeriodTotalService goalMetricPeriodTotalService;
|
||||
|
||||
@Transactional
|
||||
public Dashboard getDashboard(final long athleteId, final int calendarWeek, final int year) {
|
||||
final LocalDate selectedWeekMonday = LocalDate.now()
|
||||
@@ -40,7 +45,8 @@ public class DashboardService {
|
||||
calendarWeek,
|
||||
year,
|
||||
intervalsActivityService.getByAthleteIdBetween(athleteId, from, to),
|
||||
goalService.getByAthleteId(athleteId)
|
||||
goalService.getByAthleteId(athleteId),
|
||||
goalMetricPeriodTotalService.getByAthleteAndWeek(athleteId, year, calendarWeek)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,22 @@ public class GoalMetricPeriodTotalDAO extends AbstractDAO<GoalMetricPeriodTotal>
|
||||
return em.createQuery(cq).setMaxResults(1).getResultStream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public List<GoalMetricPeriodTotal> findByAthleteAndWeek(
|
||||
final long athleteId,
|
||||
final int year,
|
||||
final int calendarWeek) {
|
||||
final CriteriaBuilder cb = em.getCriteriaBuilder();
|
||||
final CriteriaQuery<GoalMetricPeriodTotal> cq = cb.createQuery(GoalMetricPeriodTotal.class);
|
||||
final Root<GoalMetricPeriodTotal> root = cq.from(GoalMetricPeriodTotal.class);
|
||||
cq.select(root).where(
|
||||
cb.equal(root.get(GoalMetricPeriodTotal_.athleteId), athleteId),
|
||||
cb.equal(root.get(GoalMetricPeriodTotal_.period), GoalPeriodEnum.WEEKLY),
|
||||
cb.equal(root.get(GoalMetricPeriodTotal_.periodYear), year),
|
||||
cb.equal(root.get(GoalMetricPeriodTotal_.periodIndex), calendarWeek)
|
||||
);
|
||||
return em.createQuery(cq).getResultList();
|
||||
}
|
||||
|
||||
public List<GoalMetricPeriodTotal> findByAthleteAndMetricAndPeriod(
|
||||
final long athleteId,
|
||||
final GoalMetricEnum metric,
|
||||
|
||||
@@ -67,6 +67,11 @@ public class GoalMetricPeriodTotalService extends AbstractService<GoalMetricPeri
|
||||
return goalMetricAggregateDAO.findByAthleteAndMetricAndPeriod(athleteId, metric, period);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<GoalMetricPeriodTotal> getByAthleteAndWeek(final long athleteId, final int year, final int calendarWeek) {
|
||||
return goalMetricAggregateDAO.findByAthleteAndWeek(athleteId, year, calendarWeek);
|
||||
}
|
||||
|
||||
private List<IntervalsActivity> fetchWeekActivities(final long athleteId, final int year, final int calendarWeek) {
|
||||
final LocalDate weekStart = LocalDate.of(year, 1, 4)
|
||||
.with(WeekFields.ISO.weekOfWeekBasedYear(), calendarWeek)
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
import type { AbstractDataObjectDo } from './AbstractDataObjectDo';
|
||||
import type { IntervalsActivityDo } from './IntervalsActivityDo';
|
||||
import type { GoalDo } from './GoalDo';
|
||||
import type { GoalMetricPeriodTotalDo } from './GoalMetricPeriodTotalDo';
|
||||
|
||||
export interface DashboardDo extends AbstractDataObjectDo {
|
||||
calendarWeek: number;
|
||||
year: number;
|
||||
activities: IntervalsActivityDo[];
|
||||
goals: GoalDo[];
|
||||
goalMetricPeriodTotals: GoalMetricPeriodTotalDo[];
|
||||
}
|
||||
|
||||
12
peakup-frontend/src/types/GoalMetricPeriodTotalDo.ts
Normal file
12
peakup-frontend/src/types/GoalMetricPeriodTotalDo.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
// GENERATED — do not edit manually.
|
||||
|
||||
import type { AbstractTimestampedEntityDo } from './AbstractTimestampedEntityDo';
|
||||
|
||||
export interface GoalMetricPeriodTotalDo extends AbstractTimestampedEntityDo {
|
||||
athleteId: number;
|
||||
metric: GoalMetricEnum;
|
||||
period: GoalPeriodEnum;
|
||||
periodYear: number;
|
||||
periodIndex: number;
|
||||
aggregatedValue: number;
|
||||
}
|
||||
Reference in New Issue
Block a user