File tree Expand file tree Collapse file tree 4 files changed +69
-0
lines changed
testeSantanderWay/src/main/java/br/com/testesantanderway Expand file tree Collapse file tree 4 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 11package br .com .testesantanderway .controller ;
22
33
4+ import br .com .testesantanderway .controller .form .AtualizacaoClienteForm ;
45import br .com .testesantanderway .controller .form .ClienteForm ;
56import br .com .testesantanderway .dto .ClienteDTO ;
67import br .com .testesantanderway .dto .DetalheClienteDTO ;
78import br .com .testesantanderway .modelo .Cliente ;
89import br .com .testesantanderway .repository .ClienteRepository ;
910import org .springframework .beans .factory .annotation .Autowired ;
1011import org .springframework .http .ResponseEntity ;
12+ import org .springframework .transaction .annotation .Transactional ;
1113import org .springframework .web .bind .annotation .*;
1214import org .springframework .web .util .UriComponentsBuilder ;
1315
@@ -49,4 +51,11 @@ public DetalheClienteDTO detalhe(@PathVariable String id) {
4951
5052 return new DetalheClienteDTO (cliente );
5153 }
54+
55+ @ PutMapping ("/{id}" )
56+ public ResponseEntity <ClienteDTO > atualizar (@ PathVariable String id , @ RequestBody @ Valid AtualizacaoClienteForm form ) {
57+ Cliente cliente = form .atualizar (id , clienteRepository );
58+
59+ return ResponseEntity .ok (new ClienteDTO (cliente ));
60+ }
5261}
Original file line number Diff line number Diff line change 1+ package br .com .testesantanderway .controller .form ;
2+
3+ import br .com .testesantanderway .modelo .Cliente ;
4+ import br .com .testesantanderway .repository .ClienteRepository ;
5+ import org .hibernate .validator .constraints .Length ;
6+ import javax .validation .constraints .NotEmpty ;
7+ import javax .validation .constraints .NotNull ;
8+
9+ public class AtualizacaoClienteForm {
10+ @ NotNull @ NotEmpty @ Length (min = 11 )
11+ private String email ;
12+ @ NotNull @ NotEmpty @ Length (min = 6 )
13+ private String senha ;
14+
15+ public AtualizacaoClienteForm () {
16+ }
17+
18+ public AtualizacaoClienteForm (Cliente cliente ) {
19+ this .email = cliente .getEmail ();
20+ this .senha = cliente .getSenha ();
21+ }
22+
23+ public String getEmail () {
24+ return email ;
25+ }
26+
27+ public void setEmail (String email ) {
28+ this .email = email ;
29+ }
30+
31+ public String getSenha () {
32+ return senha ;
33+ }
34+
35+ public void setSenha (String senha ) {
36+ this .senha = senha ;
37+ }
38+
39+ public Cliente atualizar (String id , ClienteRepository clienteRepository ) {
40+ Cliente cliente = clienteRepository .findById (id ).orElseThrow (() -> new RuntimeException ("Não encontrado" ));
41+
42+ cliente .setEmail (this .email );
43+ cliente .setSenha (this .senha );
44+
45+ clienteRepository .save (cliente );
46+
47+ return cliente ;
48+ }
49+ }
Original file line number Diff line number Diff line change 11package br .com .testesantanderway .controller .form ;
22
3+ import br .com .testesantanderway .dto .ClienteDTO ;
34import br .com .testesantanderway .modelo .Cliente ;
5+ import br .com .testesantanderway .repository .ClienteRepository ;
46import org .hibernate .validator .constraints .Length ;
57
68import javax .validation .constraints .NotEmpty ;
@@ -15,6 +17,7 @@ public class ClienteForm {
1517 private String email ;
1618 @ NotNull @ NotEmpty @ Length (min = 6 )
1719 private String senha ;
20+
1821 private LocalDateTime dataCriacao ;
1922
2023 public ClienteForm () {
Original file line number Diff line number Diff line change @@ -43,10 +43,18 @@ public String getEmail() {
4343 return email ;
4444 }
4545
46+ public void setEmail (String email ) {
47+ this .email = email ;
48+ }
49+
4650 public String getSenha () {
4751 return senha ;
4852 }
4953
54+ public void setSenha (String senha ) {
55+ this .senha = senha ;
56+ }
57+
5058 public LocalDateTime getDataCriacao () {
5159 return dataCriacao ;
5260 }
You can’t perform that action at this time.
0 commit comments