Compare commits
8 Commits
695371b024
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5327e66976 | |||
| 5c830c86ba | |||
| 561978e93f | |||
| 1c81385baf | |||
| 29a127e2f6 | |||
| 727fd7ec38 | |||
| 0bb19180e1 | |||
| f76fa086de |
@@ -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
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# My API
|
||||||
|
|
||||||
|
Une API personnelle généraliste permettant d'interroger une BDD self-hosted. Elle sera utilisée à terme par plusieurs applications différentes, dont Do It Earlier, une application de calendrier ou un tracker de films/séries/... .
|
||||||
|
|
||||||
|
# Stack
|
||||||
|
|
||||||
|
API réalisée en Sprinboot 4.1.1 interrogeant une base de données PostgreSQL.
|
||||||
@@ -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,6 +43,22 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||||
|
</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>
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package myapi.api.Controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.Project;
|
||||||
|
import myapi.api.Service.Interfaces.ProjectService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe servant de point d'entrée pour les objets {@link Project}
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/project")
|
||||||
|
@CrossOrigin
|
||||||
|
public class ProjectController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProjectService projectService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère tous les projets de la bdd
|
||||||
|
* @return Une liste de Project
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public List<Project> getAllProjects() {
|
||||||
|
return projectService.getAllProjects();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un projet à la bdd
|
||||||
|
* @param project Le projet à ajouter
|
||||||
|
* @return Le projet ajouté
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Project addProject(@RequestBody Project project) {
|
||||||
|
return projectService.addProject(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifie un projet de la bdd
|
||||||
|
* @param project Le projet que l'on veut modifier. Il faut que son id soit déjà présent
|
||||||
|
* @return Le projet créé
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
public Project updateProject(@RequestBody Project project) {
|
||||||
|
return projectService.updateProject(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprime un projet de la bdd à partir de son identifiant
|
||||||
|
* @param idProject L'identifiant du projet à supprimer
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
public void deleteProject(@RequestParam("id") int idProject) {
|
||||||
|
projectService.deleteProject(idProject);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package myapi.api.Controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.Task;
|
||||||
|
import myapi.api.Service.Interfaces.TaskService;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe servant de point d'entrée pour les objets Tâches
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/task")
|
||||||
|
@CrossOrigin
|
||||||
|
public class TaskController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskService taskService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère toutes les tâches de la bdd
|
||||||
|
* @return Une liste de Task
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public List<Task> getAllTasks() {
|
||||||
|
return taskService.getAllTasks();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute une nouvelle tâche à la bdd
|
||||||
|
* @param task L'objet tâche que l'on veut ajouter
|
||||||
|
* @return La tâche créée
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Task addTask(@RequestBody Task task) {
|
||||||
|
return taskService.addTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifie une tâche de la bdd
|
||||||
|
* @param task La tâche que l'on veut modifier. Il faut que son id soit déjà présent
|
||||||
|
* @return La tâche créée
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
public Task updateTask(@RequestBody Task task) {
|
||||||
|
return taskService.updateTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprime une tâche de la bdd
|
||||||
|
* @param idTask L'id de la tâche
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
public void deleteTask(@RequestParam("id") int idTask) {
|
||||||
|
taskService.deleteTask(idTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package myapi.api.Controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.TaskGroup;
|
||||||
|
import myapi.api.Service.Interfaces.TaskGroupService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe servant de point d'entrée pour les objets TaskGroup
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/group")
|
||||||
|
@CrossOrigin
|
||||||
|
public class TaskGroupController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskGroupService taskGroupService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère tous les groupes de la bdd
|
||||||
|
* @return Une liste de {@link TaskGroup}
|
||||||
|
*/
|
||||||
|
@GetMapping
|
||||||
|
public List<TaskGroup> getAllGroups() {
|
||||||
|
return taskGroupService.getAllGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un nouveau groupe à la bdd
|
||||||
|
* @param group L'objet que l'on veut ajouter
|
||||||
|
* @return Le groupe ajouté
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public TaskGroup addGroup(@RequestBody TaskGroup group) {
|
||||||
|
return taskGroupService.addGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifie un groupe de la bdd
|
||||||
|
* @param group Le groupe que l'on veut modifier. Il faut que son id soit déjà présent
|
||||||
|
* @return Le groupe modifié
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
public TaskGroup updateGroup(@RequestBody TaskGroup group) {
|
||||||
|
return taskGroupService.updateGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprime un groupe de la bdd
|
||||||
|
* @param idGroup L'identifiant du groupe
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete")
|
||||||
|
public void deleteGroup(@RequestParam("id") int idGroup) {
|
||||||
|
taskGroupService.deleteGroup(idGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package myapi.api.Model.Enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumération des différents status possibles pour une tâche
|
||||||
|
* Status
|
||||||
|
*/
|
||||||
|
public enum Status {
|
||||||
|
En_cours,
|
||||||
|
Termine,
|
||||||
|
En_retard,
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package myapi.api.Model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import org.hibernate.annotations.Audited.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe mappée à la table project de la bdd
|
||||||
|
* Project
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "project")
|
||||||
|
public class Project {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private int id_project;
|
||||||
|
|
||||||
|
private String name_project;
|
||||||
|
|
||||||
|
/* --- GETTERS ET SETTERS --- */
|
||||||
|
|
||||||
|
public int getId_project() {
|
||||||
|
return id_project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId_project(int id_project) {
|
||||||
|
this.id_project = id_project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName_project() {
|
||||||
|
return name_project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName_project(String name_project) {
|
||||||
|
this.name_project = name_project;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,81 @@
|
|||||||
package myapi.api.Model;
|
package myapi.api.Model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe mappée à la table task de la bdd
|
||||||
|
* Task
|
||||||
|
*/
|
||||||
|
@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 String status_task;
|
||||||
|
private Date date_task;
|
||||||
|
private Integer priority_task;
|
||||||
|
private Integer id_group;
|
||||||
|
|
||||||
|
/* --- GETTERS ET SETTER --- */
|
||||||
|
|
||||||
|
public int getId_task() {
|
||||||
|
return id_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId_task(int id_task) {
|
||||||
|
this.id_task = id_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName_task() {
|
||||||
|
return name_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName_task(String name_task) {
|
||||||
|
this.name_task = name_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus_task() {
|
||||||
|
return status_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus_task(String status_task) {
|
||||||
|
this.status_task = status_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate_task() {
|
||||||
|
return date_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate_task(Date date_task) {
|
||||||
|
this.date_task = date_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPriority_task() {
|
||||||
|
return priority_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriority_task(Integer priority_task) {
|
||||||
|
this.priority_task = priority_task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId_group() {
|
||||||
|
return id_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId_group(Integer id_group) {
|
||||||
|
this.id_group = id_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "id : " + this.id_group;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package myapi.api.Model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Classe mappée à la table task_group de la bdd
|
||||||
|
* TaskGroup
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "task_group")
|
||||||
|
public class TaskGroup {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private int id_group;
|
||||||
|
|
||||||
|
private String name_group;
|
||||||
|
private Integer id_project;
|
||||||
|
|
||||||
|
/* --- GETTERS ET SETTERS --- */
|
||||||
|
|
||||||
|
public int getId_group() {
|
||||||
|
return id_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId_group(int id_group) {
|
||||||
|
this.id_group = id_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName_group() {
|
||||||
|
return name_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName_group(String name_group) {
|
||||||
|
this.name_group = name_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getId_project() {
|
||||||
|
return id_project;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId_project(Integer id_project) {
|
||||||
|
this.id_project = id_project;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package myapi.api.Repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import myapi.api.Model.Project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository Jpa permettant la persistance
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface ProjectRepository extends JpaRepository<Project, Integer> {}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package myapi.api.Repository;
|
||||||
|
|
||||||
|
import myapi.api.Model.TaskGroup;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository Jpa permettant la persistance
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface TaskGroupRepository extends JpaRepository<TaskGroup, Integer> {}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package myapi.api.Repository;
|
||||||
|
|
||||||
|
import myapi.api.Model.Task;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Repository Jpa permettant la persistance
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface TaskRepository extends JpaRepository<Task, Integer> {}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package myapi.api.Service.Implementations;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.Project;
|
||||||
|
import myapi.api.Repository.ProjectRepository;
|
||||||
|
import myapi.api.Service.Interfaces.ProjectService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ProjectServiceImpl implements ProjectService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ProjectRepository projectRepository;
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
* @see myapi.api.Service.Interfaces.ProjectService#getAllProjects()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Project> getAllProjects() {
|
||||||
|
return projectRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see myapi.api.Service.Interfaces.ProjectService#addProject(myapi.api.Model.Project)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Project addProject(Project project) {
|
||||||
|
return projectRepository.save(project);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**(non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see myapi.api.Service.Interfaces.ProjectService#updateProject(myapi.api.Model.Project)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Project updateProject(Project project) {
|
||||||
|
Project dbProject = projectRepository.findById(project.getId_project()).get();
|
||||||
|
dbProject.setId_project(project.getId_project());
|
||||||
|
dbProject.setName_project(project.getName_project());
|
||||||
|
return projectRepository.save(dbProject);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**(non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see myapi.api.Service.Interfaces.ProjectService#deleteProject(int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteProject(int idProject) {
|
||||||
|
projectRepository.deleteById(idProject);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package myapi.api.Service.Implementations;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.TaskGroup;
|
||||||
|
import myapi.api.Repository.TaskGroupRepository;
|
||||||
|
import myapi.api.Service.Interfaces.TaskGroupService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TaskGroupServiceImpl implements TaskGroupService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskGroupRepository taskGroupRepository;
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
* @see myapi.api.Service.Interfaces.TaskGroupService#getAllGroups()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<TaskGroup> getAllGroups() {
|
||||||
|
return taskGroupRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
* @see myapi.api.Service.Interfaces.TaskGroupService#addGroup(myapi.api.Model.TaskGroup)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TaskGroup addGroup(TaskGroup group) {
|
||||||
|
return taskGroupRepository.save(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see myapi.api.Service.Interfaces.TaskGroupService#updateGroup(myapi.api.Model.TaskGroup)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TaskGroup updateGroup(TaskGroup group) {
|
||||||
|
TaskGroup dbGroup = taskGroupRepository.findById(group.getId_group()).get();
|
||||||
|
dbGroup.setName_group(group.getName_group());
|
||||||
|
dbGroup.setId_group(group.getId_group());
|
||||||
|
dbGroup.setId_project(group.getId_project());
|
||||||
|
return taskGroupRepository.save(dbGroup);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see myapi.api.Service.Interfaces.TaskGroupService#deleteGroup(java.lang.Integer)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteGroup(Integer idGroup) {
|
||||||
|
taskGroupRepository.deleteById(idGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package myapi.api.Service.Implementations;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.Task;
|
||||||
|
import myapi.api.Repository.TaskRepository;
|
||||||
|
import myapi.api.Service.Interfaces.TaskService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TaskServiceImpl implements TaskService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TaskRepository taskRepository;
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
* @see myapi.api.Service.Interfaces.TaskService#getAllTasks()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Task> getAllTasks() {
|
||||||
|
return taskRepository.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
* @see myapi.api.Service.Interfaces.TaskService#addTask(myapi.api.Model.Task)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Task addTask(Task task) {
|
||||||
|
return taskRepository.save(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
* @see myapi.api.Service.Interfaces.TaskService#updateTask(myapi.api.Model.Task)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Task updateTask(Task task) {
|
||||||
|
Task dbTask = taskRepository.findById(task.getId_task()).get();
|
||||||
|
dbTask.setName_task(task.getName_task());
|
||||||
|
dbTask.setStatus_task(task.getStatus_task());
|
||||||
|
dbTask.setDate_task(task.getDate_task());
|
||||||
|
dbTask.setPriority_task(task.getPriority_task());
|
||||||
|
dbTask.setId_group(task.getId_group());
|
||||||
|
|
||||||
|
return taskRepository.save(dbTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** (non-Javadoc)
|
||||||
|
* @see myapi.api.Service.Interfaces.TaskService#deleteTask(int)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void deleteTask(int idTask) {
|
||||||
|
taskRepository.deleteById(idTask);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package myapi.api.Service.Interfaces;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.Project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface pour les services de project
|
||||||
|
* ProjectService
|
||||||
|
*/
|
||||||
|
public interface ProjectService {
|
||||||
|
/**
|
||||||
|
* Récupère tous les projets de la database
|
||||||
|
* @return Une liste de projets
|
||||||
|
*/
|
||||||
|
List<Project> getAllProjects();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un nouveau projet
|
||||||
|
* @param project Le nouveau projet
|
||||||
|
* @return Le projet nouvellement créé
|
||||||
|
*/
|
||||||
|
Project addProject(Project project);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifie un projet déjà existant
|
||||||
|
* @param project Le projet à modifier. Il faut que son id existe déjà dans la database
|
||||||
|
* @return Le projet modifié
|
||||||
|
*/
|
||||||
|
Project updateProject(Project project);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprime un projet à partir de son identifiant
|
||||||
|
* @param idProject L'identifiant du projet
|
||||||
|
*/
|
||||||
|
void deleteProject(int idProject);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package myapi.api.Service.Interfaces;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.TaskGroup;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface pour les services de groupe de task
|
||||||
|
*/
|
||||||
|
public interface TaskGroupService {
|
||||||
|
/**
|
||||||
|
* Récupère tous les groupes de tâches de la database
|
||||||
|
* @return Une liste de groupe de tâches
|
||||||
|
*/
|
||||||
|
List<TaskGroup> getAllGroups();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un nouveau groupe de tâche
|
||||||
|
* @param group Le nouveau groupe
|
||||||
|
* @return Le groupe créé
|
||||||
|
*/
|
||||||
|
TaskGroup addGroup(TaskGroup group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifie un groupe déjà existant
|
||||||
|
* @param group Le groupe à modifier. Il faut que son id existe déjà dans la database
|
||||||
|
* @return Le groupe modifié
|
||||||
|
*/
|
||||||
|
TaskGroup updateGroup(TaskGroup group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprime un groupe de tâche déjà existant à partir de son identifiant
|
||||||
|
* @param idGroup L'identifiant du groupe
|
||||||
|
*/
|
||||||
|
void deleteGroup(Integer idGroup);
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package myapi.api.Service.Interfaces;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import myapi.api.Model.Task;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface pour les services de task
|
||||||
|
*/
|
||||||
|
public interface TaskService {
|
||||||
|
/**
|
||||||
|
* Récupère toutes les tâches de la database
|
||||||
|
* @return Une liste de tâches
|
||||||
|
*/
|
||||||
|
List<Task> getAllTasks();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute une nouvelle tâche
|
||||||
|
* @param task La nouvelle tâche
|
||||||
|
* @return La tâche nouvellement créée
|
||||||
|
*/
|
||||||
|
Task addTask(Task task);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modifie une tâche déjà existante
|
||||||
|
* @param task La tâche à modifier. Il faut que son id existe déjà dans la database
|
||||||
|
* @return La tâche modifiée
|
||||||
|
*/
|
||||||
|
Task updateTask(Task task);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Supprime une tâche existante à partir de son identifiant
|
||||||
|
* @param idTask L'id de la tâche à supprimer
|
||||||
|
*/
|
||||||
|
void deleteTask(int idTask);
|
||||||
|
}
|
||||||
@@ -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