From dd416f3090ec73f3e09175a0e56998ef6c7246c0 Mon Sep 17 00:00:00 2001 From: Azmi TOUIL <42934070+AzmiTouil@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:24:28 +0200 Subject: [PATCH] fix: Fix wrong label for points in reward details - MEED-7644 - Meeds-io/MIPs#154 (#598) This PR will fix the wrong label for points in reward details --- .../io/meeds/wallet/model/RewardReportStatus.java | 2 ++ .../wallet/reward/service/RewardReportService.java | 8 ++++++++ .../java/io/meeds/wallet/reward/dao/RewardDAO.java | 7 +++++++ .../reward/service/WalletRewardReportService.java | 11 ++++++++++- .../reward/storage/WalletRewardReportStorage.java | 5 +++++ .../wallet-reward/components/reward/RewardDetails.vue | 2 +- 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/wallet-api/src/main/java/io/meeds/wallet/model/RewardReportStatus.java b/wallet-api/src/main/java/io/meeds/wallet/model/RewardReportStatus.java index 7ab394f20..1595b378e 100644 --- a/wallet-api/src/main/java/io/meeds/wallet/model/RewardReportStatus.java +++ b/wallet-api/src/main/java/io/meeds/wallet/model/RewardReportStatus.java @@ -36,6 +36,8 @@ public class RewardReportStatus { private int achievementsCount; + private double points; + private double tokensSent; private double tokensToSend; diff --git a/wallet-api/src/main/java/io/meeds/wallet/reward/service/RewardReportService.java b/wallet-api/src/main/java/io/meeds/wallet/reward/service/RewardReportService.java index ce568ee71..58ef22a4e 100644 --- a/wallet-api/src/main/java/io/meeds/wallet/reward/service/RewardReportService.java +++ b/wallet-api/src/main/java/io/meeds/wallet/reward/service/RewardReportService.java @@ -186,6 +186,14 @@ public interface RewardReportService { */ Page findWalletRewardsByPeriodIdAndStatus(long periodId, String status, ZoneId zoneId, Pageable pageable); + /** + * Count wallet rewards points by PeriodId and status + * + * @param periodId Reward Period id + * @param isValid Wallet reward status + */ + double countWalletRewardsPointsByPeriodIdAndStatus(long periodId, boolean isValid); + /** * Set isChanged data map for periods not sent diff --git a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/dao/RewardDAO.java b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/dao/RewardDAO.java index 541831e77..b22933d51 100644 --- a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/dao/RewardDAO.java +++ b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/dao/RewardDAO.java @@ -46,6 +46,13 @@ Page findWalletRewardsByPeriodIdAndStatus(@Param("periodId") @Param("isValid") boolean isValid, Pageable pageable); + @Query(""" + SELECT SUM(rw.points) FROM Reward rw WHERE rw.period.id = :periodId AND + (:isValid = TRUE AND (rw.tokensSent > 0 OR rw.tokensToSend > 0) OR :isValid = FALSE AND (rw.tokensSent <= 0 AND rw.tokensToSend <= 0)) + """) + Double countWalletRewardsPointsByPeriodIdAndStatus(@Param("periodId") long periodId, + @Param("isValid") boolean isValid); + List findWalletRewardEntitiesByIdentityId(long identityId, Pageable pageable); double countWalletRewardEntitiesByIdentityId(long identityId); diff --git a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/service/WalletRewardReportService.java b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/service/WalletRewardReportService.java index 564ebaf84..6268918b5 100644 --- a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/service/WalletRewardReportService.java +++ b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/service/WalletRewardReportService.java @@ -210,7 +210,7 @@ public RewardReportStatus getReport(RewardPeriod rewardPeriod) { rewardSettingChangedMap.put(storedRewardPeriod.getId(), false); setRewardSettingChanged(rewardSettingChangedMap); } - return buildReportStatus(rewardReport, rewardPeriod); + return buildReportStatus(rewardReport, storedRewardPeriod != null ? storedRewardPeriod : rewardPeriod); } @Override @@ -394,6 +394,11 @@ public void replaceRewardTransactions(String oldHash, String newHash) { public Page findWalletRewardsByPeriodIdAndStatus(long periodId, String status, ZoneId zoneId, Pageable pageable) { boolean isValid = !status.equals("INVALID"); return rewardReportStorage.findWalletRewardsByPeriodIdAndStatus(periodId, isValid, zoneId, pageable); + } + + @Override + public double countWalletRewardsPointsByPeriodIdAndStatus(long periodId, boolean isValid) { + return rewardReportStorage.countWalletRewardsPointsByPeriodIdAndStatus(periodId, isValid); } public void setRewardSettingChanged(Map updatedSettings) { @@ -632,6 +637,7 @@ private RewardReportStatus buildReportStatus(RewardReport rewardReport, RewardPe if (participantsCount > 0) { rewardReport = computeRewards(rewardPeriod.getPeriodMedianDate()); saveRewardReport(rewardReport); + rewardPeriod = getRewardPeriod(rewardPeriod.getRewardPeriodType(), rewardPeriod.getPeriodMedianDate()); } else { rewardReport = new RewardReport(); rewardReport.setPeriod(rewardPeriod); @@ -644,11 +650,14 @@ private RewardReportStatus buildReportStatus(RewardReport rewardReport, RewardPe .findFirst() .orElse(null); + double points = rewardPeriod.getId() > 0 ? countWalletRewardsPointsByPeriodIdAndStatus(rewardPeriod.getId(), true) : 0; + return new RewardReportStatus(succeededTransaction != null ? succeededTransaction.getTransaction().getSentTimestamp() : 0, rewardReport.getPeriod(), participantsCount, rewardReport.getValidRewardCount(), achievementsCount, + points, rewardReport.getTokensSent(), rewardReport.getTokensToSend(), CollectionUtils.isNotEmpty(rewardReport.getRewards()) && rewardReport.isCompletelyProcessed()); diff --git a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/storage/WalletRewardReportStorage.java b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/storage/WalletRewardReportStorage.java index 513778703..b312c55f9 100644 --- a/wallet-reward-services/src/main/java/io/meeds/wallet/reward/storage/WalletRewardReportStorage.java +++ b/wallet-reward-services/src/main/java/io/meeds/wallet/reward/storage/WalletRewardReportStorage.java @@ -253,6 +253,11 @@ public Page findWalletRewardsByPeriodIdAndStatus(long periodId, bo return walletRewardEntities.map(walletRewardEntity -> toDTO(walletRewardEntity, zoneId)); } + public double countWalletRewardsPointsByPeriodIdAndStatus(long periodId, boolean isValid) { + Double countWalletRewardsPoints = rewardDAO.countWalletRewardsPointsByPeriodIdAndStatus(periodId, isValid); + return countWalletRewardsPoints != null ? countWalletRewardsPoints : 0; + } + private RewardPeriod toDTO(WalletRewardPeriodEntity period) { if (period == null) { return null; diff --git a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetails.vue b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetails.vue index 06713a28e..2cab39800 100644 --- a/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetails.vue +++ b/wallet-webapps/src/main/webapp/vue-app/wallet-reward/components/reward/RewardDetails.vue @@ -270,7 +270,7 @@ export default { return this.valueFormatted(this.tokensToSend); }, points() { - return this.valueFormatted(this.validRewards?.map(x => x?.points || 0).reduce((x, y) => x + y, 0), 0); + return this.rewardReport?.points; }, rewardsToSend() { return this.$t('wallet.administration.rewardDetails.label.rewardsToSend', {