File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
src/main/java/com/itacademy/CrudEmpleats Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -45,8 +45,9 @@ void start(HttpServletResponse reponse) throws IOException {
45
45
46
46
// Crear nou empleat
47
47
@ PostMapping ( "/Empleat" )
48
- public void addEmployee (@ RequestBody Employee employee ) {
48
+ public Employee addEmployee (@ RequestBody Employee employee ) {
49
49
repositori .addEmployee (employee );
50
+ return employee ;
50
51
}
51
52
52
53
// Retorna una llista JSon d'empleats
@@ -65,7 +66,12 @@ public Employee getFirstEmployee(@PathVariable("id") int id) {
65
66
}
66
67
}
67
68
68
-
69
+ //Actualitzar Empleat
70
+ @ PutMapping ("/Empleat/{id}" )
71
+ public Employee updateEmployee (@ RequestBody Employee employee , @ PathVariable ("id" ) int id ) {
72
+ repositori .updateEmployee (employee ,id );
73
+ return repositori .getEmployeeById (id );
74
+ }
69
75
70
76
71
77
Original file line number Diff line number Diff line change 10
10
public class EmployeeRepository {
11
11
12
12
/*
13
- * Els objectes seran persistidos únicament en memòria
13
+ * Els objectes seran persistits únicament en memòria
14
14
*
15
15
*/
16
16
@@ -35,4 +35,12 @@ public void addEmployee(Employee employee) {
35
35
36
36
}
37
37
38
+ public void updateEmployee (Employee employee , int id ) {
39
+ for (Employee e : repository ) {
40
+ if (e .getId ()==id ) {
41
+ repository .set (repository .indexOf (e ),employee );
42
+ }
43
+ }
44
+ }
45
+
38
46
}
You can’t perform that action at this time.
0 commit comments