Skip to content

Czy na pewno chcesz tu zwracać ResponseEntity lub null? #5

@m1kha3l

Description

@m1kha3l

default ResponseEntity<?> checkBuyingLimit(TransactionRepository transactionRepository, String purchaser, int betId, boolean option, int shares) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
cal.add(Calendar.DATE, -1);
String date24hAgo = new SimpleDateFormat(SettingsParams.DATE_FORMAT, Locale.GERMANY).format(cal.getTime());
List<Transaction> userTransactions = transactionRepository.findAllByPurchaserAndBetIdAndOptionInLast24hours(purchaser,betId,option,date24hAgo);
int sumShares = userTransactions.stream().mapToInt(Transaction::getShares).sum();
if(sumShares + shares > SettingsParams.LIMIT_PER_DAY) return ResponseEntity.badRequest().body("Przekroczyłeś dzienny limit zakupów akcji dla tej opcji zakładu. Możesz kupić "+ (SettingsParams.LIMIT_PER_DAY - sumShares) +" akcji");
return null;
}

Może tu nie powinno być zwracane ResponseEntity, tylko np. wartość limitu?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions