Correction du endpoint /employee/current qui ne fonctionnait pas lorsque aucun employé n'était connecté parce que le paramêtre "loggedInEmployee" n'était pas nullable.

This commit is contained in:
FyloZ 2021-02-16 14:20:16 -05:00
parent 329b883a6a
commit a026c4a7a0
1 changed files with 41 additions and 19 deletions

View File

@ -19,36 +19,54 @@ private const val EMPLOYEE_GROUP_CONTROLLER_PATH = "api/employee/group"
@RequestMapping(EMPLOYEE_CONTROLLER_PATH)
@Profile("rest")
class EmployeeController(employeeService: EmployeeServiceImpl) :
AbstractModelRestApiController<Employee, EmployeeSaveDto, EmployeeUpdateDto, EmployeeServiceImpl>(employeeService, EMPLOYEE_CONTROLLER_PATH) {
AbstractModelRestApiController<Employee, EmployeeSaveDto, EmployeeUpdateDto, EmployeeServiceImpl>(
employeeService,
EMPLOYEE_CONTROLLER_PATH
) {
@GetMapping("current")
@ResponseStatus(HttpStatus.OK)
fun getCurrent(loggedInEmployee: Principal): ResponseEntity<Employee> = ResponseEntity.ok(service.getById(loggedInEmployee.name.toLong(), ignoreDefaultGroupUsers = false, ignoreSystemUsers = false))
fun getCurrent(loggedInEmployee: Principal?): ResponseEntity<Employee> = if (loggedInEmployee != null)
ResponseEntity.ok(
service.getById(
loggedInEmployee.name.toLong(),
ignoreDefaultGroupUsers = false,
ignoreSystemUsers = false
)
)
else
ResponseEntity.status(HttpStatus.FORBIDDEN).build()
@PutMapping("{id}/password", consumes = [MediaType.TEXT_PLAIN_VALUE])
@ResponseStatus(HttpStatus.NO_CONTENT)
fun updatePassword(@PathVariable id: Long, @RequestBody password: String): ResponseEntity<Void> {
service.updatePassword(id, password)
return ResponseEntity
.noContent()
.build()
.noContent()
.build()
}
@PutMapping("{employeeId}/permissions/{permission}")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun addPermission(@PathVariable employeeId: Long, @PathVariable permission: EmployeePermission): ResponseEntity<Void> {
fun addPermission(
@PathVariable employeeId: Long,
@PathVariable permission: EmployeePermission
): ResponseEntity<Void> {
service.addPermission(employeeId, permission)
return ResponseEntity
.noContent()
.build()
.noContent()
.build()
}
@DeleteMapping("{employeeId}/permissions/{permission}")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun removePermission(@PathVariable employeeId: Long, @PathVariable permission: EmployeePermission): ResponseEntity<Void> {
fun removePermission(
@PathVariable employeeId: Long,
@PathVariable permission: EmployeePermission
): ResponseEntity<Void> {
service.removePermission(employeeId, permission)
return ResponseEntity
.noContent()
.build()
.noContent()
.build()
}
@GetMapping("logout")
@ -63,32 +81,36 @@ class EmployeeController(employeeService: EmployeeServiceImpl) :
@RequestMapping(EMPLOYEE_GROUP_CONTROLLER_PATH)
@Profile("rest")
class GroupsController(groupService: EmployeeGroupServiceImpl) :
AbstractModelRestApiController<EmployeeGroup, EmployeeGroupSaveDto, EmployeeGroupUpdateDto, EmployeeGroupServiceImpl>(groupService, EMPLOYEE_GROUP_CONTROLLER_PATH) {
AbstractModelRestApiController<EmployeeGroup, EmployeeGroupSaveDto, EmployeeGroupUpdateDto, EmployeeGroupServiceImpl>(
groupService,
EMPLOYEE_GROUP_CONTROLLER_PATH
) {
@GetMapping("{id}/employees")
@ResponseStatus(HttpStatus.OK)
fun getEmployeesForGroup(@PathVariable id: Long): ResponseEntity<Collection<Employee>> = ResponseEntity.ok(service.getEmployeesForGroup(id))
fun getEmployeesForGroup(@PathVariable id: Long): ResponseEntity<Collection<Employee>> =
ResponseEntity.ok(service.getEmployeesForGroup(id))
@PostMapping("default/{groupId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun setDefaultGroup(@PathVariable groupId: Long, response: HttpServletResponse): ResponseEntity<Void> {
service.setResponseDefaultGroup(groupId, response)
return ResponseEntity
.noContent()
.build()
.noContent()
.build()
}
@GetMapping("default")
@ResponseStatus(HttpStatus.OK)
fun getRequestDefaultGroup(request: HttpServletRequest): ResponseEntity<EmployeeGroup> =
ResponseEntity.ok(service.getRequestDefaultGroup(request))
ResponseEntity.ok(service.getRequestDefaultGroup(request))
@PutMapping("{groupId}/{employeeId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
fun addEmployeeToGroup(@PathVariable groupId: Long, @PathVariable employeeId: Long): ResponseEntity<Void> {
service.addEmployeeToGroup(groupId, employeeId)
return ResponseEntity
.noContent()
.build()
.noContent()
.build()
}
@DeleteMapping("{groupId}/{employeeId}")
@ -96,7 +118,7 @@ class GroupsController(groupService: EmployeeGroupServiceImpl) :
fun removeEmployeeFromGroup(@PathVariable groupId: Long, @PathVariable employeeId: Long): ResponseEntity<Void> {
service.removeEmployeeFromGroup(groupId, employeeId)
return ResponseEntity
.noContent()
.build()
.noContent()
.build()
}
}