From 54f2fa40e04e83f4ab28a31f25ad86a0a3732860 Mon Sep 17 00:00:00 2001 From: hasnain003 Date: Wed, 9 Mar 2022 12:50:24 +0530 Subject: [PATCH 1/4] Added gettaskById,patchTaskById and deleteTaskByID Rest API --- .idea/.gitignore | 8 +++ .idea/Project-Module-Feb-2022.iml | 9 +++ .idea/compiler.xml | 15 +++++ .idea/gradle.xml | 58 +++++++++++++++++++ .idea/jarRepositories.xml | 20 +++++++ .idea/misc.xml | 12 ++++ .idea/modules.xml | 8 +++ .idea/runConfigurations.xml | 10 ++++ .idea/vcs.xml | 6 ++ todolist/build.gradle | 11 +++- .../todolist/controllers/TasksController.java | 34 ++++++++++- .../java/com/scaler/todolist/models/Task.java | 13 +++-- .../src/main/resources/application.properties | 1 + 13 files changed, 196 insertions(+), 9 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Project-Module-Feb-2022.iml create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/Project-Module-Feb-2022.iml b/.idea/Project-Module-Feb-2022.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Project-Module-Feb-2022.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..baf39ff --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..4cc9d6c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,58 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..fdc392f --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..c7f6841 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d152667 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/todolist/build.gradle b/todolist/build.gradle index f84df4d..6f66853 100644 --- a/todolist/build.gradle +++ b/todolist/build.gradle @@ -1,12 +1,18 @@ plugins { id 'org.springframework.boot' version '2.6.4' id 'io.spring.dependency-management' version '1.0.11.RELEASE' - id 'java' + id("java-library") +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(17) + } } group = 'com.scaler' version = '0.0.1-SNAPSHOT' -sourceCompatibility = '17' +//sourceCompatibility = '17' configurations { compileOnly { @@ -14,6 +20,7 @@ configurations { } } + repositories { mavenCentral() } diff --git a/todolist/src/main/java/com/scaler/todolist/controllers/TasksController.java b/todolist/src/main/java/com/scaler/todolist/controllers/TasksController.java index a39e36c..0e316b7 100644 --- a/todolist/src/main/java/com/scaler/todolist/controllers/TasksController.java +++ b/todolist/src/main/java/com/scaler/todolist/controllers/TasksController.java @@ -4,7 +4,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import java.net.http.HttpResponse; import java.util.ArrayList; import java.util.List; @@ -21,7 +20,7 @@ ResponseEntity> getAllTasks() { @PostMapping("/") ResponseEntity addNewTask(@RequestBody Task task) { - Task taskToAdd = new Task(task.getName()); + Task taskToAdd = new Task(task.getId(),task.getName()); taskList.add(taskToAdd); return ResponseEntity.status(201).body(taskToAdd); } @@ -39,5 +38,36 @@ ResponseEntity addNewTask(@RequestBody Task task) { * if task 5 does not exist, send 404 */ + @GetMapping("/{id}") + ResponseEntity getTaskById(@PathVariable("id") Long taskId) { + for(Task taskItr: taskList) { + if(taskItr.getId() == taskId) { + return ResponseEntity.ok(taskItr); + } + } + return ResponseEntity.status(404).body(null); + } + + @PatchMapping("/{id}") + ResponseEntity updateTaskById(@PathVariable("id") Long taskId,@RequestBody Task task) { + for(Task taskItr:taskList) { + if(taskItr.getId() == taskId) { + taskItr.setDone(task.getDone()); + taskItr.setDue(task.getDue()); + return ResponseEntity.ok(taskItr); + } + } + return ResponseEntity.status(404).body(null); + } + @DeleteMapping("/{id}") + ResponseEntity deleteTaskById(@PathVariable("id") Long taskId) { + for(Task task:taskList) { + if(task.getId() == taskId) { + taskList.remove(task); + return ResponseEntity.noContent().build(); + } + } + return ResponseEntity.status(404).body(null); + } } diff --git a/todolist/src/main/java/com/scaler/todolist/models/Task.java b/todolist/src/main/java/com/scaler/todolist/models/Task.java index d572475..cc21888 100644 --- a/todolist/src/main/java/com/scaler/todolist/models/Task.java +++ b/todolist/src/main/java/com/scaler/todolist/models/Task.java @@ -4,15 +4,15 @@ import java.time.LocalDate; import java.time.temporal.ChronoUnit; -import java.time.temporal.TemporalUnit; -import java.util.Calendar; -import java.util.Date; @AllArgsConstructor @NoArgsConstructor @Getter(AccessLevel.PUBLIC) @Setter(AccessLevel.PUBLIC) +//@Entity(name ="tasks") public class Task { + //@Id @GeneratedValue(strategy = GenerationType.SEQUENCE) + private Long id; private String name; private LocalDate due; private Boolean done; @@ -22,7 +22,10 @@ public class Task { * due date 5 days from now, and done = false * @param name */ - public Task(String name) { - this(name, LocalDate.now().plus(5, ChronoUnit.DAYS), false); + public Task(Long id,String name) { + this.id = id; + this.name = name; + due = LocalDate.now().plus(5, ChronoUnit.DAYS); + done = false; } } diff --git a/todolist/src/main/resources/application.properties b/todolist/src/main/resources/application.properties index 2bfe6fa..9a5b335 100644 --- a/todolist/src/main/resources/application.properties +++ b/todolist/src/main/resources/application.properties @@ -1 +1,2 @@ server.port=6543 +spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration \ No newline at end of file From ba8e25fe79148f3c98b0ac377179a0c900fec1cb Mon Sep 17 00:00:00 2001 From: hasnain003 Date: Mon, 14 Mar 2022 18:35:12 +0530 Subject: [PATCH 2/4] Added getByTaskId and DeleteByTaskId API --- .idea/compiler.xml | 2 +- .idea/gradle.xml | 12 ++++++++++- .idea/runConfigurations.xml | 10 --------- taskmanager/build.gradle | 3 ++- .../taskmanager/notes/NotesRepository.java | 5 ++++- .../scaler/taskmanager/tasks/TaskEntity.java | 4 +++- .../taskmanager/tasks/TasksController.java | 19 ++++++++++++++++++ .../taskmanager/tasks/TasksService.java | 18 +++++++++++++++-- test.db.mv.db | Bin 0 -> 24576 bytes .../todolist/controllers/TasksController.java | 1 + 10 files changed, 57 insertions(+), 17 deletions(-) delete mode 100644 .idea/runConfigurations.xml create mode 100644 test.db.mv.db diff --git a/.idea/compiler.xml b/.idea/compiler.xml index baf39ff..af773d4 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -8,7 +8,7 @@ - + diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 4cc9d6c..77b6cb4 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,9 +4,11 @@