-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathGastosController.java
More file actions
62 lines (44 loc) · 1.86 KB
/
GastosController.java
File metadata and controls
62 lines (44 loc) · 1.86 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
52
53
54
55
56
57
58
59
60
61
62
package br.com.altrantest.demo.controller;
import br.com.altrantest.demo.gastos.GastoByUser;
import br.com.altrantest.demo.repository.GastosRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RequestMapping("/v1/gastos")
@RestController
public class GastosController {
@Autowired
private GastosRepository gastosRepository;
private GastoByUser gastosByUser;
//Controle de gastos
@GetMapping(path = "/user/all")
public ResponseEntity<?> findAllGastos() {
return new ResponseEntity<>(gastosRepository.findAll(), HttpStatus.OK);
}
@GetMapping(path = "/user/{id}")
public ResponseEntity<?> getGastosById(@PathVariable("id") Long id) {
GastoByUser gastos = gastosRepository.findById(id).get();
return new ResponseEntity<>(gastos, HttpStatus.OK);
}
@PostMapping(path = "/user")
public ResponseEntity<GastoByUser> adcionarGastos(@RequestBody GastoByUser gastosByUser) {
gastosByUser = gastosRepository.save(gastosByUser);
return ResponseEntity.ok().body(gastosByUser);
}
@DeleteMapping(path = "/admin/{id}")
public ResponseEntity<?> deleteGastos(@PathVariable Long id) {
gastosRepository.deleteById(id);
return new ResponseEntity<>(HttpStatus.OK);
}
@PutMapping(path = "/{id}")
public ResponseEntity<?> update(@RequestBody GastoByUser gastoByUser) {
gastosRepository.save(gastoByUser);
return new ResponseEntity<>(HttpStatus.OK);
}
@GetMapping(path = "/user/filtro/{descricao}")
@ResponseBody
public ResponseEntity<?> getByDesc(@PathVariable String descricao) {
return new ResponseEntity<>(gastosRepository.findByDescricao(descricao), HttpStatus.OK);
}
}