Skip to content
Snippets Groups Projects
Commit eab500c5 authored by mariaeloi's avatar mariaeloi
Browse files

altera rota e retorno de withdrawal

parent d5022799
No related branches found
No related tags found
1 merge request!5Rest
package br.ufrn.imd.withdrawal.controller; package br.ufrn.imd.withdrawal.controller;
import br.ufrn.imd.withdrawal.domain.Account;
import br.ufrn.imd.withdrawal.domain.Client; import br.ufrn.imd.withdrawal.domain.Client;
import br.ufrn.imd.withdrawal.service.WithdrawalService; import br.ufrn.imd.withdrawal.service.WithdrawalService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
...@@ -10,14 +9,14 @@ import org.springframework.web.bind.annotation.*; ...@@ -10,14 +9,14 @@ import org.springframework.web.bind.annotation.*;
@AllArgsConstructor @AllArgsConstructor
@RestController @RestController
@RequestMapping("/banking/client/{id}/withdrawal") @RequestMapping("/banking/client/{id}")
public class WithdrawalController { public class WithdrawalController {
@Autowired @Autowired
private final WithdrawalService service; private final WithdrawalService service;
@PatchMapping @PatchMapping
@ResponseStatus(HttpStatus.OK) @ResponseStatus(HttpStatus.OK)
public Account withdrawal(@PathVariable Integer id, @RequestParam(name = "value") Double value) { public Client withdrawal(@PathVariable Integer id, @RequestParam(name = "value") Double value) {
return service.withdraw(value, new Client(id)); return service.withdraw(value, new Client(id));
} }
} }
...@@ -15,7 +15,7 @@ public class WithdrawalService { ...@@ -15,7 +15,7 @@ public class WithdrawalService {
@Autowired @Autowired
private final ClientRepository clientRepository; private final ClientRepository clientRepository;
public Account withdraw(Double value, Client client) { public Client withdraw(Double value, Client client) {
client = clientRepository.findById(client.getId()) client = clientRepository.findById(client.getId())
.orElseThrow(() -> new RuntimeException("Invalid user!")); .orElseThrow(() -> new RuntimeException("Invalid user!"));
...@@ -26,6 +26,6 @@ public class WithdrawalService { ...@@ -26,6 +26,6 @@ public class WithdrawalService {
client = clientRepository.save(client); client = clientRepository.save(client);
log.info("Withdrawal concluded!"); log.info("Withdrawal concluded!");
log.info(String.format("Account balance: R$ %.2f", client.getAccount().getBalance())); log.info(String.format("Account balance: R$ %.2f", client.getAccount().getBalance()));
return account; return client;
} }
} }
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