|
@@ -48,7 +48,7 @@ class ProjectController(
|
|
@PostMapping("/projects")
|
|
@PostMapping("/projects")
|
|
fun addProject(@RequestBody project: Project): ResponseEntity<Project> {
|
|
fun addProject(@RequestBody project: Project): ResponseEntity<Project> {
|
|
return try {
|
|
return try {
|
|
- val found = projectRepository.findByNameContaining(project.name).size
|
|
|
|
|
|
+ val found = projectRepository.countByName(project.name)
|
|
if (project.name.isNotBlank()) {
|
|
if (project.name.isNotBlank()) {
|
|
if (project.name.length > 100 || project.description!!.length > 255) {//too long
|
|
if (project.name.length > 100 || project.description!!.length > 255) {//too long
|
|
ResponseEntity<Project>(HttpStatus.PAYLOAD_TOO_LARGE)
|
|
ResponseEntity<Project>(HttpStatus.PAYLOAD_TOO_LARGE)
|
|
@@ -73,31 +73,33 @@ class ProjectController(
|
|
@PutMapping("/projects/{id}")
|
|
@PutMapping("/projects/{id}")
|
|
fun updateProjectById(@PathVariable("id") id: Long, @RequestBody project: Project): ResponseEntity<out Any?> {
|
|
fun updateProjectById(@PathVariable("id") id: Long, @RequestBody project: Project): ResponseEntity<out Any?> {
|
|
val projectData = projectRepository.findById(id)
|
|
val projectData = projectRepository.findById(id)
|
|
- val found = projectRepository.findByNameContaining(project.name).size
|
|
|
|
|
|
+ val found = projectRepository.countByName(project.name)
|
|
val userId = userRepository.getUserByUsername(SecurityContextHolder.getContext().authentication.name)
|
|
val userId = userRepository.getUserByUsername(SecurityContextHolder.getContext().authentication.name)
|
|
val validOwner = projectRepository.validOwner(id.toString(), userId.id.toString())
|
|
val validOwner = projectRepository.validOwner(id.toString(), userId.id.toString())
|
|
val validAdmin = memberRepository.validRole(id.toString(), userId.id.toString(), "2")
|
|
val validAdmin = memberRepository.validRole(id.toString(), userId.id.toString(), "2")
|
|
- return if (validOwner > 0 || validAdmin > 0) {
|
|
|
|
- if (project.name.isNotBlank()) {
|
|
|
|
- if (project.name.length > 100 || project.description!!.length > 255) {//too long
|
|
|
|
- ResponseEntity<Project>(HttpStatus.PAYLOAD_TOO_LARGE)
|
|
|
|
- } else if (projectData.isPresent) {
|
|
|
|
- if ((project.name == projectData.get().name && found > 0) || (project.name !== projectData.get().name && found == 0)) {
|
|
|
|
- val saveProject = projectData.get()
|
|
|
|
- saveProject.name = project.name.trim()
|
|
|
|
- saveProject.description = project.description
|
|
|
|
- ResponseEntity<Any?>(projectRepository.save(saveProject), HttpStatus.OK)
|
|
|
|
- } else {//duplicate
|
|
|
|
- ResponseEntity<Project>(HttpStatus.CONFLICT)
|
|
|
|
|
|
+ return if (projectData.isPresent) {
|
|
|
|
+ if (validOwner > 0 || validAdmin > 0) {
|
|
|
|
+ if (project.name.isNotBlank()) {
|
|
|
|
+ if (project.name.length > 100 || project.description!!.length > 255) {//too long
|
|
|
|
+ ResponseEntity<Project>(HttpStatus.PAYLOAD_TOO_LARGE)
|
|
|
|
+ } else {
|
|
|
|
+ if ((project.name == projectData.get().name && found > 0) || (project.name !== projectData.get().name && found == 0)) {
|
|
|
|
+ val saveProject = projectData.get()
|
|
|
|
+ saveProject.name = project.name.trim()
|
|
|
|
+ saveProject.description = project.description
|
|
|
|
+ ResponseEntity<Any?>(projectRepository.save(saveProject), HttpStatus.OK)
|
|
|
|
+ } else {//duplicate
|
|
|
|
+ ResponseEntity<Project>(HttpStatus.CONFLICT)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- } else {//target invalid
|
|
|
|
- ResponseEntity<Project?>(HttpStatus.NOT_FOUND)
|
|
|
|
|
|
+ } else {//name invalid
|
|
|
|
+ ResponseEntity<Project?>(HttpStatus.BAD_REQUEST)
|
|
}
|
|
}
|
|
- } else {//name invalid
|
|
|
|
- ResponseEntity<Project?>(HttpStatus.BAD_REQUEST)
|
|
|
|
|
|
+ } else {
|
|
|
|
+ ResponseEntity<Project>(HttpStatus.FORBIDDEN)
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- ResponseEntity<Project>(HttpStatus.FORBIDDEN)
|
|
|
|
|
|
+ ResponseEntity<Project?>(HttpStatus.NOT_FOUND)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|