blob: d3fb32e4f12faabb4ecc1af3f7c1415b74f7748e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package com.rinha.backend.service;
import com.rinha.backend.model.PaymentModel;
import com.rinha.backend.model.SummaryModel;
import com.rinha.backend.repository.PaymentRepository;
import org.springframework.stereotype.Service;
import java.time.OffsetDateTime;
import java.util.List;
@Service
public class SummaryService {
private final PaymentRepository paymentRepository;
public SummaryService(PaymentRepository paymentRepository) {
this.paymentRepository = paymentRepository;
}
public SummaryModel getSummary(OffsetDateTime from, OffsetDateTime to) {
SummaryModel summary = new SummaryModel();
if (from == null) from = OffsetDateTime.MIN;
if (to == null) to = OffsetDateTime.MAX;
List<PaymentModel> payments = paymentRepository.findAll();
for (PaymentModel p : payments) {
if(p.getData().isBefore(from) || p.getData().isAfter(to)) continue;
if (p.getProcessor() == 1) {
summary.getProcessorDefault().addTotalRequests(1);
summary.getProcessorDefault().addTotalAmount(p.getAmount());
} else if (p.getProcessor() == 2) {
summary.getProcessorFallback().addTotalRequests(1);
summary.getProcessorFallback().addTotalAmount(p.getAmount());
}
}
return summary;
}
}
|