From 50741a8953c4acd85360d67511e93545611214b3 Mon Sep 17 00:00:00 2001 From: neviyn Date: Wed, 31 Mar 2021 22:36:05 +0100 Subject: [PATCH] Can now add, edit and delete events --- .../neviyn/projectplanner/HtmlController.kt | 6 +- .../uk/co/neviyn/projectplanner/Requests.kt | 4 +- src/main/resources/templates/project.html | 117 ++++++++++++++++-- 3 files changed, 116 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt b/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt index 9fc47bb..8f8a813 100644 --- a/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt +++ b/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt @@ -143,6 +143,7 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep @PostMapping("/addevent") @PreAuthorize("hasPermission(#id, 'Long', '')") + @ResponseBody fun addEventToProject(@PathVariable id: Long, @RequestBody e: NewEvent) { val project = projectRepository.findById(id).get() val event = Event(title = e.title, description = e.description, start = e.start, end = e.end, project = project) @@ -163,8 +164,9 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep @PostMapping("/deleteevent") @PreAuthorize("hasPermission(#id, 'Long', '')") - fun deleteEvent(@PathVariable id: Long) { - TODO() + @ResponseBody + fun deleteEvent(@PathVariable id: Long, @RequestBody e: EventID) { + eventRepository.deleteById(e.id) } diff --git a/src/main/kotlin/uk/co/neviyn/projectplanner/Requests.kt b/src/main/kotlin/uk/co/neviyn/projectplanner/Requests.kt index 6c9c9bb..c22a89a 100644 --- a/src/main/kotlin/uk/co/neviyn/projectplanner/Requests.kt +++ b/src/main/kotlin/uk/co/neviyn/projectplanner/Requests.kt @@ -8,4 +8,6 @@ data class NewProject(val title: String) data class NewEvent(val title: String, val description: String, val start: Instant, val end: Instant) -data class EditedEvent(val id: Long, val title: String, val description: String, val start: Instant, val end: Instant) \ No newline at end of file +data class EditedEvent(val id: Long, val title: String, val description: String, val start: Instant, val end: Instant) + +data class EventID(val id: Long) \ No newline at end of file diff --git a/src/main/resources/templates/project.html b/src/main/resources/templates/project.html index 1bb3d7c..e62bec4 100644 --- a/src/main/resources/templates/project.html +++ b/src/main/resources/templates/project.html @@ -7,11 +7,22 @@ + + @@ -110,17 +174,54 @@
- +
- +
+ + + + +