-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
183 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 34 additions & 1 deletion
35
moit-api/src/main/kotlin/com/mashup/moit/fine/facade/FineFacade.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,40 @@ | ||
package com.mashup.moit.fine.facade | ||
|
||
import com.mashup.moit.domain.fine.FineService | ||
import com.mashup.moit.domain.study.StudyService | ||
import com.mashup.moit.domain.user.UserService | ||
import com.mashup.moit.fine.controller.dto.FineListResponse | ||
import com.mashup.moit.fine.controller.dto.FineResponseForListView | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class FineFacade { | ||
class FineFacade( | ||
private val fineService: FineService, | ||
private val studyService: StudyService, | ||
private val userService: UserService | ||
) { | ||
fun getFineList(moitId: Long): FineListResponse { | ||
val fineList = fineService.getFineListByMoitId(moitId) | ||
if (fineList.isEmpty()) { | ||
return FineListResponse.emptyFineList() | ||
} | ||
|
||
val fineUserIds = fineList.map { it.userId }.distinct() | ||
val fineUsersMap = userService.findUsersByIds(fineUserIds).associateBy { it.id } | ||
|
||
val fineStudyIds = fineList.map { it.studyId }.distinct() | ||
val fineStudyMap = studyService.findByStudyIds(fineStudyIds).associateBy { it.id } | ||
|
||
val totalFineAmount = fineList.sumOf { it.amount } | ||
val (fineComplete, fineNotYet) = fineList.partition { it.isApproved } | ||
.let { (approvedFineList, isNotApprovedFineList) -> | ||
approvedFineList.map { | ||
FineResponseForListView.of(it, fineUsersMap[it.userId]!!, fineStudyMap[it.studyId]!!) | ||
} to isNotApprovedFineList.map { | ||
FineResponseForListView.of(it, fineUsersMap[it.userId]!!, fineStudyMap[it.studyId]!!) | ||
} | ||
} | ||
|
||
return FineListResponse(totalFineAmount, fineNotYet, fineComplete) | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
moit-domain/src/main/kotlin/com/mashup/moit/domain/fine/Fine.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,22 @@ | ||
package com.mashup.moit.domain.fine | ||
|
||
import com.mashup.moit.domain.attendance.AttendanceStatus | ||
import java.time.LocalDateTime | ||
|
||
enum class FineApproveStatus { | ||
NEW, IN_PROGRESS, REJECTED, APPROVED; | ||
} | ||
|
||
data class Fine( | ||
val id: Long, | ||
val moitId: Long, | ||
val studyId: Long, | ||
val userId: Long, | ||
val attendanceStatus: AttendanceStatus, | ||
val amount: Long, | ||
val isApproved: Boolean, | ||
val approveStatus: FineApproveStatus, | ||
val approvedAt: LocalDateTime?, | ||
val approveImageUrl: String?, | ||
val registerAt: LocalDateTime, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
moit-domain/src/main/kotlin/com/mashup/moit/domain/fine/FineRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mashup.moit.domain.fine | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface FineRepository : JpaRepository<FineEntity, Long> { | ||
fun findByMoitId(moitId: Long) : List<FineEntity> | ||
} |
12 changes: 12 additions & 0 deletions
12
moit-domain/src/main/kotlin/com/mashup/moit/domain/fine/FineService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.mashup.moit.domain.fine | ||
|
||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class FineService( | ||
private val fineRepository: FineRepository | ||
) { | ||
fun getFineListByMoitId(moitId: Long): List<Fine> { | ||
return fineRepository.findByMoitId(moitId).map { it.toDomain() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
moit-domain/src/main/kotlin/com/mashup/moit/domain/study/Study.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.mashup.moit.domain.study | ||
|
||
data class Study( | ||
val id: Long, | ||
val moitId: Long, | ||
val order: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
moit-domain/src/main/kotlin/com/mashup/moit/domain/user/UserService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.mashup.moit.domain.user | ||
|
||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class UserService( | ||
private val userRepository: UserRepository | ||
) { | ||
fun findUsersByIds(ids: List<Long>): List<User> { | ||
return userRepository.findByIdIn(ids) | ||
.map { it.toDomain() } | ||
} | ||
} |