-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #215 from DSM-PICK/214-classroom-startplace-error
🔀 :: (PICK-214)classroom startplace error
- Loading branch information
Showing
9 changed files
with
106 additions
and
50 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
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
62 changes: 38 additions & 24 deletions
62
src/main/kotlin/dsm/pick2024/domain/classroom/service/QueryFloorClassroomService.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,46 +1,60 @@ | ||
package dsm.pick2024.domain.classroom.service | ||
|
||
import dsm.pick2024.domain.application.enums.Status | ||
import dsm.pick2024.domain.attendance.port.out.QueryAttendancePort | ||
import dsm.pick2024.domain.classroom.exception.FloorNotFoundException | ||
import dsm.pick2024.domain.classroom.port.`in`.QueryFloorClassroomUseCase | ||
import dsm.pick2024.domain.classroom.port.out.QueryClassroomPort | ||
import dsm.pick2024.domain.classroom.presentation.dto.response.QueryClassroomResponse | ||
import org.joda.time.LocalDate | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class QueryFloorClassroomService( | ||
private val queryClassroomPort: QueryClassroomPort | ||
private val queryClassroomPort: QueryClassroomPort, | ||
private val queryAttendancePort: QueryAttendancePort | ||
) : QueryFloorClassroomUseCase { | ||
|
||
@Transactional(readOnly = true) | ||
override fun queryFloorClassroom( | ||
floor: Int, | ||
status: Status | ||
): List<QueryClassroomResponse> { | ||
val classrooms = when (floor) { | ||
2, 3, 4 -> { | ||
queryClassroomPort.queryFloorClassroom(floor) | ||
.filter { it.status == if (status == Status.QUIET) Status.QUIET else Status.OK } | ||
when (floor) { | ||
2, 3, 4, 5 -> { | ||
val today = LocalDate.now().dayOfWeek | ||
|
||
val dayFilter = if (today == 2 || today == 5) { | ||
queryClassroomPort.queryFloorClassroomWithAttendance(floor) | ||
.filter { it.status == if (status == Status.QUIET) Status.QUIET else Status.OK } | ||
} else { | ||
queryClassroomPort.queryFloorClassroom(floor) | ||
.filter { it.status == if (status == Status.QUIET) Status.QUIET else Status.OK } | ||
} | ||
|
||
return dayFilter.map { classroom -> | ||
val move = if (today == 2 || today == 5) { | ||
queryAttendancePort.findByUserId(classroom.userId)?.place ?: "" | ||
} else { | ||
"${classroom.grade}-${classroom.classNum}" | ||
} | ||
|
||
QueryClassroomResponse( | ||
id = classroom.userId, | ||
username = classroom.userName, | ||
classroomName = classroom.classroomName, | ||
move = move, | ||
grade = classroom.grade, | ||
classNum = classroom.classNum, | ||
num = classroom.num, | ||
startPeriod = classroom.startPeriod, | ||
endPeriod = classroom.endPeriod | ||
) | ||
}.sortedWith(compareBy({ it.grade }, { it.classNum }, { it.num })) | ||
} | ||
5 -> { | ||
queryClassroomPort.findAllByStatus(status) | ||
|
||
else -> { | ||
throw FloorNotFoundException | ||
} | ||
else -> throw FloorNotFoundException | ||
} | ||
|
||
return classrooms.map { | ||
QueryClassroomResponse( | ||
id = it.userId, | ||
username = it.userName, | ||
classroomName = it.classroomName, | ||
move = "${it.grade}-${it.classNum}", | ||
grade = it.grade, | ||
classNum = it.classNum, | ||
num = it.num, | ||
startPeriod = it.startPeriod, | ||
endPeriod = it.endPeriod | ||
) | ||
}.sortedWith(compareBy({ it.grade }, { it.classNum }, { it.num })) | ||
} | ||
} |
41 changes: 26 additions & 15 deletions
41
src/main/kotlin/dsm/pick2024/domain/classroom/service/QueryGradeClassroomService.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,33 +1,44 @@ | ||
package dsm.pick2024.domain.classroom.service | ||
|
||
import dsm.pick2024.domain.attendance.port.out.QueryAttendancePort | ||
import dsm.pick2024.domain.classroom.port.`in`.QueryGradeClassroomUseCase | ||
import dsm.pick2024.domain.classroom.port.out.QueryClassroomPort | ||
import dsm.pick2024.domain.classroom.presentation.dto.response.QueryClassroomResponse | ||
import org.joda.time.LocalDate | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
class QueryGradeClassroomService( | ||
private val queryClassroomPort: QueryClassroomPort | ||
private val queryClassroomPort: QueryClassroomPort, | ||
private val queryAttendancePort: QueryAttendancePort | ||
) : QueryGradeClassroomUseCase { | ||
@Transactional(readOnly = true) | ||
override fun queryGradeClassroom( | ||
grade: Int, | ||
classNum: Int | ||
) = | ||
queryClassroomPort.queryGradeClassroom(grade, classNum) | ||
.map { | ||
it -> | ||
): List<QueryClassroomResponse> { | ||
val today = LocalDate.now().dayOfWeek | ||
|
||
return queryClassroomPort.queryGradeClassroom(grade, classNum) | ||
.map { classroom -> | ||
val move = if (today == 2 || today == 5) { | ||
queryAttendancePort.findByUserId(classroom.userId)?.place ?: "" | ||
} else { | ||
"${classroom.grade}-${classroom.classNum}" | ||
} | ||
|
||
QueryClassroomResponse( | ||
id = it.userId, | ||
username = it.userName, | ||
classroomName = it.classroomName, | ||
move = "${it.grade}-${it.classNum}", | ||
grade = it.grade, | ||
classNum = it.classNum, | ||
num = it.num, | ||
startPeriod = it.startPeriod, | ||
endPeriod = it.endPeriod | ||
id = classroom.userId, | ||
username = classroom.userName, | ||
classroomName = classroom.classroomName, | ||
move = move, | ||
grade = classroom.grade, | ||
classNum = classroom.classNum, | ||
num = classroom.num, | ||
startPeriod = classroom.startPeriod, | ||
endPeriod = classroom.endPeriod | ||
) | ||
} | ||
}.sortedWith(compareBy({ it.grade }, { it.classNum }, { it.num })) | ||
} | ||
} |