Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<java.version>15</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
Expand All @@ -30,7 +34,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class CrudEmpleatsApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.web.bind.annotation.*;

import com.itacademy.CrudEmpleats.domain.Employee;
import com.itacademy.CrudEmpleats.persistence.EmployeeRepository;
import com.itacademy.CrudEmpleats.service.EmployeeServices;

@RestController
public class ControllerEmployees {
Expand All @@ -18,8 +18,8 @@ public class ControllerEmployees {
*/

@Autowired
private EmployeeRepository repositori;
private EmployeeServices repositori;

// Crear nou empleat
@PostMapping( "/EmployeeList")
@ResponseStatus(HttpStatus.CREATED) // 201
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/itacademy/CrudEmpleats/domain/Employee.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.itacademy.CrudEmpleats.domain;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

@Entity
public class Employee {

@Id
@NotNull
private int id;
@NotBlank
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package com.itacademy.CrudEmpleats.persistence;


import java.util.*;

import org.springframework.stereotype.Service;
import org.springframework.stereotype.Repository;

import com.itacademy.CrudEmpleats.domain.Employee;
import com.itacademy.CrudEmpleats.exceptions.IdNotFound;

@Service
@Repository
public class EmployeeRepository implements IEmployeeRepository{

// Els objectes persistents únicament en memòria

private static int idcount=0;

private List<Employee> repository = new ArrayList<>(
private static List<Employee> repository = new ArrayList<>(
Arrays.asList(
new Employee(idcount++,"Joan Gordi", "Director_Projectes"),
new Employee(idcount++,"Gerard Puig", "Programador_Mid"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.itacademy.CrudEmpleats.domain.Employee;


public interface IEmployeeRepository {

public List<Employee> getAllEmployees();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.itacademy.CrudEmpleats.service;

import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itacademy.CrudEmpleats.domain.Employee;
import com.itacademy.CrudEmpleats.persistence.EmployeeRepository;

@Service
public class EmployeeServices {

@Autowired
private EmployeeRepository repositori;

public List<Employee> getAllEmployees() {
return repositori.getAllEmployees();
}

public Employee getEmployeeById(int id){
return repositori.getEmployeeById(id);
}

public void addEmployee(Employee employee) {
repositori.addEmployee(employee);
}

public void updateEmployee(Employee employee, int id) {
repositori.updateEmployee(employee, id);
}

public void deleteEmployee(int id) {
repositori.deleteEmployee(id);
}

}