Skip to content

Commit 2200973

Browse files
committed
Correction Spring
2 parents 9e79088 + 6998047 commit 2200973

File tree

7 files changed

+54
-7
lines changed

7 files changed

+54
-7
lines changed

pom.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<java.version>15</java.version>
1919
</properties>
2020
<dependencies>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-data-jpa</artifactId>
24+
</dependency>
2125
<dependency>
2226
<groupId>org.springframework.boot</groupId>
2327
<artifactId>spring-boot-starter-validation</artifactId>
@@ -30,7 +34,6 @@
3034
<groupId>org.springframework.boot</groupId>
3135
<artifactId>spring-boot-starter-web</artifactId>
3236
</dependency>
33-
3437
<dependency>
3538
<groupId>org.springframework.boot</groupId>
3639
<artifactId>spring-boot-devtools</artifactId>

src/main/java/com/itacademy/CrudEmpleats/CrudEmpleatsApplication.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
56

6-
@SpringBootApplication
7+
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
78
public class CrudEmpleatsApplication {
89

910
public static void main(String[] args) {

src/main/java/com/itacademy/CrudEmpleats/controller/ControllerEmployees.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import org.springframework.web.bind.annotation.*;
1010

1111
import com.itacademy.CrudEmpleats.domain.Employee;
12-
import com.itacademy.CrudEmpleats.persistence.EmployeeRepository;
12+
import com.itacademy.CrudEmpleats.service.EmployeeServices;
1313

1414
@RestController
1515
public class ControllerEmployees {
@@ -18,7 +18,7 @@ public class ControllerEmployees {
1818
*/
1919

2020
@Autowired
21-
private EmployeeRepository repositori;
21+
private EmployeeServices repositori;
2222

2323
// Crear nou empleat
2424
@PostMapping( "/EmployeeList")

src/main/java/com/itacademy/CrudEmpleats/domain/Employee.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package com.itacademy.CrudEmpleats.domain;
22

3+
import javax.persistence.Entity;
4+
import javax.persistence.Id;
35
import javax.validation.constraints.NotBlank;
46
import javax.validation.constraints.NotNull;
57

8+
@Entity
69
public class Employee {
710

11+
@Id
812
@NotNull
913
private int id;
1014
@NotBlank

src/main/java/com/itacademy/CrudEmpleats/persistence/EmployeeRepository.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
package com.itacademy.CrudEmpleats.persistence;
22

3+
34
import java.util.*;
45

5-
import org.springframework.stereotype.Service;
6+
import org.springframework.stereotype.Repository;
67

78
import com.itacademy.CrudEmpleats.domain.Employee;
89
import com.itacademy.CrudEmpleats.exceptions.IdNotFound;
910

10-
@Service
11+
@Repository
1112
public class EmployeeRepository implements IEmployeeRepository{
1213

1314
// Els objectes persistents únicament en memòria
1415

1516
private static int idcount=0;
1617

17-
private List<Employee> repository = new ArrayList<>(
18+
private static List<Employee> repository = new ArrayList<>(
1819
Arrays.asList(
1920
new Employee(idcount++,"Joan Gordi", "Director_Projectes"),
2021
new Employee(idcount++,"Gerard Puig", "Programador_Mid"),

src/main/java/com/itacademy/CrudEmpleats/persistence/IEmployeeRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.itacademy.CrudEmpleats.domain.Employee;
66

7+
78
public interface IEmployeeRepository {
89

910
public List<Employee> getAllEmployees();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.itacademy.CrudEmpleats.service;
2+
3+
import java.util.*;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Service;
7+
8+
import com.itacademy.CrudEmpleats.domain.Employee;
9+
import com.itacademy.CrudEmpleats.persistence.EmployeeRepository;
10+
11+
@Service
12+
public class EmployeeServices {
13+
14+
@Autowired
15+
private EmployeeRepository repositori;
16+
17+
public List<Employee> getAllEmployees() {
18+
return repositori.getAllEmployees();
19+
}
20+
21+
public Employee getEmployeeById(int id){
22+
return repositori.getEmployeeById(id);
23+
}
24+
25+
public void addEmployee(Employee employee) {
26+
repositori.addEmployee(employee);
27+
}
28+
29+
public void updateEmployee(Employee employee, int id) {
30+
repositori.updateEmployee(employee, id);
31+
}
32+
33+
public void deleteEmployee(int id) {
34+
repositori.deleteEmployee(id);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)