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..af773d4
--- /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..77b6cb4
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,68 @@
+
+
+
+
+
+
+
\ 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/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ 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/taskmanager/README.md b/taskmanager/README.md
index aa2cd3e..ea645d2 100644
--- a/taskmanager/README.md
+++ b/taskmanager/README.md
@@ -21,14 +21,14 @@ task manager + notes support
API Endpoints (REST URLs)
GET /tasks get all tasks ✅
-GET /tasks/{id} get a task by id
-DELETE /tasks/{id} delete task by id
-PATCH /tasks/{id} update details of a task
+GET /tasks/{id} get a task by id ✅
+DELETE /tasks/{id} delete task by id ✅
+PATCH /tasks/{id} update details of a task ✅
POST /tasks create a new task ✅
-GET /tasks/{id}/notes show all notes of a task
-POST /tasks/{id}/notes add notes to a task
-DELETE /tasks/{id}/notes/{nid} delete a note from a task
+GET /tasks/{id}/notes show all notes of a task ✅
+POST /tasks/{id}/notes add notes to a task ✅
+DELETE /tasks/{id}/notes/{nid} delete a note from a task ✅
---- "idempotent"
diff --git a/taskmanager/build.gradle b/taskmanager/build.gradle
index 79e1823..098053d 100644
--- a/taskmanager/build.gradle
+++ b/taskmanager/build.gradle
@@ -6,7 +6,7 @@ plugins {
group = 'com.scaler'
version = '0.0.1-SNAPSHOT'
-sourceCompatibility = '17'
+//sourceCompatibility = '17'
configurations {
compileOnly {
@@ -21,6 +21,7 @@ repositories {
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
+ implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.12.5'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
diff --git a/taskmanager/src/main/java/com/scaler/taskmanager/QueryConstants.java b/taskmanager/src/main/java/com/scaler/taskmanager/QueryConstants.java
new file mode 100644
index 0000000..23838af
--- /dev/null
+++ b/taskmanager/src/main/java/com/scaler/taskmanager/QueryConstants.java
@@ -0,0 +1,10 @@
+package com.scaler.taskmanager;
+
+
+public final class QueryConstants {
+ public static final String FETCH_NOTES_BY_TASKID = "SELECT new com.scaler.taskmanager.notes.dto.NoteResponseBody(" +
+ "notes.id, notes.body,notes.task.id) FROM NoteEntity notes WHERE notes.task.id = :taskId";
+
+ public static final String DELETE_NOTES_BY_TASKID = "DELETE FROM NoteEntity notes "+
+ "WHERE notes.task.id = :taskId";
+}
diff --git a/taskmanager/src/main/java/com/scaler/taskmanager/TaskmanagerApplication.java b/taskmanager/src/main/java/com/scaler/taskmanager/TaskManagerApplication.java
similarity index 69%
rename from taskmanager/src/main/java/com/scaler/taskmanager/TaskmanagerApplication.java
rename to taskmanager/src/main/java/com/scaler/taskmanager/TaskManagerApplication.java
index 4498794..87c6629 100644
--- a/taskmanager/src/main/java/com/scaler/taskmanager/TaskmanagerApplication.java
+++ b/taskmanager/src/main/java/com/scaler/taskmanager/TaskManagerApplication.java
@@ -4,10 +4,10 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
-public class TaskmanagerApplication {
+public class TaskManagerApplication {
public static void main(String[] args) {
- SpringApplication.run(TaskmanagerApplication.class, args);
+ SpringApplication.run(TaskManagerApplication.class, args);
}
}
diff --git a/taskmanager/src/main/java/com/scaler/taskmanager/notes/NoteEntity.java b/taskmanager/src/main/java/com/scaler/taskmanager/notes/NoteEntity.java
index 1ddc244..9bd8e60 100644
--- a/taskmanager/src/main/java/com/scaler/taskmanager/notes/NoteEntity.java
+++ b/taskmanager/src/main/java/com/scaler/taskmanager/notes/NoteEntity.java
@@ -10,7 +10,8 @@
@AllArgsConstructor
@NoArgsConstructor
@Getter
-@Entity(name = "notes")
+@Entity
+@Table(name = "notes")
public class NoteEntity {
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE)
Long id;
@@ -20,4 +21,9 @@ public class NoteEntity {
@ManyToOne
TaskEntity task;
+
+ public NoteEntity(String body, TaskEntity task) {
+ this.body = body;
+ this.task = task;
+ }
}
diff --git a/taskmanager/src/main/java/com/scaler/taskmanager/notes/NotesController.java b/taskmanager/src/main/java/com/scaler/taskmanager/notes/NotesController.java
new file mode 100644
index 0000000..09966a4
--- /dev/null
+++ b/taskmanager/src/main/java/com/scaler/taskmanager/notes/NotesController.java
@@ -0,0 +1,54 @@
+package com.scaler.taskmanager.notes;
+
+
+import com.scaler.taskmanager.Constants;
+import com.scaler.taskmanager.notes.dto.CreateNoteRequestBody;
+import com.scaler.taskmanager.notes.dto.NoteResponseBody;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.*;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@RestController
+@RequestMapping("/tasks/{id}/notes/")
+public class NotesController {
+
+ private NotesService notesService;
+
+ public NotesController(NotesService notesService) {
+ this.notesService = notesService;
+ }
+
+ @PostMapping("")
+ ResponseEntity createNotes(@PathVariable("id") Long taskId,@RequestBody CreateNoteRequestBody body) {
+ NoteResponseBody note = notesService.addNote(body,taskId);
+ return note == null? ResponseEntity.notFound().build():ResponseEntity.created(
+ URI.create(Constants.BASE_URL + "/notes" + note.getId()))
+ .body(note);
+ }
+
+ @GetMapping("")
+ ResponseEntity> getAllNotes(@PathVariable("id") Long taskId) {
+ List noteResponseList = notesService.getAllNotes(taskId);
+ return noteResponseList == null ? ResponseEntity.notFound().build():ResponseEntity.ok(noteResponseList);
+ }
+
+ @DeleteMapping("/{noteId}")
+ ResponseEntity