Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Backend/Task/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class TaskDto {
private long task_id;
private Long task_id;
private String title;
private String description;
private String status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
public class TaskApplication implements CommandLineRunner {

public static void main(String[] args) {

SpringApplication.run(TaskApplication.class, args);
}
@Autowired
private TaskRepository taskRepository;
// @Autowired
// private TaskRepository taskRepository;

@Override
public void run(String... args) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
package com.taskManager.Task.controller;

import com.taskManager.Task.Dto.TaskDto;
import com.taskManager.Task.model.Task;
import com.taskManager.Task.repository.TaskRepository;
import com.taskManager.Task.services.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("api/v1/tasks")
public class TaskController {
@Autowired
public TaskService taskService;

private final TaskService taskService;
public TaskController(TaskService taskService) {
this.taskService = taskService;
}

@GetMapping
public ResponseEntity<List<TaskDto>> getAllTasks(){
List<TaskDto> tasks = taskService.getAllTasks();
return ResponseEntity.ok(tasks);
}
//create Tasks
@PostMapping
public ResponseEntity<TaskDto> createTask(@RequestBody TaskDto task) {
public ResponseEntity<TaskDto> createTask(@Valid @RequestBody TaskDto task) {
TaskDto taskDto = taskService.createTask(task);
return new ResponseEntity<>(taskDto, HttpStatus.CREATED);
return ResponseEntity.status(HttpStatus.CREATED).body(taskDto);
}
@GetMapping("{task_id}")
public ResponseEntity<TaskDto> getTaskById(@PathVariable("task_id") Long taskId){
@GetMapping("/{taskId}")
public ResponseEntity<TaskDto> getTaskById(@PathVariable("taskId") Long taskId){
TaskDto task = taskService.getTaskById(taskId);
return ResponseEntity.ok(task);
}

@PutMapping("{task_id}")
public ResponseEntity<TaskDto> updateTask(@PathVariable("task_id") Long taskId,
@PutMapping("/{taskId}")
public ResponseEntity<TaskDto> updateTask(@Valid @PathVariable("taskId") Long taskId,
@RequestBody TaskDto employeeDetails) {
TaskDto updateTask = taskService.updateTask(taskId, employeeDetails);
return ResponseEntity.ok(updateTask);
}
@DeleteMapping("{task_id}")
public ResponseEntity<String> deleteTask(@PathVariable("task_id") Long taskId){
taskService.deleteTask(taskId);
return ResponseEntity.ok("Task deleted successfully!");
return ResponseEntity.ok(String.format("Task %s deleted successfully!", taskId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
public class ResourceNotFoundException extends RuntimeException{
public ResourceNotFoundException(String message){
super(message);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.Setter;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.util.Date;

@Getter
Expand All @@ -17,12 +18,14 @@
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long task_id;
private Long task_id;

@NotBlank
private String title;

private String description;

@NotBlank
private String status;

private String assignee;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.taskManager.Task.model.Task;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface TaskRepository extends JpaRepository<Task, Long> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import com.taskManager.Task.Dto.TaskDto;
import com.taskManager.Task.exception.ResourceNotFoundException;
import com.taskManager.Task.mapper.TaskMapper;
import com.taskManager.Task.model.Task;
import com.taskManager.Task.repository.TaskRepository;
import com.taskManager.Task.services.TaskService;
import com.taskManager.Task.mapper.TaskMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -20,10 +20,9 @@ public class TaskServiceImpl implements TaskService {
@Override
public List<TaskDto> getAllTasks() {
List<Task> tasks = taskRepository.findAll();
List<TaskDto> taskDtos = tasks.stream()
.map((task) -> TaskMapper.maptoTaskDto(task))
return tasks.stream()
.map(TaskMapper::maptoTaskDto)
.collect(Collectors.toList());
return taskDtos;
}
@Override
public TaskDto createTask(TaskDto taskDto) {
Expand Down