Events are now viewable
This commit is contained in:
parent
f61fd78287
commit
570151a5ec
@ -12,6 +12,11 @@ import org.springframework.web.bind.annotation.PostMapping
|
|||||||
import org.springframework.web.bind.annotation.RequestBody
|
import org.springframework.web.bind.annotation.RequestBody
|
||||||
import org.springframework.web.bind.annotation.RequestMapping
|
import org.springframework.web.bind.annotation.RequestMapping
|
||||||
import org.springframework.web.bind.annotation.RequestParam
|
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.persistence.EntityManager
|
||||||
import javax.transaction.Transactional
|
import javax.transaction.Transactional
|
||||||
|
|
||||||
@ -105,19 +110,28 @@ class ProjectController @Autowired constructor(val projectRepository: ProjectRep
|
|||||||
return "project"
|
return "project"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val f: DateTimeFormatter = DateTimeFormatter.ISO_INSTANT
|
||||||
|
|
||||||
@GetMapping("/events")
|
@GetMapping("/events")
|
||||||
@PreAuthorize("hasPermission(#id, 'Long', '')")
|
@PreAuthorize("hasPermission(#id, 'Long', '')")
|
||||||
fun getProjectEvents(@PathVariable id: Long) : Set<Event> {
|
@ResponseBody
|
||||||
return projectRepository.findById(id).get().events
|
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")
|
@PostMapping("/adduser")
|
||||||
@PreAuthorize("hasPermission(#id, 'Long', '')")
|
@PreAuthorize("hasPermission(#id, 'Long', '')")
|
||||||
fun addUserToProject(@PathVariable id: Long, @RequestParam("uid") uid: Long) : String {
|
fun addUserToProject(@PathVariable id: Long, @RequestParam("uid") uid: Long) : String {
|
||||||
val user = userRepository.findById(uid).get()
|
val user = userRepository.findById(uid).get()
|
||||||
val project = projectRepository.findById(id).get()
|
val project = projectRepository.findById(id).get()
|
||||||
project.members.add(user)
|
project.addMember(user)
|
||||||
user.projects.add(project)
|
|
||||||
projectRepository.save(project)
|
projectRepository.save(project)
|
||||||
return "redirect:/project/$id"
|
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)
|
val event = Event(title = e.title, description = e.description, start = e.start, end = e.end, project = project)
|
||||||
eventRepository.save(event)
|
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()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,16 +1,20 @@
|
|||||||
package uk.co.neviyn.projectplanner
|
package uk.co.neviyn.projectplanner
|
||||||
|
|
||||||
import org.springframework.data.repository.CrudRepository
|
import org.springframework.data.repository.CrudRepository
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
interface UserRepository : CrudRepository<User, Long>{
|
interface UserRepository : CrudRepository<User, Long>{
|
||||||
fun findByUsername(username: String): User?
|
fun findByUsername(username: String): User?
|
||||||
fun findByUsernameIsLike(partialUsername: String) : List<User>
|
|
||||||
fun findByIdNotIn(ids: List<Long>) : List<User>
|
fun findByIdNotIn(ids: List<Long>) : List<User>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ProjectRepository : CrudRepository<Project, Long>{}
|
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>{}
|
interface TagRepository : CrudRepository<Tag, Long>{}
|
||||||
|
|
||||||
|
@ -21,18 +21,15 @@
|
|||||||
aspectRatio: 2.2,
|
aspectRatio: 2.2,
|
||||||
eventAdd(addInfo) {
|
eventAdd(addInfo) {
|
||||||
console.log(addInfo.event)
|
console.log(addInfo.event)
|
||||||
}
|
},
|
||||||
|
events: window.location.origin + window.location.pathname + "/events"
|
||||||
});
|
});
|
||||||
calendar.render();
|
calendar.render();
|
||||||
};
|
|
||||||
</script>
|
|
||||||
<script th:inline="javascript">
|
|
||||||
window.onload = function () {
|
|
||||||
const options = {
|
const options = {
|
||||||
valueNames: ['username'],
|
valueNames: ['username'],
|
||||||
};
|
};
|
||||||
new List('user-list', options);
|
new List('user-list', options);
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
<title></title>
|
<title></title>
|
||||||
</head>
|
</head>
|
||||||
|
Loading…
Reference in New Issue
Block a user