Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] 시간표 학기 페이지 리팩토링 1차 #519

Open
wants to merge 27 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
22cb27d
[Fix] TimetableFrame 매퍼 함수명 수정
nodobi Dec 7, 2024
2779208
[Add] 프레임 불러오는 API 변경사항 반영
nodobi Dec 7, 2024
7069a8c
[refactor] 사용하지 않는 usecase 삭제
nodobi Dec 7, 2024
610030f
[add] 모든 학기의 프레임 불러오는 유즈케이스 추가
nodobi Dec 22, 2024
0372d31
[add] 시간표 롤백 api, 유즈케이스 추가
nodobi Dec 22, 2024
b618456
[refactor] 시간표 프레임 정렬 로직 삭제
nodobi Dec 23, 2024
2277d87
[refactor] 프레임 복구, 갱신 로직 변경
nodobi Dec 23, 2024
cd955c2
[fix] 불필요한 코드 제거
nodobi Dec 24, 2024
58578ad
[fix] 형식 맞지 않은 dto 수정
nodobi Dec 24, 2024
a305585
[refactor] userSemester 가 userTimetableFrames 을 사용하도록 변경
nodobi Dec 24, 2024
1bc5e9b
[refactor] _userSemester 제거
nodobi Dec 24, 2024
75433b2
[refactor] 다이얼로그 노출 상태 screenState 로 이동
nodobi Dec 24, 2024
7977fb6
[refactor] 연도 선택 다이얼로그 노출 상태 screenState 에 추가
nodobi Dec 24, 2024
d7853da
[refactor] 연도 선택 다이얼로그 노출 상태 콜백 추가
nodobi Dec 24, 2024
5bd1cd4
[refactor] 연도 선택 다이얼로그에 상태 적용
nodobi Dec 24, 2024
e0041ea
[refactor] 학기 선택 가능한 연도 초기화 cold flow 로 변경
nodobi Dec 26, 2024
008b485
[refactor] UI 모드 변경 함수 이름 변경
nodobi Dec 26, 2024
d6900f7
[refactor] screenState 에 유저 프레임 상태 추가
nodobi Dec 26, 2024
cb755b1
[refactor] 기존 유저 프레임 변수 사용하는 부분 대체
nodobi Dec 26, 2024
f236ff3
[refactor] userTimetableFrame 의존성 대체
nodobi Dec 26, 2024
077786d
[refactor] _userTimetableFrame 제거
nodobi Dec 26, 2024
cb31f74
[refactor] 초기 데이터 로딩 flow 로 이전
nodobi Dec 28, 2024
0064cf7
[refactor] 기존 초기화 로직 제거
nodobi Dec 28, 2024
23622ca
[refactor] 익명 여부 상태에 추가
nodobi Dec 28, 2024
4443c0c
[refactor] 기존 익명 상태 제거
nodobi Dec 28, 2024
0134174
[add] 상태에 유저의 학기 추가
nodobi Dec 28, 2024
7a757e2
[refactor] 기존 userSemester 제거
nodobi Dec 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import `in`.koreatech.koin.data.request.timetable.TimetableFrameQueryRequest
import `in`.koreatech.koin.data.request.timetable.TimetableLecturesQueryRequest
import `in`.koreatech.koin.data.response.timetable.SemesterCheckResponse
import `in`.koreatech.koin.data.response.timetable.TimetableFrameResponse
import `in`.koreatech.koin.data.response.timetable.TimetableFramesResponse
import `in`.koreatech.koin.data.response.timetable.TimetableLecturesResponse
import retrofit2.Response
import retrofit2.http.Body
Expand Down Expand Up @@ -46,16 +47,32 @@ interface TimetableAuthApi {
@Body frame: TimetableFrameCreateQueryRequest
): TimetableFrameResponse

@POST("/v2/timetables/frame/rollback")
suspend fun postRollbackFrame(
@Query("timetable_frame_id") frameId: Int
): TimetableLecturesResponse

@DELETE("/v2/timetables/frame")
suspend fun deleteTimetableFrame(
@Query("id") frameId: Int
): Response<Unit>

/**
* @param semester 학기명
* @return 학기의 프레임 리스트
*/
@GET("/v2/timetables/frames")
suspend fun getTimetableFrames(
@Query("semester") semester: String
): List<TimetableFrameResponse>

/**
* 학생이 추가한 모든 학기의 프레임을 불러옴
* @return 학생이 추가한 모든 시간표 프레임
*/
@GET("/v2/timetables/frames")
suspend fun getAllFrames(): TimetableFramesResponse

@DELETE("/v2/timetables/lecture/{id}")
suspend fun deleteTimetableLecture(
@Path("id") id: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class TimetableRepositoryImpl @Inject constructor(
}

override fun getTimetableFrames(semester: String): Flow<List<TimetableFrame>> = flow {
emit(timetableRemoteDataSource.getTimetableFrames(semester).map { it.toTimetableFrameResponse() })
emit(timetableRemoteDataSource.getTimetableFrames(semester).map { it.toTimetableFrame() })
}

override fun getAllFrames(): Flow<Map<String, List<TimetableFrame>>> = flow {
emit(timetableRemoteDataSource.getAllFrames().mapValues { it.value.map { it.toTimetableFrame() } })
}

override suspend fun getTimetableLectures(timetableFrameId: Int): Result<TimetableLectures> = runCatching {
Expand Down Expand Up @@ -83,7 +87,7 @@ class TimetableRepositoryImpl @Inject constructor(
frame.timetableName,
frame.isMain
)
).toTimetableFrameResponse()
).toTimetableFrame()
}

override suspend fun postTimetableLectures(frameId: Int, lectures: List<Lecture>): Result<TimetableLectures> = runCatching {
Expand Down Expand Up @@ -135,12 +139,15 @@ class TimetableRepositoryImpl @Inject constructor(
semester = frame.semester,
timetableName = frame.timetableName
)
).toTimetableFrameResponse()
).toTimetableFrame()
}.recoverCatching {
if(it is HttpException) throw Exception(it.getErrorResponse().message ?: "")
else throw it
}

override suspend fun postRollbackFrame(frameId: Int): Result<TimetableLectures> = runCatching {
timetableRemoteDataSource.postRollbackFrame(frameId).toTimetableLectures()
}

override suspend fun deleteTimetableFrame(frameId: Int): Result<Unit> = runCatching {
timetableRemoteDataSource.deleteTimetableFrame(frameId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data class TimetableFrameResponse(
@SerializedName("is_main")
val isMain: Boolean,
) {
fun toTimetableFrameResponse(): TimetableFrame = TimetableFrame(
fun toTimetableFrame(): TimetableFrame = TimetableFrame(
id = id,
timetableName = timetableName.orEmpty(),
isMain = isMain
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package `in`.koreatech.koin.data.response.timetable

import com.google.gson.annotations.SerializedName

data class TimetableFramesResponse(
@SerializedName("semesters")
val semesterFrames: Map<String, List<TimetableFrameResponse>>
)
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class TimetableRemoteDataSource @Inject constructor(
semester: String
): List<TimetableFrameResponse> = timetableAuthApi.getTimetableFrames(semester)

suspend fun getAllFrames(): Map<String, List<TimetableFrameResponse>> =
timetableAuthApi.getAllFrames().semesterFrames

suspend fun putTimetableLectures(
lectures: TimetableLecturesQueryRequest
): TimetableLecturesResponse = timetableAuthApi.putTimetableLectures(lectures)
Expand All @@ -47,6 +50,10 @@ class TimetableRemoteDataSource @Inject constructor(
frame: TimetableFrameCreateQueryRequest
): TimetableFrameResponse = timetableAuthApi.postTimetableFrame(frame)

suspend fun postRollbackFrame(
frameId: Int
): TimetableLecturesResponse = timetableAuthApi.postRollbackFrame(frameId)

suspend fun deleteTimetableFrame(
frameId: Int
) = timetableAuthApi.deleteTimetableFrame(frameId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ interface TimetableRepository {
fun getSemesterCheck(): Flow<List<String>>
fun getLectures(semesterDate: String): Flow<List<Lecture>>
fun getTimetableFrames(semester: String): Flow<List<TimetableFrame>>
fun getAllFrames(): Flow<Map<String, List<TimetableFrame>>>


suspend fun getTimetableLectures(timetableFrameId: Int): Result<TimetableLectures>
suspend fun getTimetableLectures(semester: String): Result<TimetableLectures>
Expand All @@ -26,11 +28,11 @@ interface TimetableRepository {
suspend fun postTimetableCustomLectures(frameId: Int, lectures: List<Lecture>): Result<TimetableLectures>
suspend fun postTimetableBasicLectures(frameId: Int, lectures: List<TimetableLecture>): Result<TimetableLectures>
suspend fun postTimetableFrame(frame: TimetableFrameCreateQuery): Result<TimetableFrame>
suspend fun postRollbackFrame(frameId: Int): Result<TimetableLectures>

suspend fun deleteTimetableFrame(frameId: Int): Result<Unit>
suspend fun deleteTimetableLecture(id: Int): Result<Unit>
suspend fun deleteTimetableLectures(lectureIds: List<Int>): Result<Unit>
suspend fun deleteTimetableFrameLecture(frameId: Int, lectureId: Int): Result<Unit>

suspend fun deleteAllTimetableFrame(semester: String): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package `in`.koreatech.koin.domain.usecase.timetable

import `in`.koreatech.koin.domain.model.timetable.response.TimetableFrame
import `in`.koreatech.koin.domain.repository.TimetableRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetAllFramesUseCase @Inject constructor(
nodobi marked this conversation as resolved.
Show resolved Hide resolved
private val timetableRepository: TimetableRepository
) {
suspend operator fun invoke(): Flow<Map<String, List<TimetableFrame>>> =
timetableRepository.getAllFrames()
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package `in`.koreatech.koin.domain.usecase.timetable

import `in`.koreatech.koin.domain.model.timetable.response.TimetableLectures
import `in`.koreatech.koin.domain.repository.TimetableRepository
import javax.inject.Inject

/**
* 시간표 프레임과 담긴 강의들을 복구하는 유즈케이스
* 학기가 함께 삭제된 경우, 학기도 같이 추가한다
*/
class RollbackFrameUseCase @Inject constructor(
private val timetableRepository: TimetableRepository
) {

suspend operator fun invoke(frameId: Int): Result<TimetableLectures> {
return timetableRepository.postRollbackFrame(frameId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,28 @@ import java.time.LocalDate
fun EditSemesterDialogImpl(
years: List<Int>,
userSemesters: List<SemesterModel>,
isSelectYearDialogVisible: Boolean,
modifier: Modifier = Modifier,
onConfirmSelectYear: () -> Unit = {},
onDismissSelectYear: () -> Unit = {},
onClickSelectYear: () -> Unit = {},
onConfirm: (List<SemesterModel>) -> Unit = {},
onDismiss: () -> Unit = {},
) {
var currentYear by remember { mutableStateOf(LocalDate.now().year) }
var selectedSemesters by remember(currentYear, userSemesters) { mutableStateOf(listOf<SemesterType>()) }

var isShowingSelectYearDialog by remember { mutableStateOf(false) }

Box(
modifier = modifier
) {
if (isShowingSelectYearDialog) {
if (isSelectYearDialogVisible) {
SelectYearDialog(
currentYear = currentYear,
yearList = years,
onDismiss = { isShowingSelectYearDialog = false },
onDismiss = onDismissSelectYear,
onSelectYear = {
currentYear = it
isShowingSelectYearDialog = false
onConfirmSelectYear()
}
)
} else {
Expand All @@ -83,7 +85,7 @@ fun EditSemesterDialogImpl(
else
selectedSemesters = selectedSemesters + clickedSemester
},
onClickYear = { isShowingSelectYearDialog = true },
onClickYear = onClickSelectYear,
onConfirm = { onConfirm(selectedSemesters.map { SemesterModel(currentYear, it) }) },
onDismiss = onDismiss
)
Expand Down Expand Up @@ -280,6 +282,7 @@ private fun EditSemesterDialogImplPreview() {
EditSemesterDialogImpl(
years = listOf(2019, 2020, 2021, 2022, 2023, 2024),
userSemesters = userSemesters,
isSelectYearDialogVisible = false,
onConfirm = { selectedSemester ->
userSemesters = userSemesters.toMutableList().apply {
selectedSemester.forEach {
Expand Down
Loading