Repository navigation
feature: transaction search on Primary and Savings account pages (UserFront) #632
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package com.userFront.service; | ||
|
|
||
| import java.time.LocalDate; | ||
|
|
||
| import org.springframework.format.annotation.DateTimeFormat; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| public class TransactionFilter { | ||
|
|
||
| public static final String TYPE_DEPOSIT = "deposit"; | ||
| public static final String TYPE_WITHDRAW = "withdraw"; | ||
| public static final String TYPE_TRANSFER = "transfer"; | ||
|
|
||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) | ||
| private LocalDate from; | ||
|
|
||
| @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) | ||
| private LocalDate to; | ||
|
|
||
| private String type; | ||
| private Double minAmount; | ||
| private Double maxAmount; | ||
| private String q; | ||
|
|
||
| public boolean isActive() { | ||
| return from != null || to != null || StringUtils.hasText(type) || minAmount != null || maxAmount != null | ||
| || StringUtils.hasText(q); | ||
| } | ||
|
|
||
| public LocalDate getFrom() { | ||
| return from; | ||
| } | ||
|
|
||
| public void setFrom(LocalDate from) { | ||
| this.from = from; | ||
| } | ||
|
|
||
| public LocalDate getTo() { | ||
| return to; | ||
| } | ||
|
|
||
| public void setTo(LocalDate to) { | ||
| this.to = to; | ||
| } | ||
|
|
||
| public String getType() { | ||
| return type; | ||
| } | ||
|
|
||
| public void setType(String type) { | ||
| this.type = type; | ||
| } | ||
|
|
||
| public Double getMinAmount() { | ||
| return minAmount; | ||
| } | ||
|
|
||
| public void setMinAmount(Double minAmount) { | ||
| this.minAmount = minAmount; | ||
| } | ||
|
|
||
| public Double getMaxAmount() { | ||
| return maxAmount; | ||
| } | ||
|
|
||
| public void setMaxAmount(Double maxAmount) { | ||
| this.maxAmount = maxAmount; | ||
| } | ||
|
|
||
| public String getQ() { | ||
| return q; | ||
| } | ||
|
|
||
| public void setQ(String q) { | ||
| this.q = q; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.userFront.service; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.ZoneId; | ||
| import java.util.ArrayList; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
|
|
||
| import javax.persistence.criteria.Expression; | ||
| import javax.persistence.criteria.Predicate; | ||
|
|
||
| import org.springframework.data.jpa.domain.Specification; | ||
| import org.springframework.util.StringUtils; | ||
|
|
||
| /** | ||
| * Builds the server-side query for the account pages' transaction filters. | ||
| * The stored {@code type} column is not consistent (deposits, withdrawals and | ||
| * some transfers are all stored as "Account"), so the type filter matches on | ||
| * the description the app writes for each kind of transaction. | ||
| */ | ||
| public final class TransactionSpecifications { | ||
|
|
||
| private static final char ESCAPE = '\\'; | ||
|
|
||
| private TransactionSpecifications() { | ||
| } | ||
|
|
||
| public static <T> Specification<T> forAccount(String accountField, Object account, TransactionFilter filter) { | ||
| return (root, query, cb) -> { | ||
| List<Predicate> predicates = new ArrayList<>(); | ||
| predicates.add(cb.equal(root.get(accountField), account)); | ||
|
|
||
| if (filter == null) { | ||
| return cb.and(predicates.toArray(new Predicate[0])); | ||
| } | ||
|
|
||
| if (filter.getFrom() != null) { | ||
| predicates.add(cb.greaterThanOrEqualTo(root.<Date>get("date"), startOfDay(filter.getFrom(), 0))); | ||
| } | ||
| if (filter.getTo() != null) { | ||
| predicates.add(cb.lessThan(root.<Date>get("date"), startOfDay(filter.getTo(), 1))); | ||
| } | ||
| if (filter.getMinAmount() != null) { | ||
| predicates.add(cb.greaterThanOrEqualTo(root.<Double>get("amount"), filter.getMinAmount())); | ||
| } | ||
| if (filter.getMaxAmount() != null) { | ||
| predicates.add(cb.lessThanOrEqualTo(root.<Double>get("amount"), filter.getMaxAmount())); | ||
| } | ||
|
|
||
| Expression<String> description = cb.lower(root.<String>get("description")); | ||
| String typePattern = typePattern(filter.getType()); | ||
| if (typePattern != null) { | ||
| predicates.add(cb.like(description, typePattern)); | ||
| } | ||
| if (StringUtils.hasText(filter.getQ())) { | ||
| String text = escapeLike(filter.getQ().trim().toLowerCase(Locale.ROOT)); | ||
| predicates.add(cb.like(description, "%" + text + "%", ESCAPE)); | ||
| } | ||
|
|
||
| return cb.and(predicates.toArray(new Predicate[0])); | ||
| }; | ||
| } | ||
|
|
||
| static String typePattern(String type) { | ||
| if (type == null) { | ||
| return null; | ||
| } | ||
| switch (type.trim().toLowerCase(Locale.ROOT)) { | ||
| case TransactionFilter.TYPE_DEPOSIT: | ||
| return "deposit%"; | ||
| case TransactionFilter.TYPE_WITHDRAW: | ||
| return "withdraw%"; | ||
| case TransactionFilter.TYPE_TRANSFER: | ||
| return "%transfer%"; | ||
| default: | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private static String escapeLike(String text) { | ||
| return text.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_"); | ||
| } | ||
|
|
||
| static Date startOfDay(LocalDate day, int plusDays) { | ||
| return Date.from(day.plusDays(plusDays).atStartOfDay(ZoneId.systemDefault()).toInstant()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> | ||
| <body> | ||
|
|
||
| <div th:fragment="filterForm(actionUrl)" class="panel panel-default transaction-filter"> | ||
| <div class="panel-heading"> | ||
| <strong><i class="fa fa-filter" aria-hidden="true"></i> Search transactions</strong> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧠 TD French Language (Bill 96): Transaction search copy stays English On both account pages, View in Devin Review · Custom reviewer Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| </div> | ||
| <div class="panel-body"> | ||
| <form method="get" th:action="@{${actionUrl}}" th:object="${filter}"> | ||
| <div class="row"> | ||
| <div class="form-group col-sm-6 col-md-2"> | ||
| <label for="from">From</label> | ||
| <input type="date" class="form-control" id="from" th:field="*{from}" /> | ||
| </div> | ||
| <div class="form-group col-sm-6 col-md-2"> | ||
| <label for="to">To</label> | ||
| <input type="date" class="form-control" id="to" th:field="*{to}" /> | ||
| </div> | ||
| <div class="form-group col-sm-4 col-md-2"> | ||
| <label for="type">Type</label> | ||
| <select class="form-control" id="type" th:field="*{type}"> | ||
| <option value="">All types</option> | ||
| <option value="deposit">Deposit</option> | ||
| <option value="withdraw">Withdraw</option> | ||
| <option value="transfer">Transfer</option> | ||
| </select> | ||
| </div> | ||
| <div class="form-group col-sm-4 col-md-2"> | ||
| <label for="minAmount">Min amount</label> | ||
| <div class="input-group"> | ||
| <span class="input-group-addon"><i class="fa fa-usd" aria-hidden="true"></i></span> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧠 TD French Language (Bill 96): French amount filters show leading dollars For View in Devin Review · Custom reviewer Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| <input type="number" step="0.01" min="0" class="form-control" id="minAmount" | ||
| th:field="*{minAmount}" /> | ||
| </div> | ||
| </div> | ||
| <div class="form-group col-sm-4 col-md-2"> | ||
| <label for="maxAmount">Max amount</label> | ||
| <div class="input-group"> | ||
| <span class="input-group-addon"><i class="fa fa-usd" aria-hidden="true"></i></span> | ||
| <input type="number" step="0.01" min="0" class="form-control" id="maxAmount" | ||
| th:field="*{maxAmount}" /> | ||
| </div> | ||
| </div> | ||
| <div class="form-group col-sm-12 col-md-2"> | ||
| <label for="q">Description</label> | ||
| <input type="text" class="form-control" id="q" placeholder="e.g. recipient" | ||
| th:field="*{q}" /> | ||
| </div> | ||
| </div> | ||
| <div class="row"> | ||
| <div class="col-sm-12"> | ||
| <button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i> Filter</button> | ||
| <a class="btn btn-link" th:href="@{${actionUrl}}" th:if="${filter.active}">Clear filters</a> | ||
| </div> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div th:fragment="emptyState(actionUrl)" class="well text-center transaction-empty"> | ||
| <h4><i class="fa fa-search" aria-hidden="true"></i> | ||
| <span th:text="${filter.active} ? 'No transactions match these filters.' : 'No transactions yet.'">No transactions yet.</span> | ||
| </h4> | ||
| <p th:if="${filter.active}">Try a wider date range or amount, or | ||
| <a th:href="@{${actionUrl}}">clear filters</a> to see every transaction.</p> | ||
| </div> | ||
|
|
||
| </body> | ||
| </html> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👁️ TD Information Security: Critically vulnerable H2 test dependency
h2inherits version1.4.195from Spring Boot1.5.4.RELEASE, introducing critical CVE-2021-42392 against the Dependencies criterion. The vulnerability permits remote code execution when an H2 Console accepts untrusted remote connections. Test scope excludes production packaging; these tests do not expose that console.View in Devin Review · Custom reviewer
Was this helpful? React with 👍 or 👎 to provide feedback.