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
| @Transactional | |
| public void addBillsUncheckedException(Long id, List<BillVO> billList) { | |
| User user = userRepository.getOne(id); | |
| for (BillVO billVO : billList) { | |
| validateBillWithUncheckedException(billVO); | |
| user.getBillList().add( | |
| new Bill(billVO.getType(), | |
| billVO.getValue(), billVO.getDate(), user)); | |
| } | |
| } |
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
| @Transactional(rollbackFor = Exception.class) | |
| public void addBillsCheckedExceptionWithRollback(Long id, List<BillVO> billList) throws TransactionalException { | |
| User user = userRepository.getOne(id); | |
| for (BillVO billVO : billList) { | |
| validateBillWithCheckedException(billVO); | |
| user.getBillList().add( | |
| new Bill(billVO.getType(), | |
| billVO.getValue(), billVO.getDate(), user)); | |
| } | |
| } |
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
| public class TransactionalException extends Exception { | |
| } |
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
| public Double getTotalValue() { | |
| return getBillList() | |
| .stream() | |
| .mapToDouble(b -> b.getValue().doubleValue()) | |
| .sum(); | |
| } |
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
| @Transactional(readOnly = true) | |
| public User getUser(Long id) { | |
| log.info("M=getUser, id={}", id); | |
| User user = userRepository.getOne(id); | |
| user.setName("Sr(a). " + user.getName()); | |
| return user; | |
| } |
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
| @Transactional | |
| public User getUser(Long id) { | |
| User user = userRepository.getOne(id); | |
| user.setName("Sr(a). " + user.getName()); | |
| return user; | |
| } |
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
| @Transactional | |
| public void addBill(Long id, TypeEnum type, BigDecimal value) { | |
| User user = userRepository.getOne(id); | |
| Bill bill = new Bill(type, value, LocalDate.now(), user); | |
| user.getBillList().add(bill); | |
| } |
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
| @Transactional | |
| public void addUsers(String... documents){ | |
| List.of(documents).forEach(d->userRepository.save(new User( | |
| new Faker(new Locale("pt", "BR")).name().name(), | |
| d, Collections.emptyList()))); | |
| } |
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
| @RestController | |
| @RequestMapping("/user") | |
| @Slf4j | |
| public class UserController { | |
| @Autowired | |
| private UserService userService; | |
| @GetMapping("/total-amount") | |
| public Double getTotalAmount(){ |
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
| spring: | |
| application: | |
| name: test-app2 | |
| cloud: | |
| config: | |
| uri: http://localhost:8080 | |
| label: test-branch | |
| management: | |
| security: |