Skip to content

Commit bf950d2

Browse files
committed
Conditional staff visibility
1 parent f193866 commit bf950d2

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

src/main/kotlin/be/sgl/backend/entity/setting/SettingId.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ enum class SettingId {
55
REPRESENTATIVE_TITLE,
66
REPRESENTATIVE_USERNAME,
77
REPRESENTATIVE_SIGNATURE,
8-
CALENDAR_NAME
8+
CALENDAR_NAME,
9+
STAFF_VISIBLE
910
}

src/main/kotlin/be/sgl/backend/service/BranchService.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package be.sgl.backend.service
33
import be.sgl.backend.dto.BranchBaseDTO
44
import be.sgl.backend.dto.BranchDTO
55
import be.sgl.backend.entity.branch.Branch
6+
import be.sgl.backend.entity.branch.BranchStatus
7+
import be.sgl.backend.entity.setting.SettingId
68
import be.sgl.backend.repository.BranchRepository
79
import be.sgl.backend.repository.user.UserRepository
810
import be.sgl.backend.service.exception.BranchNotFoundException
@@ -22,10 +24,14 @@ class BranchService {
2224
private lateinit var mapper: BranchMapper
2325
@Autowired
2426
private lateinit var imageService: ImageService
27+
@Autowired
28+
private lateinit var settingService: SettingService
2529

2630
fun getBranchDTOById(id: Int): BranchDTO {
2731
val branch = getBranchById(id)
28-
branch.staff = userRepository.getStaffForBranch(branch)
32+
if (branch.status != BranchStatus.ACTIVE || settingService.getOrDefault(SettingId.STAFF_VISIBLE, true)) {
33+
branch.staff = userRepository.getStaffForBranch(branch)
34+
}
2935
return mapper.toDto(branch)
3036
}
3137

src/main/kotlin/be/sgl/backend/service/SettingService.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ class SettingService {
2525
return get(id)?.toDouble() ?: default
2626
}
2727

28+
fun getOrDefault(id: SettingId, default: Boolean): Boolean {
29+
return get(id)?.toBoolean() ?: default
30+
}
31+
2832
fun update(id: SettingId, value: Any?) {
2933
value ?: return settingRepository.deleteById(id.name)
3034
val setting = settingRepository.findByIdOrNull(id.name) ?: Setting(id, value)

0 commit comments

Comments
 (0)