File tree 3 files changed +21
-2
lines changed
src/main/java/br/com/lasbr 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -38,8 +38,8 @@ A classe `OrderItem` representa um item específico em um pedido. Cada item poss
38
38
- ` GET /users ` : Recuperar todos os usuários cadastrados.
39
39
- ` GET /users/{id} ` : Recuperar um usuário específico por ID.
40
40
- ` POST /users ` : Criar um novo usuário.
41
- - ` PUT /users/{id} ` : Atualizar um usuário existente por ID. (TO-DO)
42
- - ` DELETE /users/{id} ` : Excluir um usuário por ID. (TO-DO)
41
+ - ` PUT /users/{id} ` : Atualizar um usuário existente por ID.
42
+ - ` DELETE /users/{id} ` : Excluir um usuário por ID.
43
43
44
44
45
45
- ** Order** : ` /orders `
Original file line number Diff line number Diff line change 8
8
import org .springframework .web .bind .annotation .GetMapping ;
9
9
import org .springframework .web .bind .annotation .PathVariable ;
10
10
import org .springframework .web .bind .annotation .PostMapping ;
11
+ import org .springframework .web .bind .annotation .PutMapping ;
11
12
import org .springframework .web .bind .annotation .RequestBody ;
12
13
import org .springframework .web .bind .annotation .RequestMapping ;
13
14
import org .springframework .web .bind .annotation .RestController ;
@@ -51,4 +52,10 @@ public ResponseEntity<Void> delete(@PathVariable Long id) {
51
52
service .delete (id );
52
53
return ResponseEntity .noContent ().build ();
53
54
}
55
+
56
+ @ PutMapping (value = "/{id}" )
57
+ public ResponseEntity <User > update (@ PathVariable Long id , @ RequestBody User obj ) {
58
+ obj = service .update (id , obj );
59
+ return ResponseEntity .ok ().body (obj );
60
+ }
54
61
}
Original file line number Diff line number Diff line change @@ -33,5 +33,17 @@ public User insert(User obj) {
33
33
public void delete (Long id ) {
34
34
repository .deleteById (id );
35
35
}
36
+
37
+ public User update (Long id , User obj ) {
38
+ User entity = repository .getReferenceById (id );
39
+ updateData (entity , obj );
40
+ return repository .save (entity );
41
+ }
42
+
43
+ private void updateData (User entity , User obj ) {
44
+ entity .setName (obj .getName ());
45
+ entity .setEmail (obj .getEmail ());
46
+ entity .setPhone (obj .getPhone ());
47
+ }
36
48
}
37
49
You can’t perform that action at this time.
0 commit comments