Rename and Opti

dev
floxx2112 2 years ago
parent dbd113590f
commit 6ea92f86fd
  1. 6
      pom.xml
  2. 26
      src/main/java/com/apside/assistDbBackend/AssistDBBackendApplication.java
  3. 8
      src/main/java/com/apside/assistDbBackend/controller/InfoColumnController.java
  4. 8
      src/main/java/com/apside/assistDbBackend/controller/InfoTableController.java
  5. 6
      src/main/java/com/apside/assistDbBackend/controller/LinkInfoController.java
  6. 9
      src/main/java/com/apside/assistDbBackend/controller/ResetDataController.java
  7. 2
      src/main/java/com/apside/assistDbBackend/model/InfoColumn.java
  8. 2
      src/main/java/com/apside/assistDbBackend/model/InfoTable.java
  9. 2
      src/main/java/com/apside/assistDbBackend/model/LinkInfo.java
  10. 4
      src/main/java/com/apside/assistDbBackend/repository/InfoColumnRepository.java
  11. 5
      src/main/java/com/apside/assistDbBackend/repository/InfoTableRepository.java
  12. 4
      src/main/java/com/apside/assistDbBackend/repository/LinkInfoRepository.java
  13. 6
      src/main/java/com/apside/assistDbBackend/service/InfoColumnService.java
  14. 7
      src/main/java/com/apside/assistDbBackend/service/InfoTableService.java
  15. 8
      src/main/java/com/apside/assistDbBackend/service/LinkInfoService.java
  16. 12
      src/main/java/com/apside/assistDbBackend/service/ResetDataService.java
  17. 94
      src/main/java/com/secondtest/secondtest/controller/EmployeeController.java
  18. 36
      src/main/java/com/secondtest/secondtest/model/Employee.java
  19. 12
      src/main/java/com/secondtest/secondtest/repository/EmployeeRepository.java
  20. 36
      src/main/java/com/secondtest/secondtest/service/EmployeeService.java
  21. 8
      src/main/resources/application.properties
  22. 0
      src/main/resources/assistDbData.json
  23. 1
      src/main/resources/tableSchema.json
  24. 6
      src/test/java/com/apside/assistDbBackend/AssistDBBackendTest.java
  25. 36
      src/test/java/com/secondtest/secondtest/EmployeeRespositoryTest.java

@ -8,10 +8,10 @@
<version>3.0.2</version> <version>3.0.2</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>com.secondtest</groupId> <groupId>com.apside</groupId>
<artifactId>secondtest</artifactId> <artifactId>assistDbBackend</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<name>secondtest</name> <name>assistDbBackend</name>
<description>Demo project for Spring Boot</description> <description>Demo project for Spring Boot</description>
<properties> <properties>
<java.version>19</java.version> <java.version>19</java.version>

@ -1,18 +1,5 @@
package com.secondtest.secondtest; package com.apside.assistDbBackend;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.util.JSONPObject;
import com.secondtest.secondtest.controller.InfoColumnController;
import com.secondtest.secondtest.model.Employee;
import com.secondtest.secondtest.model.InfoColumn;
import com.secondtest.secondtest.model.InfoTable;
import com.secondtest.secondtest.service.InfoColumnService;
import com.secondtest.secondtest.service.InfoTableService;
import com.secondtest.secondtest.service.LinkInfoService;
import org.apache.tomcat.util.json.JSONParser;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -20,21 +7,14 @@ import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter; import org.springframework.web.filter.CorsFilter;
import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@SpringBootApplication @SpringBootApplication
public class SecondtestApplication { public class AssistDBBackendApplication {
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {
SpringApplication.run(SecondtestApplication.class, args); SpringApplication.run(AssistDBBackendApplication.class, args);
} }

@ -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,8 +1,7 @@
package com.secondtest.secondtest.service; package com.apside.assistDbBackend.service;
import com.secondtest.secondtest.model.Employee; import com.apside.assistDbBackend.model.LinkInfo;
import com.secondtest.secondtest.model.LinkInfo; import com.apside.assistDbBackend.repository.LinkInfoRepository;
import com.secondtest.secondtest.repository.LinkInfoRepository;
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;
@ -36,6 +35,7 @@ public class LinkInfoService {
return savedLinkInfo; return savedLinkInfo;
} }
public void truncateMyLink(){ public void truncateMyLink(){
linkInfoRepository.truncateMyLink(); linkInfoRepository.truncateMyLink();
} }

@ -1,8 +1,8 @@
package com.secondtest.secondtest.service; package com.apside.assistDbBackend.service;
import com.secondtest.secondtest.model.InfoColumn; import com.apside.assistDbBackend.model.LinkInfo;
import com.secondtest.secondtest.model.InfoTable; import com.apside.assistDbBackend.model.InfoColumn;
import com.secondtest.secondtest.model.LinkInfo; import com.apside.assistDbBackend.model.InfoTable;
import lombok.Data; import lombok.Data;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -31,7 +31,7 @@ public class ResetDataService {
} }
public void insertEverything() throws IOException { public void insertEverything() throws IOException {
String result = new String(Files.readAllBytes(Paths.get("src/main/resources/testTable.json"))); String result = new String(Files.readAllBytes(Paths.get("src/main/resources/assistDbData.json")));
JSONArray jo = new JSONArray(result); JSONArray jo = new JSONArray(result);
System.out.println("ca marche"); System.out.println("ca marche");
for (int i=0; i<jo.length(); i++){ for (int i=0; i<jo.length(); i++){
@ -103,7 +103,7 @@ public class ResetDataService {
} }
public void checkAndInsertLinks() throws IOException { public void checkAndInsertLinks() throws IOException {
String result = new String(Files.readAllBytes(Paths.get("src/main/resources/testTable.json"))); String result = new String(Files.readAllBytes(Paths.get("src/main/resources/assistDbData.json")));
JSONArray jo = new JSONArray(result); JSONArray jo = new JSONArray(result);
for (int i=0; i<jo.length(); i++){ for (int i=0; i<jo.length(); i++){

@ -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,12 +1,10 @@
package com.secondtest.secondtest; package com.apside.assistDbBackend;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.is;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
@ -14,7 +12,7 @@ import org.springframework.test.web.servlet.MockMvc;
@SpringBootTest @SpringBootTest
@AutoConfigureMockMvc @AutoConfigureMockMvc
class SecondtestApplicationTests { class AssistDBBackendTest {
@Autowired @Autowired
private MockMvc mockMvc; private MockMvc mockMvc;

@ -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…
Cancel
Save