Creation of new projects
This commit is contained in:
parent
ef621c7573
commit
bf145aed44
@ -39,7 +39,12 @@ class Project(
|
||||
@JsonIgnore
|
||||
var events: MutableSet<Event> = mutableSetOf(),
|
||||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) var id: Long? = null
|
||||
)
|
||||
) {
|
||||
fun addMember(member: User){
|
||||
members.add(member)
|
||||
member.projects.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
@Entity
|
||||
class Event(
|
||||
|
@ -70,16 +70,21 @@ class HtmlController @Autowired constructor(val userRepository: UserRepository,
|
||||
}
|
||||
|
||||
@PostMapping("/newproject")
|
||||
fun createNewProject(@RequestBody newProject: NewProject){
|
||||
val project = Project(title = newProject.name)
|
||||
@Transactional
|
||||
fun createNewProject(@ModelAttribute newProject: NewProject, @AuthenticationPrincipal userDetails: CustomUserDetails) : String {
|
||||
val project = Project(title = newProject.title)
|
||||
val user = entityManager.merge(userDetails.user)
|
||||
project.addMember(user)
|
||||
projectRepository.save(project)
|
||||
return "redirect:/project/" + project.id
|
||||
}
|
||||
|
||||
@GetMapping("/projects")
|
||||
@Transactional
|
||||
fun listUserProjects(model: Model, @AuthenticationPrincipal userDetails: CustomUserDetails) : String {
|
||||
val user = entityManager.merge(userDetails.user) // Reattach User entity
|
||||
model.addAttribute("projects", user.projects)
|
||||
model.addAttribute("projects", user.projects.sortedBy { it.id })
|
||||
model.addAttribute("newProject", NewProject(""))
|
||||
return "projectlist"
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,6 @@ data class SimpleUser(val id: Long, val username: String)
|
||||
|
||||
data class DisplayUser(val id: Long, val username: String, val email: String, val password: String, val oldPassword: String)
|
||||
|
||||
data class NewProject(val name: String)
|
||||
data class NewProject(val title: String)
|
||||
|
||||
data class NewEvent(val title: String, val description: String, val start: LocalDateTime, val end: LocalDateTime)
|
@ -23,6 +23,36 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row justify-content-center mt-3">
|
||||
<div class="col-xl-6 col-md-8 col-sm-12">
|
||||
<div class="list-group">
|
||||
<button class="list-group-item list-group-item-action list-group-item-secondary"
|
||||
data-bs-target="#newProjectModal" data-bs-toggle="modal">New Project...
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal" id="newProjectModal" tabindex="-1">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">New Project</h5>
|
||||
<button aria-label="Close" class="btn-close" data-bs-dismiss="modal" type="button"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form id="newProjectForm" class="form-floating mb-3" th:action="@{/newproject}" th:object="${newProject}" method="post">
|
||||
<input class="form-control" id="titleInput" type="text" th:field="*{title}" required>
|
||||
<label for="titleInput">Project Title</label>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-secondary" data-bs-dismiss="modal" type="button">Close</button>
|
||||
<button class="btn btn-primary" type="submit" form="newProjectForm">Create Project</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user