-
Notifications
You must be signed in to change notification settings - Fork 23
feat: alert on low remaining contract days #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yoandiny
wants to merge
29
commits into
hei-teacher:preprod
Choose a base branch
from
Bradon614:low-remaining-days-alert
base: preprod
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b91aee4
feat: add findActiveContractByWorker for per-worker active contract l…
yoandiny 269dc04
feat: add getRemainingDaysOnActiveContractOrZero on ContractService (…
yoandiny 440c92a
Feat/low remaining days alert event (#57)
haja171106 af5a9e9
Feature/wave1 active contract and calendar UI (#59)
Tom-1747 dde2f5a
feat: add LowRemainingDaysAlertService for low contract days alert
nelio-gio 46ad931
chore: format code
nelio-gio d033f3a
test: clean up alert IT fixtures to avoid shared DB pollution
yoandiny 859e39b
Merge pull request #60 from Bradon614/feat/low-remaining-alert-service
Bradon614 ca67b3e
Feature/daily execution default date tests (#61)
saviola24 b76ad26
feat(calendar): integrate low remaining days alert service (#62)
Bradon614 4120bbb
fix: prevent alert email on calendar view and trigger after pointage …
haja171106 e6cf78e
fix: reject punch-in when contract is inactive (#64)
nyamyjese 0ffd661
fix: calendar assets, zero-days banner, and pointage Loza guard (#65)
yoandiny f30f75d
chore: restore application.properties without session jdbc init (#66)
yoandiny d506bcf
docs: document ACCOUNTANTS and LOW_REMAINING_DAYS_THRESHOLD in README…
yoandiny fc2f01f
refactor: simplify low remaining alert wiring (#68)
yoandiny 757b63e
fix: align pointage and calendar flow with review feedback (#70)
yoandiny 8f74be7
fix: show low-days banner from calendar GET (#72)
yoandiny c350a92
test: move alert IT fixtures to Flyway migration (#73)
yoandiny b42402d
refactor: use double for remaining days calculations (#75)
Tom-1747 4dc7a55
refactor: rename checkRemainingDays alert method to verify (#76)
yoandiny 1896683
refactor: add DailyExecutionService.verifyAndSave for pointage (#77)
yoandiny f4f4bdc
Move pointage IT contract fixtures to Flyway to avoid runtime team sa…
yoandiny a57abe4
Rename verifyAndSave to saveAndAlert for clearer pointage save flow (…
yoandiny 69ad638
Show low remaining days warning banner on daily-execution GET. (#80)
yoandiny 6869606
Mirror calendar contract banners on daily-execution GET (#81)
yoandiny a75122a
Unify contract warning into one banner with conditional color (#82)
yoandiny e65f003
Simplify calendar alert to message-only banner and remove toast. (#83)
yoandiny 8777251
Remove unnecessary empty accountants check per review. (#84)
yoandiny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/school/hei/asa/endpoint/event/model/LowRemainingDaysAlertRequested.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package school.hei.asa.endpoint.event.model; | ||
|
|
||
| import java.time.Duration; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.EqualsAndHashCode; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.ToString; | ||
|
|
||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder(toBuilder = true) | ||
| @Data | ||
| @EqualsAndHashCode(callSuper = false) | ||
| @ToString | ||
| public class LowRemainingDaysAlertRequested extends PojaEvent { | ||
|
|
||
| private String workerCode; | ||
| private int remainingDays; | ||
|
|
||
| @Override | ||
| public Duration maxConsumerDuration() { | ||
| return Duration.ofSeconds(45); | ||
| } | ||
|
|
||
| @Override | ||
| public Duration maxConsumerBackoffBetweenRetries() { | ||
| return Duration.ofSeconds(30); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package school.hei.asa.number; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public final class DaysFormatter { | ||
|
|
||
| private DaysFormatter() {} | ||
|
|
||
| public static String format(double days) { | ||
| var normalized = BigDecimal.valueOf(days).stripTrailingZeros(); | ||
| if (normalized.scale() <= 0) { | ||
| return normalized.toBigInteger().toString(); | ||
| } | ||
| return normalized.toPlainString(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/school/hei/asa/service/DailyExecutionService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package school.hei.asa.service; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import school.hei.asa.model.DailyExecution; | ||
| import school.hei.asa.repository.DailyExecutionRepository; | ||
|
|
||
| @Service | ||
| @AllArgsConstructor | ||
| public class DailyExecutionService { | ||
| private final DailyExecutionRepository dailyExecutionRepository; | ||
| private final LowRemainingDaysAlertService lowRemainingDaysAlertService; | ||
|
|
||
| public void saveAndAlert(DailyExecution dailyExecution) { | ||
| dailyExecutionRepository.save(dailyExecution); | ||
| lowRemainingDaysAlertService.sendAlertEmailIfLowRemainingDays(dailyExecution.worker()); | ||
| } | ||
| } |
72 changes: 72 additions & 0 deletions
72
src/main/java/school/hei/asa/service/LowRemainingDaysAlertService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package school.hei.asa.service; | ||
|
|
||
| import static java.util.Locale.US; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.stereotype.Service; | ||
| import school.hei.asa.endpoint.event.EventProducer; | ||
| import school.hei.asa.endpoint.event.model.LowRemainingDaysAlertRequested; | ||
| import school.hei.asa.model.Worker; | ||
|
|
||
| @Slf4j | ||
| @Service | ||
| public class LowRemainingDaysAlertService { | ||
|
|
||
| private final ContractService contractService; | ||
| private final EventProducer<LowRemainingDaysAlertRequested> eventProducer; | ||
| private final int lowRemainingDaysThreshold; | ||
|
|
||
| public LowRemainingDaysAlertService( | ||
| ContractService contractService, | ||
| EventProducer<LowRemainingDaysAlertRequested> eventProducer, | ||
| @Value("${LOW_REMAINING_DAYS_THRESHOLD}") int lowRemainingDaysThreshold) { | ||
| this.contractService = contractService; | ||
| this.eventProducer = eventProducer; | ||
| this.lowRemainingDaysThreshold = lowRemainingDaysThreshold; | ||
| } | ||
|
|
||
| public Optional<String> verifyRemainingDaysAndBuildAlertMessage(Worker worker) { | ||
| var remainingDays = contractService.getRemainingDaysOnActiveContractOrZero(worker); | ||
|
|
||
| if (remainingDays <= 0) { | ||
| return Optional.of( | ||
| "Please note : You do not have an active contract. Please contact your administrator."); | ||
| } | ||
|
|
||
| if (!isBelowThreshold(remainingDays)) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| return Optional.of( | ||
| "Please note : You have " + formatDays(remainingDays) + " day(s) left on your contract !"); | ||
| } | ||
|
|
||
| public void sendAlertEmailIfLowRemainingDays(Worker worker) { | ||
| var remainingDays = contractService.getRemainingDaysOnActiveContractOrZero(worker); | ||
|
|
||
| if (!isBelowThreshold(remainingDays)) { | ||
| return; | ||
| } | ||
|
|
||
| log.info("Requesting alert email to accountants for worker '{}'", worker.code()); | ||
| eventProducer.accept( | ||
| List.of( | ||
| LowRemainingDaysAlertRequested.builder() | ||
| .workerCode(worker.code()) | ||
| .remainingDays((int) remainingDays) | ||
| .build())); | ||
| } | ||
|
|
||
| private boolean isBelowThreshold(double remainingDays) { | ||
| return remainingDays > 0 && remainingDays < lowRemainingDaysThreshold; | ||
| } | ||
|
|
||
| private static String formatDays(double days) { | ||
| return days == Math.floor(days) | ||
| ? String.format(US, "%.0f", days) | ||
| : String.format(US, "%.1f", days); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.