WalletController.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package com.platform2easy.genesis.web.controller;
  2. import com.platform2easy.genesis.domain.model.Wallet;
  3. import com.platform2easy.genesis.domain.service.WalletService;
  4. import lombok.AllArgsConstructor;
  5. import org.springframework.http.HttpStatus;
  6. import org.springframework.web.bind.annotation.*;
  7. import java.util.List;
  8. @RestController
  9. @RequestMapping("/api/wallet")
  10. @AllArgsConstructor
  11. public class WalletController {
  12. private final WalletService service;
  13. @GetMapping
  14. @ResponseStatus(HttpStatus.OK)
  15. public List<Wallet> listAll() {
  16. return service.listarTodos();
  17. }
  18. @GetMapping("/{id}")
  19. @ResponseStatus(HttpStatus.OK)
  20. public Wallet getById(@PathVariable Long id) {
  21. return service.buscarPorId(id);
  22. }
  23. @PostMapping
  24. @ResponseStatus(HttpStatus.CREATED)
  25. public Wallet create(@RequestBody Wallet wallet) {
  26. wallet.setId(null);
  27. return service.salvar(wallet);
  28. }
  29. @PutMapping("/{id}")
  30. @ResponseStatus(HttpStatus.OK)
  31. public Wallet update(@PathVariable Long id, @RequestBody Wallet wallet) {
  32. wallet.setId(id);
  33. return service.salvar(wallet);
  34. }
  35. @DeleteMapping("/{id}")
  36. @ResponseStatus(HttpStatus.NO_CONTENT)
  37. public void delete(@PathVariable Long id) {
  38. service.deletarPorId(id);
  39. }
  40. }