parent
dbd113590f
commit
6ea92f86fd
@ -1,10 +1,8 @@ |
|||||||
package com.secondtest.secondtest.controller; |
package com.apside.assistDbBackend.controller; |
||||||
|
|
||||||
import com.secondtest.secondtest.model.InfoColumn; |
import com.apside.assistDbBackend.model.InfoColumn; |
||||||
import com.secondtest.secondtest.model.InfoTable; |
import com.apside.assistDbBackend.service.InfoColumnService; |
||||||
import com.secondtest.secondtest.service.InfoColumnService; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import org.springframework.data.repository.query.Param; |
|
||||||
import org.springframework.web.bind.annotation.*; |
import org.springframework.web.bind.annotation.*; |
||||||
|
|
||||||
import java.util.ArrayList; |
import java.util.ArrayList; |
@ -1,9 +1,7 @@ |
|||||||
package com.secondtest.secondtest.controller; |
package com.apside.assistDbBackend.controller; |
||||||
|
|
||||||
import com.secondtest.secondtest.model.Employee; |
import com.apside.assistDbBackend.service.InfoTableService; |
||||||
import com.secondtest.secondtest.model.InfoTable; |
import com.apside.assistDbBackend.model.InfoTable; |
||||||
import com.secondtest.secondtest.repository.InfoTableRepository; |
|
||||||
import com.secondtest.secondtest.service.InfoTableService; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import org.springframework.web.bind.annotation.*; |
import org.springframework.web.bind.annotation.*; |
||||||
|
|
@ -1,7 +1,7 @@ |
|||||||
package com.secondtest.secondtest.controller; |
package com.apside.assistDbBackend.controller; |
||||||
|
|
||||||
import com.secondtest.secondtest.model.LinkInfo; |
import com.apside.assistDbBackend.model.LinkInfo; |
||||||
import com.secondtest.secondtest.service.LinkInfoService; |
import com.apside.assistDbBackend.service.LinkInfoService; |
||||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import org.springframework.web.bind.annotation.DeleteMapping; |
import org.springframework.web.bind.annotation.DeleteMapping; |
||||||
import org.springframework.web.bind.annotation.GetMapping; |
import org.springframework.web.bind.annotation.GetMapping; |
@ -1,11 +1,8 @@ |
|||||||
package com.secondtest.secondtest.controller; |
package com.apside.assistDbBackend.controller; |
||||||
|
|
||||||
import java.io.IOException; |
import java.io.IOException; |
||||||
import java.util.Optional; |
|
||||||
import com.secondtest.secondtest.service.InfoColumnService; |
import com.apside.assistDbBackend.service.ResetDataService; |
||||||
import com.secondtest.secondtest.service.InfoTableService; |
|
||||||
import com.secondtest.secondtest.service.LinkInfoService; |
|
||||||
import com.secondtest.secondtest.service.ResetDataService; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import org.springframework.web.bind.annotation.*; |
import org.springframework.web.bind.annotation.*; |
||||||
|
|
@ -1,4 +1,4 @@ |
|||||||
package com.secondtest.secondtest.model; |
package com.apside.assistDbBackend.model; |
||||||
|
|
||||||
import jakarta.persistence.*; |
import jakarta.persistence.*; |
||||||
import lombok.Builder; |
import lombok.Builder; |
@ -1,4 +1,4 @@ |
|||||||
package com.secondtest.secondtest.model; |
package com.apside.assistDbBackend.model; |
||||||
|
|
||||||
import jakarta.persistence.*; |
import jakarta.persistence.*; |
||||||
import lombok.Builder; |
import lombok.Builder; |
@ -1,4 +1,4 @@ |
|||||||
package com.secondtest.secondtest.model; |
package com.apside.assistDbBackend.model; |
||||||
|
|
||||||
import jakarta.persistence.*; |
import jakarta.persistence.*; |
||||||
import lombok.Data; |
import lombok.Data; |
@ -1,6 +1,6 @@ |
|||||||
package com.secondtest.secondtest.repository; |
package com.apside.assistDbBackend.repository; |
||||||
|
|
||||||
import com.secondtest.secondtest.model.InfoColumn; |
import com.apside.assistDbBackend.model.InfoColumn; |
||||||
import org.springframework.data.jpa.repository.Modifying; |
import org.springframework.data.jpa.repository.Modifying; |
||||||
import org.springframework.data.jpa.repository.Query; |
import org.springframework.data.jpa.repository.Query; |
||||||
import org.springframework.data.repository.CrudRepository; |
import org.springframework.data.repository.CrudRepository; |
@ -1,7 +1,6 @@ |
|||||||
package com.secondtest.secondtest.repository; |
package com.apside.assistDbBackend.repository; |
||||||
|
|
||||||
import com.secondtest.secondtest.model.InfoTable; |
import com.apside.assistDbBackend.model.InfoTable; |
||||||
import org.springframework.data.jpa.repository.JpaRepository; |
|
||||||
import org.springframework.data.jpa.repository.Modifying; |
import org.springframework.data.jpa.repository.Modifying; |
||||||
import org.springframework.data.jpa.repository.Query; |
import org.springframework.data.jpa.repository.Query; |
||||||
import org.springframework.data.repository.CrudRepository; |
import org.springframework.data.repository.CrudRepository; |
@ -1,6 +1,6 @@ |
|||||||
package com.secondtest.secondtest.repository; |
package com.apside.assistDbBackend.repository; |
||||||
|
|
||||||
import com.secondtest.secondtest.model.LinkInfo; |
import com.apside.assistDbBackend.model.LinkInfo; |
||||||
import org.springframework.data.jpa.repository.Modifying; |
import org.springframework.data.jpa.repository.Modifying; |
||||||
import org.springframework.data.jpa.repository.Query; |
import org.springframework.data.jpa.repository.Query; |
||||||
import org.springframework.data.repository.CrudRepository; |
import org.springframework.data.repository.CrudRepository; |
@ -1,7 +1,7 @@ |
|||||||
package com.secondtest.secondtest.service; |
package com.apside.assistDbBackend.service; |
||||||
|
|
||||||
import com.secondtest.secondtest.model.InfoColumn; |
import com.apside.assistDbBackend.repository.InfoColumnRepository; |
||||||
import com.secondtest.secondtest.repository.InfoColumnRepository; |
import com.apside.assistDbBackend.model.InfoColumn; |
||||||
import lombok.Data; |
import lombok.Data; |
||||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
@ -1,8 +1,7 @@ |
|||||||
package com.secondtest.secondtest.service; |
package com.apside.assistDbBackend.service; |
||||||
|
|
||||||
import com.secondtest.secondtest.model.Employee; |
import com.apside.assistDbBackend.repository.InfoTableRepository; |
||||||
import com.secondtest.secondtest.model.InfoTable; |
import com.apside.assistDbBackend.model.InfoTable; |
||||||
import com.secondtest.secondtest.repository.InfoTableRepository; |
|
||||||
import lombok.Data; |
import lombok.Data; |
||||||
import org.springframework.beans.factory.annotation.Autowired; |
import org.springframework.beans.factory.annotation.Autowired; |
||||||
import org.springframework.stereotype.Service; |
import org.springframework.stereotype.Service; |
@ -1,94 +0,0 @@ |
|||||||
package com.secondtest.secondtest.controller; |
|
||||||
|
|
||||||
import java.util.Optional; |
|
||||||
import com.secondtest.secondtest.model.Employee; |
|
||||||
import com.secondtest.secondtest.service.EmployeeService; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.web.bind.annotation.*; |
|
||||||
|
|
||||||
@RestController |
|
||||||
@RequestMapping("/api") |
|
||||||
public class EmployeeController { |
|
||||||
@Autowired |
|
||||||
private EmployeeService employeeService; |
|
||||||
|
|
||||||
/** |
|
||||||
* Create - Add a new employee |
|
||||||
* @param employee An object employee |
|
||||||
* @return The employee object saved |
|
||||||
*/ |
|
||||||
@PostMapping("/employee/add") |
|
||||||
public Employee createEmployee(@RequestBody Employee employee) { |
|
||||||
return employeeService.addOrUpdateEmployee(employee); |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Read - Get one employee |
|
||||||
* @param id The id of the employee |
|
||||||
* @return An Employee object full filled |
|
||||||
*/ |
|
||||||
@GetMapping("/employee/{id}") |
|
||||||
public Employee getEmployee(@PathVariable("id") final Long id) { |
|
||||||
Optional<Employee> employee = employeeService.getEmployee(id); |
|
||||||
if(employee.isPresent()) { |
|
||||||
return employee.get(); |
|
||||||
} else { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Read - Get all employees |
|
||||||
* @return - An Iterable object of Employee full filled |
|
||||||
*/ |
|
||||||
@GetMapping("/employees/all") |
|
||||||
public Iterable<Employee> getEmployees() { |
|
||||||
return employeeService.getAllEmployees(); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Update - Update an existing employee |
|
||||||
* @param id - The id of the employee to update |
|
||||||
* @param employee - The employee object updated |
|
||||||
* @return |
|
||||||
*/ |
|
||||||
@PutMapping("/employee/update/{id}") |
|
||||||
public Employee updateEmployee(@PathVariable("id") final Long id, @RequestBody Employee employee) { |
|
||||||
Optional<Employee> e = employeeService.getEmployee(id); |
|
||||||
if(e.isPresent()) { |
|
||||||
Employee currentEmployee = e.get(); |
|
||||||
|
|
||||||
String firstName = employee.getFirstName(); |
|
||||||
if(firstName != null) { |
|
||||||
currentEmployee.setFirstName(firstName); |
|
||||||
} |
|
||||||
String lastName = employee.getLastName(); |
|
||||||
if(lastName != null) { |
|
||||||
currentEmployee.setLastName(lastName);; |
|
||||||
} |
|
||||||
String mail = employee.getMail(); |
|
||||||
if(mail != null) { |
|
||||||
currentEmployee.setMail(mail); |
|
||||||
} |
|
||||||
String password = employee.getPassword(); |
|
||||||
if(password != null) { |
|
||||||
currentEmployee.setPassword(password);; |
|
||||||
} |
|
||||||
employeeService.addOrUpdateEmployee(currentEmployee); |
|
||||||
return currentEmployee; |
|
||||||
} else { |
|
||||||
return null; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Delete - Delete an employee |
|
||||||
* @param id - The id of the employee to delete |
|
||||||
*/ |
|
||||||
@DeleteMapping("/employee/delete/{id}") |
|
||||||
public void deleteEmployee(@PathVariable("id") final Long id) { |
|
||||||
employeeService.deleteEmployee(id); |
|
||||||
} |
|
||||||
} |
|
@ -1,36 +0,0 @@ |
|||||||
package com.secondtest.secondtest.model; |
|
||||||
|
|
||||||
import jakarta.persistence.*; |
|
||||||
import lombok.Builder; |
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
@Data |
|
||||||
@Builder |
|
||||||
@Entity |
|
||||||
@Table(name = "employees") |
|
||||||
public class Employee { |
|
||||||
|
|
||||||
@Id |
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY) |
|
||||||
private Long id; |
|
||||||
|
|
||||||
@Column(name="first_name") |
|
||||||
private String firstName; |
|
||||||
|
|
||||||
@Column(name="last_name") |
|
||||||
private String lastName; |
|
||||||
|
|
||||||
private String mail; |
|
||||||
|
|
||||||
private String password; |
|
||||||
|
|
||||||
public Employee(){} |
|
||||||
public Employee(Long id, String firstName, String lastName, String mail, String password){ |
|
||||||
this.id = id; |
|
||||||
this.firstName = firstName; |
|
||||||
this.lastName = lastName; |
|
||||||
this.mail = mail; |
|
||||||
this.password = password; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,12 +0,0 @@ |
|||||||
package com.secondtest.secondtest.repository; |
|
||||||
|
|
||||||
import com.secondtest.secondtest.model.Employee; |
|
||||||
import org.springframework.data.repository.CrudRepository; |
|
||||||
import org.springframework.stereotype.Repository; |
|
||||||
|
|
||||||
import java.util.Optional; |
|
||||||
|
|
||||||
@Repository |
|
||||||
public interface EmployeeRepository extends CrudRepository<Employee, Long> { |
|
||||||
|
|
||||||
} |
|
@ -1,36 +0,0 @@ |
|||||||
package com.secondtest.secondtest.service; |
|
||||||
|
|
||||||
import java.util.Optional; |
|
||||||
|
|
||||||
import com.secondtest.secondtest.model.Employee; |
|
||||||
import com.secondtest.secondtest.repository.EmployeeRepository; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.stereotype.Service; |
|
||||||
|
|
||||||
import lombok.Data; |
|
||||||
|
|
||||||
@Data |
|
||||||
@Service |
|
||||||
public class EmployeeService { |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private EmployeeRepository employeeRepository; |
|
||||||
|
|
||||||
public Optional<Employee> getEmployee(final Long id) { |
|
||||||
return employeeRepository.findById(id); |
|
||||||
} |
|
||||||
|
|
||||||
public Iterable<Employee> getAllEmployees() { |
|
||||||
return employeeRepository.findAll(); |
|
||||||
} |
|
||||||
|
|
||||||
public void deleteEmployee(final Long id) { |
|
||||||
employeeRepository.deleteById(id); |
|
||||||
} |
|
||||||
|
|
||||||
public Employee addOrUpdateEmployee(Employee employee) { |
|
||||||
Employee savedEmployee = employeeRepository.save(employee); |
|
||||||
return savedEmployee; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
@ -1,8 +1,8 @@ |
|||||||
|
|
||||||
spring.application.name=TestApp |
spring.application.name=AssistDBBackend |
||||||
spring.datasource.url=jdbc:mysql://localhost:3306/prudencetest |
spring.datasource.url= |
||||||
spring.datasource.username=root |
spring.datasource.username= |
||||||
spring.datasource.password=Pompom.21 |
spring.datasource.password= |
||||||
|
|
||||||
logging.level.org.springframework.boot.web.embedded.tomcat=INFO |
logging.level.org.springframework.boot.web.embedded.tomcat=INFO |
||||||
logging.level.org.springframework=error |
logging.level.org.springframework=error |
||||||
|
File diff suppressed because one or more lines are too long
@ -1,36 +0,0 @@ |
|||||||
package com.secondtest.secondtest; |
|
||||||
|
|
||||||
import com.secondtest.secondtest.model.Employee; |
|
||||||
import com.secondtest.secondtest.repository.EmployeeRepository; |
|
||||||
import org.junit.jupiter.api.Test; |
|
||||||
import org.springframework.beans.factory.annotation.Autowired; |
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; |
|
||||||
|
|
||||||
import java.util.Optional; |
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals; |
|
||||||
|
|
||||||
@DataJpaTest |
|
||||||
@EnableConfigurationProperties |
|
||||||
public class EmployeeRespositoryTest { |
|
||||||
|
|
||||||
|
|
||||||
@Autowired |
|
||||||
private TestEntityManager entityManager; |
|
||||||
|
|
||||||
@Autowired |
|
||||||
private EmployeeRepository employeeRepository; |
|
||||||
|
|
||||||
/*@Test |
|
||||||
public void testFindId(){ |
|
||||||
Employee employee = new Employee(6L,"Stephano", "Last", "mail", "pass"); |
|
||||||
employeeRepository.save(employee); |
|
||||||
Optional<Employee> result = employeeRepository.findById(employee.getId()); |
|
||||||
assertEquals(employee.getId(), result.get().getId()); |
|
||||||
}*/ |
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} |
|
Loading…
Reference in new issue