@@ -68,27 +68,23 @@ open class TeamService( | |||||
val addIds = req.addStaffIds ?: listOf<Int>() | val addIds = req.addStaffIds ?: listOf<Int>() | ||||
val teamLead: Staff | val teamLead: Staff | ||||
val teamName: String | |||||
val teamCode: String | |||||
// val teamName: String | |||||
// val teamCode: String | |||||
if (addIds.isNotEmpty()) { | if (addIds.isNotEmpty()) { | ||||
val leader = staffRepository.findById(addIds[0].toLong()).orElseThrow() | val leader = staffRepository.findById(addIds[0].toLong()).orElseThrow() | ||||
// teamName = "Team " + leader.name | // teamName = "Team " + leader.name | ||||
teamName = req.name | |||||
teamLead = leader; | teamLead = leader; | ||||
// val initials = leader.name.split(" ").map { it.first() } | // val initials = leader.name.split(" ").map { it.first() } | ||||
// teamCode = initials.joinToString("") | // teamCode = initials.joinToString("") | ||||
teamCode = req.code | |||||
} else { | } else { | ||||
teamLead = team.staff | teamLead = team.staff | ||||
teamName = team.name | |||||
teamCode = team.code | |||||
} | } | ||||
team.apply { | team.apply { | ||||
this.staff = teamLead | this.staff = teamLead | ||||
name = teamName | |||||
code = teamCode | |||||
name = req.name | |||||
code = req.code | |||||
description = req.description | description = req.description | ||||
} | } | ||||
@@ -41,15 +41,18 @@ class TeamController( | |||||
} | } | ||||
@GetMapping("/{id}") | @GetMapping("/{id}") | ||||
fun getStaff(@PathVariable id: Long): MutableMap<String, Any> { | |||||
val map: MutableMap<String, Any> = mutableMapOf("team" to teamService.find(id).orElseThrow { NotFoundException() }) | |||||
fun getStaff(@PathVariable id: Long): Map<String, Any> { | |||||
val staffList = staffsService.findAllByTeamId(id).orElseThrow { NotFoundException() } | val staffList = staffsService.findAllByTeamId(id).orElseThrow { NotFoundException() } | ||||
val staffIdList: MutableList<Long> = mutableListOf() | val staffIdList: MutableList<Long> = mutableListOf() | ||||
for (staff in staffList) { | for (staff in staffList) { | ||||
staffIdList.add(staff.id as Long) | staffIdList.add(staff.id as Long) | ||||
} | } | ||||
map["staffIds"] = staffIdList | |||||
return map | |||||
// val map: Map<String, Any> = java.util.Map.of("team" to teamService.find(id).orElseThrow { NotFoundException() }) | |||||
// map["staffIds"] = staffIdList | |||||
return java.util.Map.of( | |||||
"team", staffsService.find(id).orElseThrow { NotFoundException() }, | |||||
"staffIds", staffIdList | |||||
) | |||||
} | } | ||||
// @Transactional(rollbackFor = [Exception::class]) | // @Transactional(rollbackFor = [Exception::class]) | ||||