diff --git a/src/main/kotlin/uk/co/neviyn/projectplanner/Entities.kt b/src/main/kotlin/uk/co/neviyn/projectplanner/Entities.kt index c22dd40..d4c259a 100644 --- a/src/main/kotlin/uk/co/neviyn/projectplanner/Entities.kt +++ b/src/main/kotlin/uk/co/neviyn/projectplanner/Entities.kt @@ -1,8 +1,10 @@ package uk.co.neviyn.projectplanner import com.fasterxml.jackson.annotation.JsonIgnore +import java.time.Instant import java.time.LocalDateTime import javax.persistence.CascadeType +import javax.persistence.Column import javax.persistence.Entity import javax.persistence.GeneratedValue import javax.persistence.GenerationType @@ -56,8 +58,10 @@ class Project( class Event( var title: String = "INVALID", var description: String = "INVALID", - var start: LocalDateTime = LocalDateTime.MIN, - var end: LocalDateTime = LocalDateTime.MIN, + @Column(name = "start_time") + var start: Instant = Instant.MIN, + @Column(name = "end_time") + var end: Instant = Instant.MIN, @ManyToOne @JoinColumn(name = "project_id") @JsonIgnore diff --git a/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt b/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt index 2ff1ea0..9fc47bb 100644 --- a/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt +++ b/src/main/kotlin/uk/co/neviyn/projectplanner/HtmlController.kt @@ -14,9 +14,6 @@ import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.ResponseBody import java.time.Instant -import java.time.LocalDateTime -import java.time.ZoneOffset -import java.time.format.DateTimeFormatter import javax.persistence.EntityManager import javax.transaction.Transactional @@ -110,19 +107,15 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep return "project" } - val f: DateTimeFormatter = DateTimeFormatter.ISO_INSTANT - @GetMapping("/events") @PreAuthorize("hasPermission(#id, 'Long', '')") @ResponseBody - fun getProjectEventsBetween(@PathVariable id: Long, @RequestParam start: String?, @RequestParam end: String?) : Set { - val startTime: LocalDateTime? = LocalDateTime.ofInstant(Instant.from(f.parse(start)), ZoneOffset.UTC) - val endTime: LocalDateTime? = LocalDateTime.ofInstant(Instant.from(f.parse(end)), ZoneOffset.UTC) + fun getProjectEventsBetween(@PathVariable id: Long, @RequestParam start: Instant?, @RequestParam end: Instant?) : Set { val project = projectRepository.findById(id).get() - if(startTime == null && endTime == null) return project.events - else if(startTime == null && endTime != null) return eventRepository.findByEndBeforeAndProject(endTime, project) - else if(startTime != null && endTime == null) return eventRepository.findByStartAfterAndProject(startTime, project) - return eventRepository.findByStartAfterAndEndBeforeAndProjectIs(startTime!!, endTime!!, project) + if(start == null && end == null) return project.events + else if(start == null && end != null) return eventRepository.findByEndBeforeAndProject(end, project) + else if(start != null && end == null) return eventRepository.findByStartAfterAndProject(start, project) + return eventRepository.findByStartAfterAndEndBeforeAndProjectIs(start!!, end!!, project) } @@ -158,8 +151,14 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep @PostMapping("/editevent") @PreAuthorize("hasPermission(#id, 'Long', '')") - fun editEvent(@PathVariable id: Long) { - TODO() + @ResponseBody + fun editEvent(@PathVariable id: Long, @RequestBody e: EditedEvent) { + val event = eventRepository.findById(e.id).get() + event.title = e.title + event.description = e.description + event.start = e.start + event.end = e.end + eventRepository.save(event) } @PostMapping("/deleteevent") diff --git a/src/main/kotlin/uk/co/neviyn/projectplanner/Repositories.kt b/src/main/kotlin/uk/co/neviyn/projectplanner/Repositories.kt index 51ffc15..ef6004d 100644 --- a/src/main/kotlin/uk/co/neviyn/projectplanner/Repositories.kt +++ b/src/main/kotlin/uk/co/neviyn/projectplanner/Repositories.kt @@ -1,7 +1,7 @@ package uk.co.neviyn.projectplanner import org.springframework.data.repository.CrudRepository -import java.time.LocalDateTime +import java.time.Instant interface UserRepository : CrudRepository{ fun findByUsername(username: String): User? @@ -11,9 +11,9 @@ interface UserRepository : CrudRepository{ interface ProjectRepository : CrudRepository{} interface EventRepository : CrudRepository{ - fun findByStartAfterAndProject(start: LocalDateTime, project: Project) : Set - fun findByEndBeforeAndProject(end: LocalDateTime, project: Project) : Set - fun findByStartAfterAndEndBeforeAndProjectIs(start: LocalDateTime, end: LocalDateTime, project: Project) : Set + fun findByStartAfterAndProject(start: Instant, project: Project) : Set + fun findByEndBeforeAndProject(end: Instant, project: Project) : Set + fun findByStartAfterAndEndBeforeAndProjectIs(start: Instant, end: Instant, project: Project) : Set } interface TagRepository : CrudRepository{} diff --git a/src/main/kotlin/uk/co/neviyn/projectplanner/Requests.kt b/src/main/kotlin/uk/co/neviyn/projectplanner/Requests.kt index 0b4ffb0..6c9c9bb 100644 --- a/src/main/kotlin/uk/co/neviyn/projectplanner/Requests.kt +++ b/src/main/kotlin/uk/co/neviyn/projectplanner/Requests.kt @@ -1,9 +1,11 @@ package uk.co.neviyn.projectplanner -import java.time.LocalDateTime +import java.time.Instant data class DisplayUser(val id: Long, val username: String, val email: String, val password: String, val oldPassword: String) data class NewProject(val title: String) -data class NewEvent(val title: String, val description: String, val start: LocalDateTime, val end: LocalDateTime) \ No newline at end of file +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 diff --git a/src/main/resources/templates/project.html b/src/main/resources/templates/project.html index 7779f93..1bb3d7c 100644 --- a/src/main/resources/templates/project.html +++ b/src/main/resources/templates/project.html @@ -7,7 +7,7 @@ -