feat: Get de toutes les tasks de la database
This commit is contained in:
@@ -6,6 +6,8 @@ target/
|
|||||||
!**/src/test/**/target/
|
!**/src/test/**/target/
|
||||||
mvnw
|
mvnw
|
||||||
mvnw.cmd
|
mvnw.cmd
|
||||||
|
application-dev.properties
|
||||||
|
|
||||||
### STS ###
|
### STS ###
|
||||||
.apt_generated
|
.apt_generated
|
||||||
.classpath
|
.classpath
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||||
|
>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@@ -40,10 +43,22 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.postgresql</groupId>
|
||||||
|
<artifactId>postgresql</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -1,21 +1,26 @@
|
|||||||
package myapi.api.Controller;
|
package myapi.api.Controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import myapi.api.Data.DAO.TaskDao;
|
import myapi.api.Data.Repository.TaskRepository;
|
||||||
|
import myapi.api.Model.Task;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/task")
|
@RequestMapping("/task")
|
||||||
public class TaskController {
|
public class TaskController {
|
||||||
@Autowired
|
private final TaskRepository taskRepository;
|
||||||
private TaskDao taskDao;
|
|
||||||
|
|
||||||
|
public TaskController(TaskRepository repository){
|
||||||
|
this.taskRepository = repository;
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("")
|
@GetMapping
|
||||||
public String getTasks(){
|
public List<Task> getTasks(){
|
||||||
return this.taskDao.getTasks().getFirst();
|
return this.taskRepository.findAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
package myapi.api.Data.DAO;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import myapi.api.Model.Enums.Status;
|
|
||||||
import myapi.api.Model.Task;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public class TaskDao {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retourne toutes les tâches de la base de données
|
|
||||||
* @return Une liste de tâches
|
|
||||||
*/
|
|
||||||
public ArrayList<String> getTasks() {
|
|
||||||
ArrayList<String> result = new ArrayList<String>() {};
|
|
||||||
result.add(new Task(1, "test", Status.EnCours, new Date(), 1, 1).toString());
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package myapi.api.Data.Repository;
|
||||||
|
|
||||||
|
import myapi.api.Model.Task;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface TaskRepository extends JpaRepository<Task, Integer> {}
|
||||||
@@ -1,27 +1,27 @@
|
|||||||
package myapi.api.Model;
|
package myapi.api.Model;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import myapi.api.Model.Enums.Status;
|
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name="task")
|
||||||
public class Task {
|
public class Task {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private int id_task;
|
private int id_task;
|
||||||
|
|
||||||
private String name_task;
|
private String name_task;
|
||||||
private Status status_task;
|
private String status_task;
|
||||||
private Date date_task;
|
private Date date_task;
|
||||||
private int priority_task;
|
private Integer priority_task;
|
||||||
private int id_group;
|
private Integer id_group;
|
||||||
|
|
||||||
public Task() {}
|
|
||||||
|
|
||||||
public Task(int id, String name, Status status, Date date, int priority, int group) {
|
|
||||||
this.id_task = id;
|
|
||||||
this.name_task = name;
|
|
||||||
this.status_task = status;
|
|
||||||
this.date_task = date;
|
|
||||||
this.priority_task = priority;
|
|
||||||
this.id_group = group;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getId_task() {
|
public int getId_task() {
|
||||||
return id_task;
|
return id_task;
|
||||||
@@ -39,11 +39,11 @@ public class Task {
|
|||||||
this.name_task = name_task;
|
this.name_task = name_task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Status getStatus_task() {
|
public String getStatus_task() {
|
||||||
return status_task;
|
return status_task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStatus_task(Status status_task) {
|
public void setStatus_task(String status_task) {
|
||||||
this.status_task = status_task;
|
this.status_task = status_task;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,19 +55,19 @@ public class Task {
|
|||||||
this.date_task = date_task;
|
this.date_task = date_task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPriority_task() {
|
public Integer getPriority_task() {
|
||||||
return priority_task;
|
return priority_task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPriority_task(int priority_task) {
|
public void setPriority_task(Integer priority_task) {
|
||||||
this.priority_task = priority_task;
|
this.priority_task = priority_task;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId_group() {
|
public Integer getId_group() {
|
||||||
return id_group;
|
return id_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId_group(int id_group) {
|
public void setId_group(Integer id_group) {
|
||||||
this.id_group = id_group;
|
this.id_group = id_group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
spring.application.name=api
|
spring.application.name=api
|
||||||
|
spring.profiles.active=dev
|
||||||
|
spring.jpa.show-sql=true
|
||||||
|
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||||
Reference in New Issue
Block a user