File tree Expand file tree Collapse file tree 3 files changed +34
-5
lines changed
java/com/itacademy/CrudEmpleats Expand file tree Collapse file tree 3 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 1
1
package com .itacademy .CrudEmpleats .controller ;
2
2
3
- import org .springframework .stereotype .Controller ;
3
+ import java .io .IOException ;
4
+ import java .util .List ;
4
5
5
- @ Controller
6
+ import javax .servlet .http .HttpServletResponse ;
7
+
8
+ import org .springframework .beans .factory .annotation .Autowired ;
9
+ import org .springframework .web .bind .annotation .GetMapping ;
10
+ import org .springframework .web .bind .annotation .RestController ;
11
+
12
+ import com .itacademy .CrudEmpleats .domain .Employee ;
13
+ import com .itacademy .CrudEmpleats .persistence .EmployeeRepository ;
14
+
15
+ @ RestController
6
16
public class ControllerEmployees {
7
17
8
18
/*
@@ -21,4 +31,21 @@ public class ControllerEmployees {
21
31
*
22
32
*/
23
33
34
+ @ Autowired
35
+ private EmployeeRepository repositori ;
36
+
37
+ //Temporalment redirigim a la llista d'empleats
38
+ @ GetMapping ("/" )
39
+ void start (HttpServletResponse reponse ) throws IOException {
40
+ reponse .sendRedirect ("/Empleat" );;
41
+ }
42
+
43
+ //Retorna una llista JSon d'empleats
44
+ @ GetMapping ("/Empleat" )
45
+ public List <Employee > allEmployees (){
46
+ return repositori .getAllEmployees ();
47
+ }
48
+
49
+
50
+
24
51
}
Original file line number Diff line number Diff line change 1
1
package com .itacademy .CrudEmpleats .persistence ;
2
2
3
- import java .util .ArrayList ;
4
- import java .util .Arrays ;
3
+ import java .util .*;
5
4
6
5
import org .springframework .stereotype .Service ;
7
6
@@ -15,12 +14,15 @@ public class EmployeeRepository {
15
14
*
16
15
*/
17
16
18
- private ArrayList <Employee > repository = new ArrayList <>(
17
+ private List <Employee > repository = new ArrayList <>(
19
18
Arrays .asList (
20
19
new Employee ("Juan" , "Director de Projectes" ),
21
20
new Employee ("Gerard" , "Programador" ),
22
21
new Employee ("Maria" , "Administrativa" )
23
22
)
24
23
);
24
+ public List <Employee > getAllEmployees () {
25
+ return repository ;
26
+ }
25
27
26
28
}
File renamed without changes.
You can’t perform that action at this time.
0 commit comments