Skip to content
Snippets Groups Projects
Commit 6ab4409e authored by Fernando Ferreira de Lima Filho's avatar Fernando Ferreira de Lima Filho
Browse files

feature: client integrationd with balance service

parent fff9ed03
No related branches found
No related tags found
1 merge request!5Rest
......@@ -4,15 +4,15 @@ package br.ufrn.imd.balance.controller;
import br.ufrn.imd.balance.domain.Client;
import br.ufrn.imd.balance.service.BalanceService;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
@AllArgsConstructor
@RequiredArgsConstructor
@RestController
@RequestMapping("/banking/client/{id}")
public class BalanceController {
@Autowired
private final BalanceService service;
@GetMapping
......
......@@ -110,11 +110,14 @@ public class MachineState {
}
} else if(state.equals(DEPOSIT)) {
String v = sc.nextLine();
DepositMessage depositMessage = new DepositMessage(this.client, Double.parseDouble(v));
ResponseEntity<Account> response = restTemplate.postForEntity(HOST_DEPOSIT_SERVICE, depositMessage, Account.class);
ResponseEntity<Client> response =
restTemplate.getForEntity(
HOST_DEPOSIT_SERVICE +
String.format("/%d?value=%s", this.client.getId(), v),
Client.class);
if(response.getStatusCodeValue() == 200) {
System.out.println(
String.format(">>> Your balance is: %.2f", response.getBody().getBalance())
String.format(">>> Your balance is: %.2f", response.getBody().getAccount().getBalance())
);
}
try {
......
......@@ -8,7 +8,7 @@ public class NameSpace {
public static final Integer PORT_TRANSFER_SERVICE = 8080;
public final static String HOST_AUTHENTICATOR_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_AUTHENTICATOR_SERVICE, "authenticator");
public final static String HOST_WITHDRAWAL_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_WITHDRAWAL_SERVICE, "withdrawal");
public static final String HOST_DEPOSIT_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_DEPOSIT_SERVICE, "deposit");
public static final String HOST_DEPOSIT_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_DEPOSIT_SERVICE, "/gateway/deposit/banking/client");
public static final String HOST_BALANCE_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_BALANCE_SERVICE, "/gateway/balance/banking/client");
public final static String HOST_TRANSFER_SERVICE = String.format("http://127.0.0.1:%d/%s", PORT_TRANSFER_SERVICE, "transfer");
}
......@@ -14,7 +14,7 @@ public class DepositController {
@Autowired
private final DepositService service;
@PatchMapping
@GetMapping
@ResponseStatus(HttpStatus.OK)
public Client deposit(@PathVariable Integer id, @RequestParam(name = "value") Double value) {
return service.deposit(value, new Client(id));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment