-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add test * add test * fix duplicate * fix in out to vietnamese * fix choose a user to vietnamese * fix validation and to vietnamese * fix validation to vietnamese * fix default is admin * fix edit modal * add statistic * fix return active category * fix checkstyle * add test * add test * fix
- Loading branch information
Showing
13 changed files
with
468 additions
and
221 deletions.
There are no files selected for viewing
This file contains 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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/fjb/sunrise/constraints/StringMustBeDigitWithFraction.java
This file contains 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,21 @@ | ||
package com.fjb.sunrise.constraints; | ||
|
||
import jakarta.validation.Constraint; | ||
import jakarta.validation.Payload; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Constraint(validatedBy = StringMustBeDigitWithFractionValidator.class) | ||
@Target({ElementType.FIELD, ElementType.METHOD}) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface StringMustBeDigitWithFraction { | ||
String message() default "Số tiền phải là chữ số với số thập phân là {fraction}"; | ||
|
||
Class<?>[] groups() default {}; | ||
|
||
Class<? extends Payload>[] payload() default {}; | ||
|
||
int fraction(); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/fjb/sunrise/constraints/StringMustBeDigitWithFractionValidator.java
This file contains 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,36 @@ | ||
package com.fjb.sunrise.constraints; | ||
|
||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import org.springframework.util.StringUtils; | ||
|
||
public class StringMustBeDigitWithFractionValidator | ||
implements ConstraintValidator<StringMustBeDigitWithFraction, String> { | ||
private int fraction = 0; | ||
|
||
@Override | ||
public void initialize(StringMustBeDigitWithFraction constraintAnnotation) { | ||
ConstraintValidator.super.initialize(constraintAnnotation); | ||
fraction = constraintAnnotation.fraction(); | ||
} | ||
|
||
@Override | ||
public boolean isValid(String string, ConstraintValidatorContext constraintValidatorContext) { | ||
String ignoreComma = string.replaceAll(",", ""); | ||
String ignoreDot = ignoreComma.replace(".", ""); | ||
if (ignoreDot.chars().allMatch(Character::isDigit)) { | ||
if (fraction > 0) { | ||
int startOfFraction = ignoreComma.indexOf("."); | ||
if (startOfFraction == -1) { | ||
return true; | ||
} | ||
if (ignoreComma.length() - startOfFraction - 1 > fraction) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
return false; | ||
} | ||
} |
This file contains 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 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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/fjb/sunrise/dtos/responses/StatisticResponse.java
This file contains 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,13 @@ | ||
package com.fjb.sunrise.dtos.responses; | ||
|
||
import java.io.Serializable; | ||
import lombok.Data; | ||
|
||
|
||
|
||
@Data | ||
public class StatisticResponse implements Serializable { | ||
private String totalThisYear; | ||
private String totalInputThisYear; | ||
private String totalThisMonth; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/fjb/sunrise/repositories/TransactionRepository.java
This file contains 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 |
---|---|---|
@@ -1,13 +1,28 @@ | ||
package com.fjb.sunrise.repositories; | ||
|
||
|
||
import com.fjb.sunrise.enums.ETrans; | ||
import com.fjb.sunrise.models.Transaction; | ||
import java.time.LocalDateTime; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
|
||
|
||
public interface TransactionRepository extends JpaRepository<Transaction, Long>, | ||
JpaSpecificationExecutor<Transaction> { | ||
|
||
Page<Transaction> findAll(Pageable pageable); | ||
|
||
@Query("select sum(t.amount) from Transaction t " | ||
+ "where t.updatedAt between ?1 and ?2") | ||
Double sumAmountInRange(LocalDateTime start, LocalDateTime end); | ||
|
||
@Query("select sum(t.amount) from Transaction t " | ||
+ "where t.transactionType = ?1 and t.updatedAt between ?2 and ?3 ") | ||
Double sumTransactionTypeINInThisYear(ETrans transactionType, LocalDateTime start, LocalDateTime end); | ||
|
||
} |
This file contains 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 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 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 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
Oops, something went wrong.