ActivitySummary
This commit is contained in:
@@ -18,6 +18,7 @@ import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import org.jboss.resteasy.reactive.RestResponse;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.List;
|
||||
|
||||
@Path("/api/activities")
|
||||
@@ -40,7 +41,12 @@ public class IntervalsActivityResource extends AbstractResource {
|
||||
throw new BadRequestException("athleteId query parameter is required");
|
||||
}
|
||||
if (from != null && to != null) {
|
||||
return RestResponse.ok(intervalsActivityService.getByAthleteIdBetween(athleteId, from, to));
|
||||
try {
|
||||
return RestResponse.ok(intervalsActivityService.getByAthleteIdBetween(
|
||||
athleteId, LocalDate.parse(from), LocalDate.parse(to)));
|
||||
} catch (final java.time.format.DateTimeParseException e) {
|
||||
throw new BadRequestException("from and to must be YYYY-MM-DD");
|
||||
}
|
||||
}
|
||||
return RestResponse.ok(intervalsActivityService.getByAthleteId(athleteId, page, size));
|
||||
}
|
||||
@@ -64,7 +70,7 @@ public class IntervalsActivityResource extends AbstractResource {
|
||||
throw new BadRequestException("athleteId and date query parameters are required");
|
||||
}
|
||||
try {
|
||||
return RestResponse.ok(intervalsActivityService.getByAthleteIdAndDay(athleteId, date));
|
||||
return RestResponse.ok(intervalsActivityService.getByAthleteIdAndDay(athleteId, LocalDate.parse(date)));
|
||||
} catch (final java.time.format.DateTimeParseException e) {
|
||||
throw new BadRequestException("date must be YYYY-MM-DD");
|
||||
}
|
||||
|
||||
@@ -30,9 +30,9 @@ public class ActivitySummaryService extends AbstractTimestampedReadonlyService<A
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<ActivitySummary> getByAthleteIdBetween(final Long athleteId, final String from, final String to) {
|
||||
final Instant fromInstant = LocalDate.parse(from).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
final Instant toInstant = LocalDate.parse(to).plusDays(1).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
public List<ActivitySummary> getByAthleteIdBetween(final Long athleteId, final LocalDate from, final LocalDate to) {
|
||||
final Instant fromInstant = from.atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
final Instant toInstant = to.plusDays(1).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
return activitySummaryDAO.getByAthleteIdBetween(athleteId, fromInstant, toInstant);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,16 +49,16 @@ public class IntervalsActivityService extends AbstractService<IntervalsActivity,
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<IntervalsActivity> getByAthleteIdBetween(final Long athleteId, final String from, final String to) {
|
||||
final Instant fromInstant = LocalDate.parse(from).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
final Instant toInstant = LocalDate.parse(to).plusDays(1).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
public List<IntervalsActivity> getByAthleteIdBetween(final Long athleteId, final LocalDate from, final LocalDate to) {
|
||||
final Instant fromInstant = from.atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
final Instant toInstant = to.plusDays(1).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
return intervalsActivityDAO.getByAthleteIdBetween(athleteId, fromInstant, toInstant);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<IntervalsActivity> getByAthleteIdAndDay(final Long athleteId, final String date) {
|
||||
final Instant dayStart = LocalDate.parse(date).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
final Instant dayEnd = LocalDate.parse(date).plusDays(1).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
public List<IntervalsActivity> getByAthleteIdAndDay(final Long athleteId, final LocalDate date) {
|
||||
final Instant dayStart = date.atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
final Instant dayEnd = date.plusDays(1).atStartOfDay(ZoneOffset.UTC).toInstant();
|
||||
return intervalsActivityDAO.getByAthleteIdAndDay(athleteId, dayStart, dayEnd);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ import jakarta.transaction.Transactional;
|
||||
import java.time.DayOfWeek;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.WeekFields;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -56,10 +55,7 @@ public class DashboardService {
|
||||
final LocalDate rangeFrom = selectedWeekMonday.minusWeeks(11);
|
||||
final LocalDate rangeTo = selectedWeekMonday.plusDays(6);
|
||||
|
||||
final String from = rangeFrom.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
final String to = rangeTo.format(DateTimeFormatter.ISO_LOCAL_DATE);
|
||||
|
||||
final List<ActivitySummary> activitySummaries = activitySummaryService.getByAthleteIdBetween(athleteId, from, to);
|
||||
final List<ActivitySummary> activitySummaries = activitySummaryService.getByAthleteIdBetween(athleteId, rangeFrom, rangeTo);
|
||||
final Map<Long, List<ActivityMapStreamPoint>> weekActivityMapStreams =
|
||||
resolveWeekActivityMapStreams(activitySummaries, selectedWeekMonday);
|
||||
final Map<Long, List<ActivityStreamPoint>> weekActivityStreams =
|
||||
|
||||
@@ -85,7 +85,7 @@ public class GoalMetricPeriodTotalService extends AbstractService<GoalMetricPeri
|
||||
.with(WeekFields.ISO.weekOfWeekBasedYear(), calendarWeek)
|
||||
.with(WeekFields.ISO.dayOfWeek(), 1);
|
||||
final LocalDate weekEnd = weekStart.plusDays(6);
|
||||
return intervalsActivityService.getByAthleteIdBetween(athleteId, weekStart.toString(), weekEnd.toString());
|
||||
return intervalsActivityService.getByAthleteIdBetween(athleteId, weekStart, weekEnd);
|
||||
}
|
||||
|
||||
public void recalculateUpToCurrentWeek(final long athleteId) {
|
||||
|
||||
@@ -102,7 +102,7 @@ public class GoalNotificationService {
|
||||
.with(WeekFields.ISO.dayOfWeek(), 1);
|
||||
final LocalDate weekEnd = weekStart.plusDays(6);
|
||||
final List<IntervalsActivity> weekActivities = intervalsActivityService.getByAthleteIdBetween(
|
||||
athleteId, weekStart.toString(), weekEnd.toString());
|
||||
athleteId, weekStart, weekEnd);
|
||||
|
||||
final Athlete athlete = athleteService.getById(athleteId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user