-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathBanksController.java
More file actions
51 lines (43 loc) · 1.89 KB
/
BanksController.java
File metadata and controls
51 lines (43 loc) · 1.89 KB
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
42
43
44
45
46
47
48
49
50
51
package com.tesobe.obp.api;
import com.tesobe.obp.clientapi.ObpBankMetaApiClient;
import com.tesobe.obp.domain.ATM;
import com.tesobe.obp.domain.Bank;
import com.tesobe.obp.domain.Branch;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@Slf4j
public class BanksController {
private final ObpBankMetaApiClient obpBankMetaApiClient;
public BanksController(ObpBankMetaApiClient obpBankMetaApiClient) {
this.obpBankMetaApiClient = obpBankMetaApiClient;
}
@GetMapping("/branches")
public List<Branch> allBranches() {
List<Bank> allBanks = obpBankMetaApiClient.getBanks().getBanks();
log.info("Fetching branches for " + allBanks);
return allBanks.stream().map(bank -> {
try {
List<Branch> branches = obpBankMetaApiClient.getBranches(bank.getId()).getBranches();
return branches;
} catch (Exception e) {
//TODO: fix API not to return 400 if no branches are found for a bank
return Collections.<Branch>emptyList();
}
}).filter(branches -> branches.size() > 0) //exclude empty branch lists
.flatMap(Collection::stream).collect(Collectors.toList());
}
@GetMapping("/atms")
public List<ATM> allAtms() {
List<Bank> allBanks = obpBankMetaApiClient.getBanks().getBanks();
return allBanks.stream().map(bank -> obpBankMetaApiClient.getAtms(bank.getId()).getAtms())
.filter(branches -> branches.size() > 0) //exclude empty branch lists
.flatMap(Collection::stream).collect(Collectors.toList());
}
}