moved project from github
This commit is contained in:
parent
06a1b3434b
commit
ffb81afe49
0
.metadata/.lock
Normal file
0
.metadata/.lock
Normal file
4
.metadata/.lock_info
Normal file
4
.metadata/.lock_info
Normal file
@ -0,0 +1,4 @@
|
||||
#Thu Oct 23 14:22:17 CEST 2025
|
||||
host=Dany-Laptop
|
||||
process-id=19188
|
||||
user=cool_
|
||||
7727
.metadata/.plugins/org.eclipse.buildship.core/gradle/versions.json
Normal file
7727
.metadata/.plugins/org.eclipse.buildship.core/gradle/versions.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,78 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
|
||||
public TaskService(TaskRepository taskRepository) {
|
||||
this.taskRepository = taskRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific task
|
||||
* @param id The id of the task
|
||||
* @param taskDto The updated task
|
||||
* @return
|
||||
*/
|
||||
public void updateTask(Integer id, TaskDto taskDto) {
|
||||
Optional<TaskPO> taskPO = taskRepository.findById(id);
|
||||
taskPO.get().setDescription(taskDto.getDescription());
|
||||
taskPO.get().setStatus(taskDto.getStatus());
|
||||
taskPO.get().setTitle(taskDto.getTitle());
|
||||
taskPO.get().setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
this.taskRepository.save(taskPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void deleteTask(Integer id) {
|
||||
taskRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public TaskPO createTask(TaskPO task) {
|
||||
task.setStatus(TaskStatusEnum.OPEN);
|
||||
return taskRepository.save(task);
|
||||
}
|
||||
|
||||
public List<TaskPO> loadProjectTasks(ProjectPO projectPO) {
|
||||
return taskRepository.findByProject(projectPO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.RestController;
|
||||
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return projectService.loadAllProjects();
|
||||
}
|
||||
|
||||
@PostMapping("/projects")
|
||||
public String createProject() {
|
||||
return "TODO create project";
|
||||
}
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public String deleteProject() {
|
||||
return "TODO delete project";
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TaskDTO {
|
||||
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String description;
|
||||
private TaskStatusEnum status;
|
||||
private Integer projectId;
|
||||
private List<UserDTO> users;
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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.RestController;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.service.TaskService;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@PutMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> updateTask(@PathVariable Integer id, @RequestBody TaskDto task) {
|
||||
this.taskService.updateTask(id, task);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{projectId}")
|
||||
public ResponseEntity<Void> createTask(@PathVariable Integer projectId, @RequestBody TaskDto task) {
|
||||
this.taskService.createTask(task, projectId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/tasks/{id}")
|
||||
public ResponseEntity<TaskDto> loadTask(@PathVariable Integer id) {
|
||||
TaskDto taskDto = this.taskService.loadTask(id);
|
||||
return ResponseEntity.ok(taskDto);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.UserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user
|
||||
* @return return all found user
|
||||
*/
|
||||
public List<UserDto> loadAllUsers() {
|
||||
List<UserPO> userListPO = this.userRepository.findAll();
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
userListDto.add(this.convertUserPOToUserDto(userPO));
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific user
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public UserDto loadUser(Integer id) {
|
||||
Optional<UserPO> userPO = this.userRepository.findById(id);
|
||||
return this.convertUserPOToUserDto(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific user
|
||||
* @param id The id of the user
|
||||
* @param userPO The updated user
|
||||
*/
|
||||
public void updateUser(Integer id, UserDto userDto) {
|
||||
Optional<UserPO> userPO = userRepository.findById(id);
|
||||
userPO.get().setFirstName(userDto.getFirstName());
|
||||
userPO.get().setLastName(userDto.getLastName());
|
||||
this.userRepository.save(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific user
|
||||
* @param id The id of the user
|
||||
*/
|
||||
public void deleteUser(Integer id) {
|
||||
userRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public UserPO createUser(UserPO user) {
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userPO The UserPO object
|
||||
* @return The UserDto object
|
||||
*/
|
||||
private UserDto convertUserPOToUserDto(UserPO userPO) {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
return userDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectService.loadAllProjects();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/projects", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Void> createProject(@RequestBody ProjectDto project) {
|
||||
if(project.getTasks() == null) {
|
||||
project.setTasks(new ArrayList<>());
|
||||
}
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Integer id) {
|
||||
projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{id}")
|
||||
public ResponseEntity<ProjectPO> updateProject(@PathVariable Integer id, @RequestBody ProjectDto project){
|
||||
ProjectPO updatedTask = projectService.updateProject(id, project);
|
||||
return ResponseEntity.ok(updatedTask);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,181 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectDto> loadAllProjects() {
|
||||
List<ProjectPO> projectListPO = this.projectRepository.findAll();
|
||||
List<ProjectDto> projectListDto = new ArrayList<>();
|
||||
|
||||
projectListPO.stream().forEach(projectPO -> {
|
||||
ProjectDto projectDto = new ProjectDto();
|
||||
projectDto.setId(projectPO.getId());
|
||||
projectDto.setTitle(projectPO.getTitle());
|
||||
projectDto.setTasks(projectPO.getTasks());
|
||||
});
|
||||
|
||||
return projectListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getTitle());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskDto> convertTaskPOToTaskDto(List<TaskDto> taskListPO, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.example.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
@Bean
|
||||
public WebMvcConfigurer corsConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("http://localhost:4200") // Angular Frontend
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
public class ProjectPO {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="PROJECT")
|
||||
public class ProjectPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name="name", nullable = false)
|
||||
private String title;
|
||||
|
||||
@OneToMany(mappedBy = "project", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
private List<TaskPO> tasks;
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="TASK")
|
||||
public class TaskPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "title", nullable = false)
|
||||
private String title;
|
||||
|
||||
@Column(name = "description", length = 1000)
|
||||
private String description;
|
||||
|
||||
@Column(name = "status", nullable = false)
|
||||
private TaskStatus status;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "project_id")
|
||||
@JsonBackReference
|
||||
private ProjectPO project;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name ="Task_User", joinColumns= @JoinColumn(name = "task_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
|
||||
@JsonIgnoreProperties("tasks")
|
||||
private List<UserPO> users;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
spring.application.name=taskManagement
|
||||
|
||||
# h2 Database
|
||||
spring.datasource.url=jdbc:h2:file:/data/example
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
|
||||
|
||||
# h2 Console Configuration
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.path=/h2-console
|
||||
spring.h2.console.settings.trace=false
|
||||
spring.h2.console.settings.web-allow-others=false
|
||||
|
||||
# JPA and Hibernate Configuration
|
||||
spring.jpa.hibernate.ddl-auto=create
|
||||
spring.jpa.generate-ddl=true
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.jpa.defer-datasource-initialization=true
|
||||
@ -0,0 +1,54 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="TASK")
|
||||
public class TaskPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "title", nullable = false)
|
||||
private String title;
|
||||
|
||||
@Column(name = "description", length = 1000)
|
||||
private String description;
|
||||
|
||||
@Column(name = "status", nullable = false)
|
||||
private TaskStatusEnum status;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "project_id")
|
||||
@JsonBackReference
|
||||
private ProjectPO project;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name ="Task_User", joinColumns= @JoinColumn(name = "task_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
private List<UserPO> users;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="Project")
|
||||
public class ProjectPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name="name", nullable = false)
|
||||
private String name;
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
public class UserService {
|
||||
|
||||
}
|
||||
@ -0,0 +1,118 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectPO newProject) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(newProject.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getName());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.service.UserService;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public UserController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/users")
|
||||
public List<UserDto> loadAllUser() {
|
||||
return userService.loadAllUsers();
|
||||
}
|
||||
|
||||
@PostMapping("user/{id}")
|
||||
public ResponseEntity<Void> updateUser(@PathVariable Integer id, @RequestBody UserDto user) {
|
||||
userService.updateUser(id, user);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("user/{id}")
|
||||
public ResponseEntity<Void> deleteUser(@PathVariable Integer id){
|
||||
userService.deleteUser(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/user")
|
||||
public ResponseEntity<Void> createUser(@RequestBody UserPO user) {
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectService.loadAllProjects();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/projects", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public void createProject(@RequestBody ProjectDto project) {
|
||||
if(project.getTasks() == null) {
|
||||
project.setTasks(new ArrayList<>());
|
||||
}
|
||||
this.projectService.createProject(project);
|
||||
}
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Integer id) {
|
||||
projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{id}")
|
||||
public ResponseEntity<ProjectPO> updateProject(@PathVariable Integer id, @RequestBody ProjectPO project){
|
||||
ProjectPO updatedTask = projectService.updateProject(id, project);
|
||||
return ResponseEntity.ok(updatedTask);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
|
||||
public TaskService(TaskRepository taskRepository) {
|
||||
this.taskRepository = taskRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific task
|
||||
* @param id The id of the task
|
||||
* @param taskDto The updated task
|
||||
* @return
|
||||
*/
|
||||
public void updateTask(Integer id, TaskDto taskDto) {
|
||||
Optional<TaskPO> taskPO = this.taskRepository.findById(id);
|
||||
taskPO.get().setDescription(taskDto.getDescription());
|
||||
taskPO.get().setStatus(taskDto.getStatus());
|
||||
taskPO.get().setTitle(taskDto.getTitle());
|
||||
taskPO.get().setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
this.taskRepository.save(taskPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific task
|
||||
* @param id The id of the task
|
||||
*/
|
||||
public void deleteTask(Integer id) {
|
||||
this.taskRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new task
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
public void createTask(TaskDto taskDto) {
|
||||
this.taskRepository.save(taskPO);
|
||||
}
|
||||
|
||||
public List<TaskPO> loadProjectTasks(ProjectPO projectPO) {
|
||||
return taskRepository.findByProject(projectPO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectService.loadAllProjects();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/projects", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Void> createProject(@RequestBody ProjectDto project) {
|
||||
if(project.getTasks() == null) {
|
||||
project.setTasks(new ArrayList<>());
|
||||
}
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Integer id) {
|
||||
this.projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> updateProject(@PathVariable Integer id, @RequestBody ProjectDto project){
|
||||
ProjectPO updatedTask = projectService.updateProject(id, project);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,103 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
import com.example.demo.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public TaskService(TaskRepository taskRepository, ProjectRepository projectRepository) {
|
||||
this.taskRepository = taskRepository;
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific task
|
||||
* @param id The id of the task
|
||||
* @param taskDto The updated task
|
||||
* @return
|
||||
*/
|
||||
public void updateTask(Integer id, TaskDto taskDto) {
|
||||
Optional<TaskPO> taskPO = this.taskRepository.findById(id);
|
||||
taskPO.get().setDescription(taskDto.getDescription());
|
||||
taskPO.get().setStatus(taskDto.getStatus());
|
||||
taskPO.get().setTitle(taskDto.getTitle());
|
||||
taskPO.get().setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
this.taskRepository.save(taskPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific task
|
||||
* @param id The id of the task
|
||||
*/
|
||||
public void deleteTask(Integer id) {
|
||||
this.taskRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new task
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
public void createTask(TaskDto taskDto) {
|
||||
this.taskRepository.save(this.convertTaskDtoToTaskPO(taskDto, null));
|
||||
}
|
||||
|
||||
public List<TaskPO> loadProjectTasks(ProjectPO projectPO) {
|
||||
return taskRepository.findByProject(projectPO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskDto The TaskDto object
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO object
|
||||
*/
|
||||
private TaskPO convertTaskDtoToTaskPO(TaskDto taskDto, Integer projectId) {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
return taskPO;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
public class Project {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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.RestController;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.service.TaskService;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@PutMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> updateTask(@PathVariable Integer id, @RequestBody TaskDto task) {
|
||||
this.taskService.updateTask(id, task);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> createTask(@PathVariable Integer projectId, @RequestBody TaskDto task) {
|
||||
this.taskService.createTask(task, projectId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/task")
|
||||
public ResponseEntity<TaskDto> loadTask(@PathVariable Integer id) {
|
||||
TaskDto taskDto = this.taskService.loadTask(id);
|
||||
return ResponseEntity.ok(taskDto);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,181 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectDto> loadAllProjects() {
|
||||
List<ProjectPO> projectListPO = this.projectRepository.findAll();
|
||||
List<ProjectDto> projectListDto = new ArrayList<>();
|
||||
|
||||
projectListPO.stream().forEach(projectPO -> {
|
||||
ProjectDto projectDto = new ProjectDto();
|
||||
projectDto.setId(projectPO.getId());
|
||||
projectDto.setTitle(projectPO.getTitle());
|
||||
projectDto.setTasks(this.convertTaskPOToTaskDto(projectPO.getTasks(), projectPO.getId()));
|
||||
});
|
||||
|
||||
return projectListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectDto loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
|
||||
return this.convertProjectDtoToProjectPO(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param projectDto The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getTitle());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskPO object into a TaskDto object
|
||||
* @param taskListPO The TaskPO objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskDto objects
|
||||
*/
|
||||
private List<TaskDto> convertTaskPOToTaskDto(List<TaskPO> taskListPO, Integer projectId) {
|
||||
List<TaskDto> taskListDto = new ArrayList<>();
|
||||
taskListPO.stream().forEach(taskPO -> {
|
||||
TaskDto taskDto = new TaskDto();
|
||||
taskDto.setDescription(taskPO.getDescription());
|
||||
taskDto.setId(taskPO.getId());
|
||||
taskDto.setProjectId(projectId);
|
||||
taskDto.setStatus(taskPO.getStatus());
|
||||
taskDto.setTitle(taskPO.getTitle());
|
||||
taskDto.setUsers(this.convertUserPOToUserDto(taskPO.getUsers()));
|
||||
|
||||
taskListDto.add(taskDto);
|
||||
});
|
||||
|
||||
return taskListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userListPO The UserPO objects
|
||||
* @return The UserDto objects
|
||||
*/
|
||||
private List<UserDto> convertUserPOToUserDto(List<UserPO> userListPO) {
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
userListDto.add(userDto);
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="PROJECT")
|
||||
public class ProjectPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name="title", nullable = false)
|
||||
private String title;
|
||||
|
||||
@OneToMany(mappedBy = "project", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@JsonManagedReference
|
||||
private List<TaskPO> tasks;
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.TaskDTO;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.service.TaskService;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@PostMapping("/task/{id}")
|
||||
public ResponseEntity<TaskDTO> updateTask(@PathVariable Integer id, @RequestBody TaskDTO task) {
|
||||
TaskDTO updatedTask = taskService.updateTask(id, task);
|
||||
return ResponseEntity.ok(updatedTask);
|
||||
}
|
||||
|
||||
@DeleteMapping("/task/{id}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/task/{project}")
|
||||
public List<TaskPO> loadProjectTasks(@RequestBody ProjectPO project) {
|
||||
return taskService.loadProjectTasks(project);
|
||||
}
|
||||
|
||||
@PostMapping("/task")
|
||||
public TaskPO createTask(@RequestBody TaskPO task) {
|
||||
return taskService.createTask(task);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
|
||||
public TaskService(TaskRepository taskRepository) {
|
||||
this.taskRepository = taskRepository;
|
||||
}
|
||||
|
||||
public TaskPO updateTask(Integer id, TaskPO newTask) {
|
||||
Optional<TaskPO> task = taskRepository.findById(id);
|
||||
task.get().setDescription(newTask.getDescription());
|
||||
task.get().setProject(newTask.getProject());
|
||||
task.get().setStatus(TaskStatusEnum.OPEN);
|
||||
task.get().setTitle(newTask.getTitle());
|
||||
task.get().setUsers(newTask.getUsers());
|
||||
return taskRepository.save(task.get());
|
||||
}
|
||||
|
||||
public void deleteTask(Integer id) {
|
||||
taskRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public TaskPO createTask(TaskPO task) {
|
||||
task.setStatus(TaskStatusEnum.OPEN);
|
||||
return taskRepository.save(task);
|
||||
}
|
||||
|
||||
public List<TaskPO> loadProjectTasks(ProjectPO projectPO) {
|
||||
return taskRepository.findByProject(projectPO);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,40 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="PROJECT")
|
||||
public class ProjectPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
@Schema(description = "Unique identifier of the project", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="title", nullable = false)
|
||||
@Schema(description = "Title of the project", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String title;
|
||||
|
||||
@OneToMany(mappedBy = "project", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@JsonManagedReference
|
||||
@Schema(description = "List of tasks belonging to the project")
|
||||
private List<TaskPO> tasks;
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
spring.application.name=taskManagement
|
||||
|
||||
# h2 Database
|
||||
spring.datasource.url=jdbc:h2:mem:testdb
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
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.RestController;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
@PostMapping("/task/{id}")
|
||||
public String updateTask() {
|
||||
return "TODO update Task";
|
||||
}
|
||||
|
||||
@DeleteMapping("/task/{id}")
|
||||
public String deleteTask() {
|
||||
return "TODO delete task";
|
||||
}
|
||||
|
||||
@GetMapping("/task/{projectId}")
|
||||
public String loadProjectTasks() {
|
||||
return "TODO load Tasks of Project";
|
||||
}
|
||||
|
||||
@PostMapping("/task")
|
||||
public String createTask() {
|
||||
return "TODO createTask";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="USER")
|
||||
public class UserPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name= "firstname", nullable = false)
|
||||
private String firstName;
|
||||
|
||||
@Column(name="lastname", nullable = false)
|
||||
private String lastName;
|
||||
|
||||
@ManyToMany(mappedBy = "users")
|
||||
private List<TaskPO> tasks;
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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.RestController;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.service.TaskService;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@PutMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> updateTask(@PathVariable Integer id, @RequestBody TaskDto task) {
|
||||
this.taskService.updateTask(id, task);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{id]")
|
||||
public ResponseEntity<Void> createTask(@PathVariable Integer projectId, @RequestBody TaskDto task) {
|
||||
this.taskService.createTask(task, projectId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/task")
|
||||
public ResponseEntity<TaskDto> loadTask(@PathVariable Integer id) {
|
||||
TaskDto taskDto = this.taskService.loadTask(id);
|
||||
return ResponseEntity.ok(taskDto);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,39 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonManagedReference;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="PROJECT")
|
||||
public class ProjectPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
@Schema(description = "Unique identifier of the project", accessMode = Schema.AccessMode.READ_ONLY)
|
||||
private Integer id;
|
||||
|
||||
@Column(name="title", nullable = false)
|
||||
@Schema(description = "Title of the project", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String title;
|
||||
|
||||
@OneToMany(mappedBy = "project", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
|
||||
@JsonManagedReference
|
||||
private List<TaskPO> tasks;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
spring.application.name=taskManagement
|
||||
|
||||
# h2 Database
|
||||
spring.datasource.url=jdbc:h2:file:/data/example
|
||||
spring.datasource.driverClassName=org.h2.Driver
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=password
|
||||
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
|
||||
spring.jpa.defer-datasource-initialization=true
|
||||
|
||||
|
||||
|
||||
# h2 Console Configuration
|
||||
spring.h2.console.enabled=true
|
||||
spring.h2.console.path=/h2-console
|
||||
spring.h2.console.settings.trace=false
|
||||
spring.h2.console.settings.web-allow-others=false
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
package com.example.demo.repository;
|
||||
|
||||
public interface TaskRepository {
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="User")
|
||||
public class UserPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name= "firstname")
|
||||
private String firstName;
|
||||
|
||||
@Column(name="lastname")
|
||||
private String lastName;
|
||||
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.UserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user
|
||||
* @return return all found user
|
||||
*/
|
||||
public List<UserDto> loadAllUsers() {
|
||||
List<UserPO> userListPO = this.userRepository.findAll();
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
userListDto.add(this.convertUserPOToUserDto(userPO));
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific user
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public UserDto loadUser(Integer id) {
|
||||
Optional<UserPO> userPO = this.userRepository.findById(id);
|
||||
return this.convertUserPOToUserDto(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific user
|
||||
* @param id The id of the user
|
||||
* @param userPO The updated user
|
||||
*/
|
||||
public void updateUser(Integer id, UserDto userDto) {
|
||||
Optional<UserPO> userPO = userRepository.findById(id);
|
||||
userPO.get().setFirstName(userDto.getFirstName());
|
||||
userPO.get().setLastName(userDto.getLastName());
|
||||
this.userRepository.save(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific user
|
||||
* @param id The id of the user
|
||||
*/
|
||||
public void deleteUser(Integer id) {
|
||||
userRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
* @param user The details of the user
|
||||
*/
|
||||
public void createUser(UserDto user) {
|
||||
this.userRepository.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userPO The UserPO object
|
||||
* @return The UserDto object
|
||||
*/
|
||||
private UserDto convertUserPOToUserDto(UserPO userPO) {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
return userDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private UserPO convertUserDtoTOUserPO(UserDto userDto) {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
return userPO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,42 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.UserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
public List<UserPO> loadAllUsers() {
|
||||
return userRepository.findAll();
|
||||
}
|
||||
|
||||
public UserPO updateUser(Integer id, UserPO newUser) {
|
||||
Optional<UserPO> user = userRepository.findById(id);
|
||||
user.get().setFirstName(newUser.getFirstName());
|
||||
user.get().setLastName(newUser.getLastName());
|
||||
user.get().setTasks(newUser.getTasks());
|
||||
return userRepository.save(user.get());
|
||||
}
|
||||
|
||||
public void deleteUser(Integer id) {
|
||||
userRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public UserPO createUser(UserPO user) {
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,137 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectDto> loadAllProjects() {
|
||||
List<ProjectPO> projectListPO = this.projectRepository.findAll();
|
||||
List<ProjectDto> projectListDto = new ArrayList<>();
|
||||
|
||||
projectListPO.stream().forEach(projectPO -> {
|
||||
ProjectDto projectDto = new ProjectDto();
|
||||
projectDto.setId(projectPO.getId());
|
||||
projectDto.setTasks(projectPO.getTasks());
|
||||
projectDto.setTitle(projectPO.getTitle());
|
||||
});
|
||||
|
||||
return projectListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getTitle());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.UserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user
|
||||
* @return return all found user
|
||||
*/
|
||||
public List<UserDto> loadAllUsers() {
|
||||
List<UserPO> userListPO = this.userRepository.findAll();
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
userListDto.add(this.convertUserPOToUserDto(userPO));
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific user
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public UserDto loadUser(Integer id) {
|
||||
Optional<UserPO> userPO = this.userRepository.findById(id);
|
||||
return this.convertUserPOToUserDto(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific user
|
||||
* @param id The id of the user
|
||||
* @param userPO The updated user
|
||||
*/
|
||||
public void updateUser(Integer id, UserDto userDto) {
|
||||
Optional<UserPO> userPO = userRepository.findById(id);
|
||||
userPO.get().setFirstName(userDto.getFirstName());
|
||||
userPO.get().setLastName(userDto.getLastName());
|
||||
this.userRepository.save(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific user
|
||||
* @param id The id of the user
|
||||
*/
|
||||
public void deleteUser(Integer id) {
|
||||
userRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
* @param user The details of the user
|
||||
* @return
|
||||
*/
|
||||
public UserPO createUser(UserPO user) {
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userPO The UserPO object
|
||||
* @return The UserDto object
|
||||
*/
|
||||
private UserDto convertUserPOToUserDto(UserPO userPO) {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
return userDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,70 @@
|
||||
<?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"
|
||||
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>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.5.6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>taskManagement</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>taskManagement</name>
|
||||
<description>Task Management Application</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>2.4.240</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,26 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="Task")
|
||||
public class TaskPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
private String title;
|
||||
private String description;
|
||||
private TaskStatus status;
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="Task")
|
||||
public class TaskPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
private String title;
|
||||
private String description;
|
||||
private TaskStatus status;
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.example.demo.enums;
|
||||
|
||||
public class TaskStatus {
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
|
||||
public TaskService(TaskRepository taskRepository) {
|
||||
this.taskRepository = taskRepository;
|
||||
}
|
||||
|
||||
public TaskPO updateTask(Integer id, TaskPO newTask) {
|
||||
Optional<TaskPO> task = taskRepository.findById(id);
|
||||
task.get().setDescription(newTask.getDescription());
|
||||
task.get().setProject(newTask.getProject());
|
||||
task.get().setStatus(newTask.getStatus());
|
||||
task.get().setTitle(newTask.getTitle());
|
||||
task.get().setUsers(newTask.getUsers());
|
||||
return taskRepository.save(task.get());
|
||||
}
|
||||
|
||||
public void deleteTask(Integer id) {
|
||||
taskRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public TaskPO createTask(TaskPO task) {
|
||||
// TODO ich muss mir überlegen, ob man die hier überhaupt setzen können osll
|
||||
task.setStatus(TaskStatus.OPEN);
|
||||
return taskRepository.save(task);
|
||||
}
|
||||
|
||||
public List<TaskPO> loadProjectTasks(ProjectPO projectPO) {
|
||||
return taskRepository.findByProject(projectPO);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
|
||||
public TaskService(TaskRepository taskRepository) {
|
||||
this.taskRepository = taskRepository;
|
||||
}
|
||||
|
||||
public TaskPO updateTask(Integer id, TaskPO newTask) {
|
||||
Optional<TaskPO> task = taskRepository.findById(id);
|
||||
task.get().setDescription(newTask.getDescription());
|
||||
task.get().setProject(newTask.getProject());
|
||||
task.get().setStatus(newTask.getStatus());
|
||||
task.get().setTitle(newTask.getTitle());
|
||||
task.get().setUsers(newTask.getUsers());
|
||||
return taskRepository.save(task.get());
|
||||
}
|
||||
|
||||
public void deleteTask(Integer id) {
|
||||
taskRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public TaskPO createTask(TaskPO task) {
|
||||
task.setStatus(TaskStatus.OPEN);
|
||||
return taskRepository.save(task);
|
||||
}
|
||||
|
||||
public List<TaskPO> loadProjectTasks(ProjectPO projectPO) {
|
||||
return taskRepository.findByProject(projectPO);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,129 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectDto> loadAllProjects() {
|
||||
List<ProjectPO> projectListPO = this.projectRepository.findAll();
|
||||
List<ProjectDto> projectListDto = new ArrayList<>();
|
||||
return projectListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getTitle());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
<?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"
|
||||
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>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.5.6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>taskManagement</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>taskManagement</name>
|
||||
<description>Task Management Application</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,54 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public ResponseEntity<List<ProjectDto>> loadAllProjects() {
|
||||
List<ProjectDto> projectListDto = this.projectService.loadAllProjects();
|
||||
return ResponseEntity.ok(projectListDto);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/projects", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Void> createProject(@RequestBody ProjectDto project) {
|
||||
if(project.getTasks() == null) {
|
||||
project.setTasks(new ArrayList<>());
|
||||
}
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
// TODO load single project
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Integer id) {
|
||||
this.projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> updateProject(@PathVariable Integer id, @RequestBody ProjectDto project){
|
||||
this.projectService.updateProject(id, project);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.apt.aptEnabled=false
|
||||
org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations
|
||||
@ -0,0 +1,52 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="TASK")
|
||||
public class TaskPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "title", nullable = false)
|
||||
private String title;
|
||||
|
||||
@Column(name = "description", length = 1000)
|
||||
private String description;
|
||||
|
||||
@Column(name = "status", nullable = false)
|
||||
private TaskStatus status;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "project_id")
|
||||
private ProjectPO project;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name ="Task_User", joinColumns= @JoinColumn(name = "task_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
private List<UserPO> users;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="Task")
|
||||
public class TaskPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "title")
|
||||
private String title;
|
||||
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@Column(name = "status")
|
||||
private TaskStatus status;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "project_id")
|
||||
private ProjectPO project;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name ="Task_User", joinColumns= @JoinColumn(name = "task_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
private List<UserPO> users;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserDTO {
|
||||
|
||||
private Integer id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private List<TaskDTO> tasks;
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectService.loadAllProjects();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/projects", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Void> createProject(@RequestBody ProjectDto project) {
|
||||
if(project.getTasks() == null) {
|
||||
project.setTasks(new ArrayList<>());
|
||||
}
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Integer id) {
|
||||
this.projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> updateProject(@PathVariable Integer id, @RequestBody ProjectDto project){
|
||||
ProjectPO updatedTask = this.projectService.updateProject(id, project);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,180 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectDto> loadAllProjects() {
|
||||
List<ProjectPO> projectListPO = this.projectRepository.findAll();
|
||||
List<ProjectDto> projectListDto = new ArrayList<>();
|
||||
|
||||
projectListPO.stream().forEach(projectPO -> {
|
||||
ProjectDto projectDto = new ProjectDto();
|
||||
projectDto.setId(projectPO.getId());
|
||||
projectDto.setTitle(projectPO.getTitle());
|
||||
projectDto.setTasks(projectPO.getTasks());
|
||||
});
|
||||
|
||||
return projectListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getTitle());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskPO object into a TaskDto object
|
||||
* @param taskListPO The TaskPO objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskDto objects
|
||||
*/
|
||||
private List<TaskDto> convertTaskPOToTaskDto(List<TaskDto> taskListPO, Integer projectId) {
|
||||
List<TaskDto> taskListDto = new ArrayList<>();
|
||||
taskListPO.stream().forEach(taskPO -> {
|
||||
TaskDto taskDto = new TaskDto();
|
||||
taskDto.setDescription(taskPO.getDescription());
|
||||
taskDto.setId(taskPO.getId());
|
||||
taskDto.setProjectId(projectId);
|
||||
taskDto.setStatus(taskPO.getStatus());
|
||||
taskDto.setTitle(taskPO.getTitle());
|
||||
taskDto.setUsers(this.convertUserDtoTOUserPO(taskPO.getUsers()));
|
||||
|
||||
taskListDto.add(taskDto);
|
||||
});
|
||||
|
||||
return taskListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userListPO The UserPO objects
|
||||
* @return The UserDto objects
|
||||
*/
|
||||
private List<UserDto> convertUserPOToUserDto(List<UserPO> userListPO) {
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
userListPO.add(userDto);
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
@GetMapping("/user"){
|
||||
public String loadAllUser() {
|
||||
return "TODO loadAllUser";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
|
||||
public TaskService(TaskRepository taskRepository) {
|
||||
this.taskRepository = taskRepository;
|
||||
}
|
||||
|
||||
public TaskPO updateTask(Integer id, TaskPO newTask) {
|
||||
Optional<TaskPO> task = taskRepository.findById(id);
|
||||
task.get().setDescription(newTask.getDescription());
|
||||
task.get().setProject(newTask.getProject());
|
||||
task.get().setStatus(newTask.getStatus());
|
||||
task.get().setTitle(newTask.getTitle());
|
||||
task.get().setUsers(newTask.getUsers());
|
||||
return taskRepository.save(task.get());
|
||||
}
|
||||
|
||||
public void deleteTask(Integer id) {
|
||||
taskRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public TaskPO createTask(TaskPO task) {
|
||||
// TODO ich muss mir überlegen, ob man die hier überhaupt setzen können soll!
|
||||
task.setStatus(TaskStatus.OPEN);
|
||||
return taskRepository.save(task);
|
||||
}
|
||||
|
||||
public List<TaskPO> loadProjectTasks(ProjectPO projectPO) {
|
||||
return taskRepository.findByProject(projectPO);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.service.TaskService;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@PostMapping("/task/{id}")
|
||||
public ResponseEntity<TaskPO> updateTask(@PathVariable Integer id, @RequestBody TaskPO task) {
|
||||
TaskPO updatedTask = taskService.updateTask(id, task);
|
||||
return ResponseEntity.ok(updatedTask);
|
||||
}
|
||||
|
||||
@DeleteMapping("/task/{id}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/task")
|
||||
public List<TaskPO> loadProjectTasks(@RequestBody ProjectPO project) {
|
||||
return taskService.loadProjectTasks(project);
|
||||
}
|
||||
|
||||
@PostMapping("/task")
|
||||
public TaskPO createTask(@RequestBody TaskPO task) {
|
||||
return taskService.createTask(task);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,127 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getName());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.service.UserService;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public UserController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
public List<UserPO> loadAllUser() {
|
||||
return userService.loadAllUsers();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
@ -0,0 +1,24 @@
|
||||
package com.example.demo.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
@Bean
|
||||
public WebMvcConfigurer corsConfigurer() {
|
||||
return new WebMvcConfigurer() {
|
||||
@Override
|
||||
public void addCorsMappings(CorsRegistry registry) {
|
||||
registry.addMapping("/**")
|
||||
.allowedOrigins("http://localhost:4200")
|
||||
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
|
||||
.allowedHeaders("*")
|
||||
.allowCredentials(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.UserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
public List<UserPO> loadAllUsers() {
|
||||
return userRepository.findAll();
|
||||
}
|
||||
|
||||
public UserPO updateUser(Integer id, UserPO newUser) {
|
||||
Optional<UserPO> user = userRepository.findById(id);
|
||||
user.get().setFirstName(newUser.getFirstName());
|
||||
user.get().setLastName(newUser.getLastName());
|
||||
user.get().setTasks(newUser.getTasks());
|
||||
return userRepository.save(user.get());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TaskDto {
|
||||
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String description;
|
||||
private TaskStatusEnum status;
|
||||
private Integer projectId;
|
||||
private List<UserDTO> users;
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectService.loadAllProjects();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/projects", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Void> createProject(@RequestBody ProjectDto project) {
|
||||
if(project.getTasks() == null) {
|
||||
project.setTasks(new ArrayList<>());
|
||||
}
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Integer id) {
|
||||
this.projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> updateProject(@PathVariable Integer id, @RequestBody ProjectDto project){
|
||||
this.projectService.updateProject(id, project);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,119 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update da specific project
|
||||
* @param id
|
||||
* @param newProject
|
||||
* @return
|
||||
*/
|
||||
public ProjectPO updateProject(Integer id, ProjectPO newProject) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(newProject.getTitle());
|
||||
return this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getName());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="Project")
|
||||
public class ProjectPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name="name")
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,76 @@
|
||||
<?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"
|
||||
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>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.5.6</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>taskManagement</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>taskManagement</name>
|
||||
<description>Task Management Application</description>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.42</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,51 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="Task")
|
||||
public class TaskPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "title")
|
||||
private String title;
|
||||
|
||||
@Column(name = "description")
|
||||
private String description;
|
||||
|
||||
@Column(name = "status")
|
||||
private TaskStatus status;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "project_id")
|
||||
private ProjectPO project;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name ="Task_User", joinColumns= @JoinColumn(name = "task_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
private List<UserPO> users;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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.RestController;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.service.TaskService;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@PutMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> updateTask(@PathVariable Integer id, @RequestBody TaskDto task) {
|
||||
this.taskService.updateTask(id, task);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/task/{id}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/task")
|
||||
public ResponseEntity<Void> createTask(@PathVariable Integer projectId, @RequestBody TaskDto task) {
|
||||
this.taskService.createTask(task, projectId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/task")
|
||||
public ResponseEntity<TaskDto> loadTask(@PathVariable Integer id) {
|
||||
TaskDto taskDto = this.taskService.loadTask(id);
|
||||
return ResponseEntity.ok(taskDto);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,83 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.UserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user
|
||||
* @return return all found user
|
||||
*/
|
||||
public List<UserDto> loadAllUsers() {
|
||||
List<UserPO> userListPO = this.userRepository.findAll();
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
userListDto.add(this.convertUserPOToUserDto(userPO));
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific user
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public UserDto loadUser(Integer id) {
|
||||
Optional<UserPO> userPO = this.userRepository.findById(id);
|
||||
return this.convertUserPOToUserDto(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific user
|
||||
* @param id The id of the user
|
||||
* @param userPO The updated user
|
||||
*/
|
||||
public void updateUser(Integer id, UserPO userPO) {
|
||||
Optional<UserPO> user = userRepository.findById(id);
|
||||
user.get().setFirstName(userPO.getFirstName());
|
||||
user.get().setLastName(userPO.getLastName());
|
||||
user.get().setTasks(userPO.getTasks());
|
||||
this.userRepository.save(user.get());
|
||||
}
|
||||
|
||||
public void deleteUser(Integer id) {
|
||||
userRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public UserPO createUser(UserPO user) {
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userPO The UserPO object
|
||||
* @return The UserDto object
|
||||
*/
|
||||
private UserDto convertUserPOToUserDto(UserPO userPO) {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
return userDto;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class UserDto {
|
||||
|
||||
private Integer id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private List<TaskDTO> tasks;
|
||||
|
||||
}
|
||||
@ -0,0 +1,55 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
import com.fasterxml.jackson.annotation.JsonBackReference;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToMany;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(name="TASK")
|
||||
public class TaskPO {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@Column(name = "title", nullable = false)
|
||||
private String title;
|
||||
|
||||
@Column(name = "description", length = 1000)
|
||||
private String description;
|
||||
|
||||
@Column(name = "status", nullable = false)
|
||||
private TaskStatus status;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(name = "project_id")
|
||||
@JsonBackReference
|
||||
private ProjectPO project;
|
||||
|
||||
@ManyToMany
|
||||
@JoinTable(name ="Task_User", joinColumns= @JoinColumn(name = "task_id"), inverseJoinColumns = @JoinColumn(name = "user_id"))
|
||||
private List<UserPO> users;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ProjectDto {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private List<TaskDTO> tasks;
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
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.RestController;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.service.TaskService;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@PutMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> updateTask(@PathVariable Integer id, @RequestBody TaskDto task) {
|
||||
this.taskService.updateTask(id, task);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/tasks/{id}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/{projectId}")
|
||||
public ResponseEntity<Void> createTask(@PathVariable Integer projectId, @RequestBody TaskDto task) {
|
||||
this.taskService.createTask(task, projectId);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/task/{id}")
|
||||
public ResponseEntity<TaskDto> loadTask(@PathVariable Integer id) {
|
||||
TaskDto taskDto = this.taskService.loadTask(id);
|
||||
return ResponseEntity.ok(taskDto);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.example.demo.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
import com.example.demo.models.TaskPO;
|
||||
|
||||
|
||||
|
||||
@Repository
|
||||
public interface TaskRepository extends JpaRepository<TaskPO, Integer> {
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.example.demo.models;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
public class Project {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public ResponseEntity<List<ProjectDto>> loadAllProjects() {
|
||||
List<ProjectDto> projectListDto = this.projectService.loadAllProjects();
|
||||
return ResponseEntity.ok(projectListDto);
|
||||
}
|
||||
|
||||
@PostMapping(value = "/projects", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Void> createProject(@RequestBody ProjectDto project) {
|
||||
if(project.getTasks() == null) {
|
||||
project.setTasks(new ArrayList<>());
|
||||
}
|
||||
this.projectService.createProject(project);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
// TODO load single project
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Integer id) {
|
||||
this.projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> updateProject(@PathVariable Integer id, @RequestBody ProjectDto project){
|
||||
this.projectService.updateProject(id, project);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/project")
|
||||
public ResponseEntity<ProjectDto> loadProject(@PathVariable Integer id) {
|
||||
ProjectDto projectDto = this.projectService.loadProject(id);
|
||||
return ResponseEntity.ok(projectDto);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TaskDto {
|
||||
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String description;
|
||||
private TaskStatusEnum status;
|
||||
private Integer projectId;
|
||||
private List<UserDTO> users;
|
||||
}
|
||||
@ -0,0 +1,89 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.UserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user
|
||||
* @return return all found user
|
||||
*/
|
||||
public List<UserDto> loadAllUsers() {
|
||||
List<UserPO> userListPO = this.userRepository.findAll();
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
userListDto.add(this.convertUserPOToUserDto(userPO));
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific user
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public UserDto loadUser(Integer id) {
|
||||
Optional<UserPO> userPO = this.userRepository.findById(id);
|
||||
return this.convertUserPOToUserDto(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific user
|
||||
* @param id The id of the user
|
||||
* @param userPO The updated user
|
||||
*/
|
||||
public void updateUser(Integer id, UserDto userDto) {
|
||||
Optional<UserPO> userPO = userRepository.findById(id);
|
||||
userPO.get().setFirstName(userDto.getFirstName());
|
||||
userPO.get().setLastName(userDto.getLastName());
|
||||
this.userRepository.save(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific user
|
||||
* @param id The id of the user
|
||||
*/
|
||||
public void deleteUser(Integer id) {
|
||||
userRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param user
|
||||
* @return
|
||||
*/
|
||||
public UserPO createUser(UserPO user) {
|
||||
return userRepository.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userPO The UserPO object
|
||||
* @return The UserDto object
|
||||
*/
|
||||
private UserDto convertUserPOToUserDto(UserPO userPO) {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
return userDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.UserRepository;
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
public UserService(UserRepository userRepository) {
|
||||
this.userRepository = userRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all user
|
||||
* @return return all found user
|
||||
*/
|
||||
public List<UserDto> loadAllUsers() {
|
||||
List<UserPO> userListPO = this.userRepository.findAll();
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
userListDto.add(this.convertUserPOToUserDto(userPO));
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific user
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public UserDto loadUser(Integer id) {
|
||||
Optional<UserPO> userPO = this.userRepository.findById(id);
|
||||
return this.convertUserPOToUserDto(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific user
|
||||
* @param id The id of the user
|
||||
* @param userPO The updated user
|
||||
*/
|
||||
public void updateUser(Integer id, UserDto userDto) {
|
||||
Optional<UserPO> userPO = userRepository.findById(id);
|
||||
userPO.get().setFirstName(userDto.getFirstName());
|
||||
userPO.get().setLastName(userDto.getLastName());
|
||||
this.userRepository.save(userPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific user
|
||||
* @param id The id of the user
|
||||
*/
|
||||
public void deleteUser(Integer id) {
|
||||
userRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
* @param user The details of the user
|
||||
*/
|
||||
public void createUser(UserDto user) {
|
||||
this.userRepository.save(user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userPO The UserPO object
|
||||
* @return The UserDto object
|
||||
*/
|
||||
private UserDto convertUserPOToUserDto(UserPO userPO) {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
return userDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.service.ProjectService;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
private final ProjectService projectService;
|
||||
|
||||
public ProjectController(ProjectService projectService) {
|
||||
this.projectService = projectService;
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return projectService.loadAllProjects();
|
||||
}
|
||||
|
||||
@PostMapping(value = "/projects", consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ProjectPO createProject(@RequestBody ProjectPO project) {
|
||||
if(project.getTasks() == null) {
|
||||
project.setTasks((new ArrayList<>());
|
||||
}
|
||||
return projectService.createProject(project);
|
||||
}
|
||||
|
||||
@DeleteMapping("/projects/{id}")
|
||||
public ResponseEntity<Void> deleteProject(@PathVariable Integer id) {
|
||||
projectService.deleteProject(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PostMapping("/projects/{id}")
|
||||
public ResponseEntity<ProjectPO> updateProject(@PathVariable Integer id, @RequestBody ProjectPO project){
|
||||
ProjectPO updatedTask = projectService.updateProject(id, project);
|
||||
return ResponseEntity.ok(updatedTask);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,180 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectDto> loadAllProjects() {
|
||||
List<ProjectPO> projectListPO = this.projectRepository.findAll();
|
||||
List<ProjectDto> projectListDto = new ArrayList<>();
|
||||
|
||||
projectListPO.stream().forEach(projectPO -> {
|
||||
ProjectDto projectDto = new ProjectDto();
|
||||
projectDto.setId(projectPO.getId());
|
||||
projectDto.setTitle(projectPO.getTitle());
|
||||
projectDto.setTasks(projectPO.getTasks());
|
||||
});
|
||||
|
||||
return projectListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getTitle());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskPO object into a TaskDto object
|
||||
* @param taskListPO The TaskPO objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskDto objects
|
||||
*/
|
||||
private List<TaskDto> convertTaskPOToTaskDto(List<TaskDto> taskListPO, Integer projectId) {
|
||||
List<TaskDto> taskListDto = new ArrayList<>();
|
||||
taskListPO.stream().forEach(taskPO -> {
|
||||
TaskDto taskDto = new TaskDto();
|
||||
taskDto.setDescription(taskPO.getDescription());
|
||||
taskDto.setId(taskPO.getId());
|
||||
taskDto.setProjectId(projectId);
|
||||
taskDto.setStatus(taskPO.getStatus());
|
||||
taskDto.setTitle(taskPO.getTitle());
|
||||
taskDto.setUsers(this.convertUserDtoTOUserPO(taskPO.getUsers()));
|
||||
|
||||
taskListDto.add(taskDto);
|
||||
});
|
||||
|
||||
return taskListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserPOTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.example.demo.enums.TaskStatus;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TaskDTO {
|
||||
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String description;
|
||||
private TaskStatus status;
|
||||
private Integer projectId;
|
||||
private List<UserDTO> users;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ProjectDto {
|
||||
|
||||
private Integer id;
|
||||
private String name;
|
||||
private List<TaskDto> tasks;
|
||||
}
|
||||
@ -0,0 +1,180 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectDto> loadAllProjects() {
|
||||
List<ProjectPO> projectListPO = this.projectRepository.findAll();
|
||||
List<ProjectDto> projectListDto = new ArrayList<>();
|
||||
|
||||
projectListPO.stream().forEach(projectPO -> {
|
||||
ProjectDto projectDto = new ProjectDto();
|
||||
projectDto.setId(projectPO.getId());
|
||||
projectDto.setTitle(projectPO.getTitle());
|
||||
projectDto.setTasks(projectPO.getTasks());
|
||||
});
|
||||
|
||||
return projectListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getTitle());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskDto> convertTaskPOToTaskDto(List<TaskDto> taskListPO, ProjectDto project) {
|
||||
List<TaskPO> taskListDto = new ArrayList<>();
|
||||
taskListPO.stream().forEach(taskPO -> {
|
||||
TaskDto taskDto = new TaskDto();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,119 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectPO> loadAllProjects() {
|
||||
return this.projectRepository.findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectPO loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return project.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param newProject The updated project
|
||||
* @return
|
||||
*/
|
||||
public ProjectPO updateProject(Integer id, ProjectPO newProject) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(newProject.getTitle());
|
||||
return this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getName());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,193 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.ProjectDto;
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.ProjectRepository;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private final ProjectRepository projectRepository;
|
||||
|
||||
public ProjectService(ProjectRepository projectRepository) {
|
||||
this.projectRepository = projectRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all projects
|
||||
* @return all found projects
|
||||
*/
|
||||
public List<ProjectDto> loadAllProjects() {
|
||||
List<ProjectPO> projectListPO = this.projectRepository.findAll();
|
||||
List<ProjectDto> projectListDto = new ArrayList<>();
|
||||
|
||||
projectListPO.stream().forEach(projectPO -> {
|
||||
ProjectDto projectDto = new ProjectDto();
|
||||
projectDto.setId(projectPO.getId());
|
||||
projectDto.setTitle(projectPO.getTitle());
|
||||
projectDto.setTasks(this.convertTaskPOToTaskDto(projectPO.getTasks(), projectPO.getId()));
|
||||
});
|
||||
|
||||
return projectListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a specific project
|
||||
* @param id The id of the project
|
||||
* @return The found project
|
||||
*/
|
||||
public ProjectDto loadProject(Integer id) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
return this.convertProjectPOToProjectDto(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new project
|
||||
* @param project The details of the project
|
||||
*/
|
||||
public void createProject(ProjectDto project) {
|
||||
this.projectRepository.save(this.convertProjectDtoToProjectPO(project));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific project
|
||||
* @param id The id of the project
|
||||
*/
|
||||
public void deleteProject(Integer id) {
|
||||
this.projectRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific project
|
||||
* @param id The id of the project
|
||||
* @param projectDto The updated project
|
||||
*/
|
||||
public void updateProject(Integer id, ProjectDto projectDto) {
|
||||
Optional<ProjectPO> project = this.projectRepository.findById(id);
|
||||
project.get().setTitle(projectDto.getTitle());
|
||||
this.projectRepository.save(project.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectDto object into a ProjectPO object
|
||||
* @param projectdto The ProjectDto object
|
||||
* @return The ProjectPO object
|
||||
*/
|
||||
private ProjectPO convertProjectDtoToProjectPO(ProjectDto projectdto) {
|
||||
ProjectPO projectPO = new ProjectPO();
|
||||
projectPO.setId(projectdto.getId());
|
||||
projectPO.setTitle(projectdto.getTitle());
|
||||
projectPO.setTasks(this.convertTaskDtoToTaskPO(projectdto.getTasks(), projectdto.getId()));
|
||||
return projectPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private List<TaskPO> convertTaskDtoToTaskPO(List<TaskDto> taskListDto, Integer projectId) {
|
||||
List<TaskPO> taskLisPO = new ArrayList<>();
|
||||
taskListDto.stream().forEach(taskDto -> {
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
taskLisPO.add(taskPO);
|
||||
});
|
||||
|
||||
return taskLisPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a ProjectPO object into a ProjectDto object
|
||||
* @param projectPO The ProjectPO object
|
||||
* @return The ProjectDto object
|
||||
*/
|
||||
private ProjectDto convertProjectPOToProjectDto(ProjectPO projectPO) {
|
||||
ProjectDto projectDto = new ProjectDto();
|
||||
projectDto.setId(projectPO.getId());
|
||||
projectDto.setTitle(projectPO.getTitle());
|
||||
projectDto.setTasks(this.convertTaskPOToTaskDto(projectPO.getTasks(), projectPO.getId()));
|
||||
return projectDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskPO object into a TaskDto object
|
||||
* @param taskListPO The TaskPO objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskDto objects
|
||||
*/
|
||||
private List<TaskDto> convertTaskPOToTaskDto(List<TaskPO> taskListPO, Integer projectId) {
|
||||
List<TaskDto> taskListDto = new ArrayList<>();
|
||||
taskListPO.stream().forEach(taskPO -> {
|
||||
TaskDto taskDto = new TaskDto();
|
||||
taskDto.setDescription(taskPO.getDescription());
|
||||
taskDto.setId(taskPO.getId());
|
||||
taskDto.setProjectId(projectId);
|
||||
taskDto.setStatus(taskPO.getStatus());
|
||||
taskDto.setTitle(taskPO.getTitle());
|
||||
taskDto.setUsers(this.convertUserPOToUserDto(taskPO.getUsers()));
|
||||
|
||||
taskListDto.add(taskDto);
|
||||
});
|
||||
|
||||
return taskListDto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserPO object into a UserDto object
|
||||
* @param userListPO The UserPO objects
|
||||
* @return The UserDto objects
|
||||
*/
|
||||
private List<UserDto> convertUserPOToUserDto(List<UserPO> userListPO) {
|
||||
List<UserDto> userListDto = new ArrayList<>();
|
||||
|
||||
userListPO.stream().forEach(userPO -> {
|
||||
UserDto userDto = new UserDto();
|
||||
userDto.setFirstName(userPO.getFirstName());
|
||||
userDto.setId(userPO.getId());
|
||||
userDto.setLastName(userPO.getLastName());
|
||||
|
||||
userListDto.add(userDto);
|
||||
});
|
||||
|
||||
return userListDto;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,104 @@
|
||||
package com.example.demo.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.dto.UserDto;
|
||||
import com.example.demo.enums.TaskStatusEnum;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.repository.TaskRepository;
|
||||
|
||||
@Service
|
||||
public class TaskService {
|
||||
|
||||
private final TaskRepository taskRepository;
|
||||
|
||||
public TaskService(TaskRepository taskRepository) {
|
||||
this.taskRepository = taskRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a specific task
|
||||
* @param id The id of the task
|
||||
* @param taskDto The updated task
|
||||
* @return
|
||||
*/
|
||||
public void updateTask(Integer id, TaskDto taskDto) {
|
||||
Optional<TaskPO> taskPO = this.taskRepository.findById(id);
|
||||
taskPO.get().setDescription(taskDto.getDescription());
|
||||
taskPO.get().setStatus(taskDto.getStatus());
|
||||
taskPO.get().setTitle(taskDto.getTitle());
|
||||
taskPO.get().setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
this.taskRepository.save(taskPO.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a specific task
|
||||
* @param id The id of the task
|
||||
*/
|
||||
public void deleteTask(Integer id) {
|
||||
this.taskRepository.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new task
|
||||
* @param task
|
||||
* @return
|
||||
*/
|
||||
public void createTask(TaskDto taskDto) {
|
||||
this.taskRepository.save(taskPO);
|
||||
}
|
||||
|
||||
public List<TaskPO> loadProjectTasks(ProjectPO projectPO) {
|
||||
return taskRepository.findByProject(projectPO);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a UserDto object into a UserPO object
|
||||
* @param userListDto The UserDto objects
|
||||
* @return The UserPO objects
|
||||
*/
|
||||
private List<UserPO> convertUserDtoTOUserPO(List<UserDto> userListDto) {
|
||||
List<UserPO> userListPO = new ArrayList<>();
|
||||
|
||||
userListDto.stream().forEach(userDto -> {
|
||||
UserPO userPO = new UserPO();
|
||||
userPO.setFirstName(userDto.getFirstName());
|
||||
userPO.setId(userDto.getId());
|
||||
userPO.setLastName(userDto.getLastName());
|
||||
|
||||
userListPO.add(userPO);
|
||||
});
|
||||
|
||||
return userListPO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a TaskDto object into a TaskPO object
|
||||
* @param taskListDto The TaskDto objects
|
||||
* @param projectId The id of the project
|
||||
* @return The TaskPO objects
|
||||
*/
|
||||
private TaskPO convertTaskDtoToTaskPO(TaskDto taskListDto, Integer projectId) {
|
||||
|
||||
Optional<ProjectPO> projectPO = this.projectRepository.findById(projectId);
|
||||
TaskPO taskPO = new TaskPO();
|
||||
taskPO.setDescription(taskDto.getDescription());
|
||||
taskPO.setId(taskDto.getId());
|
||||
taskPO.setProject(projectPO.get());
|
||||
taskPO.setStatus(taskDto.getStatus());
|
||||
taskPO.setTitle(taskDto.getTitle());
|
||||
taskPO.setUsers(this.convertUserDtoTOUserPO(taskDto.getUsers()));
|
||||
|
||||
|
||||
|
||||
return taskPO;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,43 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.models.UserPO;
|
||||
import com.example.demo.service.UserService;
|
||||
|
||||
@RestController
|
||||
public class UserController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public UserController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@GetMapping("/user")
|
||||
public List<UserPO> loadAllUser() {
|
||||
return userService.loadAllUsers();
|
||||
}
|
||||
|
||||
@PostMapping("user/{id}")
|
||||
public ResponseEntity<UserPO> updateUser(@PathVariable Integer id, @RequestBody UserPO user) {
|
||||
UserPO updatedUser = userService.updateUser(id, user);
|
||||
return ResponseEntity.ok(updatedUser);
|
||||
}
|
||||
|
||||
@DeleteMapping("user/{id}")
|
||||
public ResponseEntity<Void> deleteUser(@PathVariable Integer id){
|
||||
userService.deleteUser(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
package com.example.demo.dto;
|
||||
|
||||
public class TaskDTO {
|
||||
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
|
||||
org.eclipse.jdt.core.compiler.compliance=21
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
||||
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=21
|
||||
@ -0,0 +1,48 @@
|
||||
package com.example.demo.controller;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.example.demo.dto.TaskDto;
|
||||
import com.example.demo.models.ProjectPO;
|
||||
import com.example.demo.models.TaskPO;
|
||||
import com.example.demo.service.TaskService;
|
||||
|
||||
@RestController
|
||||
public class TaskController {
|
||||
|
||||
private final TaskService taskService;
|
||||
|
||||
public TaskController(TaskService taskService) {
|
||||
this.taskService = taskService;
|
||||
}
|
||||
|
||||
@PostMapping("/task/{id}")
|
||||
public ResponseEntity<Void> updateTask(@PathVariable Integer id, @RequestBody TaskDto task) {
|
||||
this.taskService.updateTask(id, task);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/task/{id}")
|
||||
public ResponseEntity<Void> deleteTask(@PathVariable Integer id) {
|
||||
taskService.deleteTask(id);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@GetMapping("/task")
|
||||
public List<TaskPO> loadProjectTasks(@RequestBody ProjectPO project) {
|
||||
return taskService.loadProjectTasks(project);
|
||||
}
|
||||
|
||||
@PostMapping("/task")
|
||||
public TaskPO createTask(@RequestBody TaskPO task) {
|
||||
return taskService.createTask(task);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user