-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
414 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.example.rest.DTO; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class ProjectDTO { | ||
private String name; | ||
private String description;gi | ||
|
||
public ProjectDTO() { | ||
} | ||
|
||
public ProjectDTO(String name, String description) { | ||
this.name = name; | ||
this.description = description; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.example.rest.DTO; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.time.LocalDate; | ||
|
||
@Component | ||
public class TaskDTO { | ||
|
||
private String name; | ||
private String description; | ||
private String type; | ||
private LocalDate startDate; | ||
private LocalDate dueDate; | ||
|
||
public TaskDTO(String name, String description, String type, LocalDate startDate, LocalDate dueDate) { | ||
this.name = name; | ||
this.description = description; | ||
this.type = type; | ||
this.startDate = startDate; | ||
this.dueDate = dueDate; | ||
} | ||
|
||
public TaskDTO() { | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public LocalDate getStartDate() { | ||
return startDate; | ||
} | ||
|
||
public void setStartDate(LocalDate startDate) { | ||
this.startDate = startDate; | ||
} | ||
|
||
public LocalDate getDueDate() { | ||
return dueDate; | ||
} | ||
|
||
public void setDueDate(LocalDate dueDate) { | ||
this.dueDate = dueDate; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.example.rest.Services; | ||
|
||
import com.example.rest.DTO.TaskDTO; | ||
import com.example.rest.entities.Task; | ||
|
||
public interface TaskService { | ||
|
||
|
||
// para crea tareas | ||
|
||
Task createTask(long project_id, TaskDTO taskDTO); | ||
|
||
// para eliminar tareas | ||
|
||
void deleteTask(Long task_id); | ||
|
||
// para obtener tareas | ||
|
||
Task getTaskById(Long task_id); | ||
|
||
} |
67 changes: 67 additions & 0 deletions
67
src/main/java/com/example/rest/Services/TaskServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.example.rest.Services; | ||
|
||
import com.example.rest.DTO.TaskDTO; | ||
import com.example.rest.entities.Project; | ||
import com.example.rest.entities.Task; | ||
import com.example.rest.entities.TaskStatus; | ||
import com.example.rest.repositories.ProjectRepository; | ||
import com.example.rest.repositories.TaskRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
@Service | ||
public class TaskServiceImpl implements TaskService { | ||
|
||
private final TaskRepository taskRepository; | ||
private final ProjectRepository projectRepository; | ||
|
||
public TaskServiceImpl(TaskRepository taskRepository, ProjectRepository projectRepository) { | ||
this.taskRepository = taskRepository; | ||
this.projectRepository = projectRepository; | ||
} | ||
|
||
@Override | ||
public Task createTask(long project_id, TaskDTO taskDTO) { | ||
|
||
Project proyectoBaseDeDatos = projectRepository.findProjectById(project_id); | ||
if (proyectoBaseDeDatos != null) { | ||
throw new RuntimeException("Ya existe en la base de datos"); | ||
} | ||
|
||
Task newTask = new Task(); | ||
newTask.setName(taskDTO.getName()); | ||
newTask.setDescription(taskDTO.getDescription()); | ||
newTask.setTaskStatus(TaskStatus.TODO.toString()); | ||
newTask.setType(taskDTO.getType()); | ||
newTask.setStartDate(taskDTO.getStartDate()); | ||
newTask.setDueDate(taskDTO.getDueDate()); | ||
newTask.setCreateDate(LocalDate.now()); | ||
newTask.setLastUpdatedDate(LocalDateTime.now()); | ||
|
||
Task savedTask = taskRepository.save(newTask); | ||
return newTask; | ||
} | ||
|
||
@Override | ||
public void deleteTask(Long task_id) { | ||
Optional <Task> taskOptional = taskRepository.findById(task_id); | ||
if(taskOptional.isPresent()){ | ||
taskRepository.deleteById(task_id); | ||
} else { | ||
throw new RuntimeException("La tarea no existe"); // cambiar | ||
} | ||
} | ||
|
||
@Override | ||
public Task getTaskById(Long task_id) { | ||
Optional <Task> taskOptional = taskRepository.findById(task_id); | ||
if(taskOptional.isPresent()){ | ||
return taskOptional.get(); | ||
} else { | ||
throw new RuntimeException("La tarea no existe"); // cambiar | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
src/main/java/com/example/rest/controllers/TareaController.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/main/java/com/example/rest/controllers/TaskController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.rest.controllers; | ||
|
||
import com.example.rest.DTO.TaskDTO; | ||
import com.example.rest.Services.TaskServiceImpl; | ||
import com.example.rest.entities.Task; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.net.URI; | ||
|
||
@RestController | ||
@RequestMapping("/v1/task/") | ||
public class TaskController { | ||
|
||
//Injeccion del servicio para Task | ||
|
||
private TaskServiceImpl taskService; | ||
|
||
// POST // Crear tarea | ||
@PostMapping("/project/{id}") | ||
public ResponseEntity<Task> createTask(@PathVariable("id") Long project_id, @RequestBody TaskDTO taskDTO) { | ||
Task tareaCreada = taskService.createTask(project_id, taskDTO); | ||
return ResponseEntity.created(URI.create("/v1/task" + tareaCreada.getId())) | ||
.body(tareaCreada); | ||
} | ||
|
||
// DELETE // Eliminar un Task | ||
|
||
public ResponseEntity<Void> deleteTask(@PathVariable("id") Long task_id) { | ||
taskService.deleteTask(task_id); | ||
return ResponseEntity.noContent() | ||
.build(); | ||
} | ||
|
||
// GET // Obtener un Task | ||
|
||
@GetMapping("/{id}") | ||
public ResponseEntity<Task> getTask(@PathVariable("id") Long task_id){ | ||
Task task = taskService.getTaskById(task_id); | ||
return ResponseEntity.ok(task); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.