Events are now viewable

This commit is contained in:
neviyn 2021-03-31 20:47:20 +01:00
parent f61fd78287
commit 570151a5ec
3 changed files with 41 additions and 12 deletions

View File

@ -12,6 +12,11 @@ import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
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
@ -105,19 +110,28 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep
return "project"
}
val f: DateTimeFormatter = DateTimeFormatter.ISO_INSTANT
@GetMapping("/events")
@PreAuthorize("hasPermission(#id, 'Long', '')")
fun getProjectEvents(@PathVariable id: Long) : Set<Event> {
return projectRepository.findById(id).get().events
@ResponseBody
fun getProjectEventsBetween(@PathVariable id: Long, @RequestParam start: String?, @RequestParam end: String?) : Set<Event> {
val startTime: LocalDateTime? = LocalDateTime.ofInstant(Instant.from(f.parse(start)), ZoneOffset.UTC)
val endTime: LocalDateTime? = LocalDateTime.ofInstant(Instant.from(f.parse(end)), ZoneOffset.UTC)
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)
}
@PostMapping("/adduser")
@PreAuthorize("hasPermission(#id, 'Long', '')")
fun addUserToProject(@PathVariable id: Long, @RequestParam("uid") uid: Long) : String {
val user = userRepository.findById(uid).get()
val project = projectRepository.findById(id).get()
project.members.add(user)
user.projects.add(project)
project.addMember(user)
projectRepository.save(project)
return "redirect:/project/$id"
}
@ -141,4 +155,18 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep
val event = Event(title = e.title, description = e.description, start = e.start, end = e.end, project = project)
eventRepository.save(event)
}
@PostMapping("/editevent")
@PreAuthorize("hasPermission(#id, 'Long', '')")
fun editEvent(@PathVariable id: Long) {
TODO()
}
@PostMapping("/deleteevent")
@PreAuthorize("hasPermission(#id, 'Long', '')")
fun deleteEvent(@PathVariable id: Long) {
TODO()
}
}

View File

@ -1,16 +1,20 @@
package uk.co.neviyn.projectplanner
import org.springframework.data.repository.CrudRepository
import java.time.LocalDateTime
interface UserRepository : CrudRepository<User, Long>{
fun findByUsername(username: String): User?
fun findByUsernameIsLike(partialUsername: String) : List<User>
fun findByIdNotIn(ids: List<Long>) : List<User>
}
interface ProjectRepository : CrudRepository<Project, Long>{}
interface EventRepository : CrudRepository<Event, Long>{}
interface EventRepository : CrudRepository<Event, Long>{
fun findByStartAfterAndProject(start: LocalDateTime, project: Project) : Set<Event>
fun findByEndBeforeAndProject(end: LocalDateTime, project: Project) : Set<Event>
fun findByStartAfterAndEndBeforeAndProjectIs(start: LocalDateTime, end: LocalDateTime, project: Project) : Set<Event>
}
interface TagRepository : CrudRepository<Tag, Long>{}

View File

@ -21,18 +21,15 @@
aspectRatio: 2.2,
eventAdd(addInfo) {
console.log(addInfo.event)
}
},
events: window.location.origin + window.location.pathname + "/events"
});
calendar.render();
};
</script>
<script th:inline="javascript">
window.onload = function () {
const options = {
valueNames: ['username'],
};
new List('user-list', options);
}
};
</script>
<title></title>
</head>