-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 수원대 포털 연동 API 3종 및 에러 매핑 레이어 추가 #83
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.chukchukhaksa.mobile.data.portal.datasource | ||
|
|
||
| import com.chukchukhaksa.mobile.remote.portal.model.AcceptedResponseDto | ||
| import com.chukchukhaksa.mobile.remote.portal.model.JobStatusResponseDto | ||
| import com.chukchukhaksa.mobile.remote.portal.model.JobSummaryResponseDto | ||
|
|
||
| interface PortalRemoteDataSource { | ||
| suspend fun createLinkJob( | ||
| portalType: String, | ||
| username: String, | ||
| password: String, | ||
| idempotencyKey: String, | ||
| ): AcceptedResponseDto | ||
|
|
||
| suspend fun getJobStatus(jobId: String): JobStatusResponseDto | ||
|
|
||
| suspend fun getJobSummary(jobId: String): JobSummaryResponseDto | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.chukchukhaksa.mobile.data.portal.di | ||
|
|
||
| import com.chukchukhaksa.mobile.data.portal.datasource.PortalRemoteDataSource | ||
| import com.chukchukhaksa.mobile.data.portal.repository.PortalRepositoryImpl | ||
| import com.chukchukhaksa.mobile.domain.portal.repository.PortalRepository | ||
| import com.chukchukhaksa.mobile.remote.portal.PortalRemoteDataSourceImpl | ||
| import org.koin.dsl.module | ||
|
|
||
| val portalRepositoryModule = module { | ||
| single<PortalRemoteDataSource> { PortalRemoteDataSourceImpl(get()) } | ||
| single<PortalRepository> { PortalRepositoryImpl(get()) } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,124 @@ | ||||||||||||||||||||||||||||
| package com.chukchukhaksa.mobile.data.portal.repository | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.data.portal.datasource.PortalRemoteDataSource | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.domain.portal.model.PortalScrapingError | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.domain.portal.model.PortalScrapingException | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.domain.portal.model.ScrapingProgress | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.domain.portal.model.ScrapingResult | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.domain.portal.model.StudentInfo | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.domain.portal.repository.PortalRepository | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.remote.portal.mapToPortalScrapingError | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.remote.portal.model.JobStatusResponseDto | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.remote.portal.model.JobSummaryResponseDto | ||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.remote.portal.model.StudentInfoDto | ||||||||||||||||||||||||||||
| import kotlinx.coroutines.delay | ||||||||||||||||||||||||||||
| import kotlinx.coroutines.flow.Flow | ||||||||||||||||||||||||||||
| import kotlinx.coroutines.flow.flow | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class PortalRepositoryImpl( | ||||||||||||||||||||||||||||
| private val portalRemoteDataSource: PortalRemoteDataSource, | ||||||||||||||||||||||||||||
| ) : PortalRepository { | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| override fun linkPortal( | ||||||||||||||||||||||||||||
| portalType: String, | ||||||||||||||||||||||||||||
| username: String, | ||||||||||||||||||||||||||||
| password: String, | ||||||||||||||||||||||||||||
| idempotencyKey: String, | ||||||||||||||||||||||||||||
| ): Flow<ScrapingProgress> = flow { | ||||||||||||||||||||||||||||
| val accepted = portalRemoteDataSource.createLinkJob( | ||||||||||||||||||||||||||||
| portalType = portalType, | ||||||||||||||||||||||||||||
| username = username, | ||||||||||||||||||||||||||||
| password = password, | ||||||||||||||||||||||||||||
| idempotencyKey = idempotencyKey, | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| val jobId = accepted.jobId ?: throw PortalScrapingException( | ||||||||||||||||||||||||||||
| error = PortalScrapingError.Unknown(httpStatus = null, appCode = null), | ||||||||||||||||||||||||||||
| httpStatus = null, | ||||||||||||||||||||||||||||
| appCode = null, | ||||||||||||||||||||||||||||
| retryable = null, | ||||||||||||||||||||||||||||
| message = "포털 연동 job id가 비어있습니다.", | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| emit(ScrapingProgress.Accepted(jobId = jobId)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| repeat(MAX_POLL_COUNT) { | ||||||||||||||||||||||||||||
| delay(POLL_INTERVAL_MS) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| val statusDto = portalRemoteDataSource.getJobStatus(jobId) | ||||||||||||||||||||||||||||
| val jobStatus = statusDto.status.orEmpty() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| when { | ||||||||||||||||||||||||||||
| jobStatus.isTerminalSuccess() -> { | ||||||||||||||||||||||||||||
| val summary = portalRemoteDataSource.getJobSummary(jobId) | ||||||||||||||||||||||||||||
| emit( | ||||||||||||||||||||||||||||
| ScrapingProgress.Completed( | ||||||||||||||||||||||||||||
| jobId = jobId, | ||||||||||||||||||||||||||||
| result = summary.toDomain(), | ||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| return@flow | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| jobStatus.isTerminalFailure() -> { | ||||||||||||||||||||||||||||
| throw statusDto.toException() | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| else -> emit( | ||||||||||||||||||||||||||||
| ScrapingProgress.InProgress( | ||||||||||||||||||||||||||||
| jobId = jobId, | ||||||||||||||||||||||||||||
| status = jobStatus, | ||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| throw PortalScrapingException( | ||||||||||||||||||||||||||||
| error = PortalScrapingError.Unknown(httpStatus = null, appCode = TIMEOUT_APP_CODE), | ||||||||||||||||||||||||||||
| httpStatus = null, | ||||||||||||||||||||||||||||
| appCode = TIMEOUT_APP_CODE, | ||||||||||||||||||||||||||||
| retryable = null, | ||||||||||||||||||||||||||||
| message = "포털 연동이 시간 내에 완료되지 않았습니다.", | ||||||||||||||||||||||||||||
|
Comment on lines
+75
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 타임아웃 예외에 Line 79에서 🔧 제안 수정안 throw PortalScrapingException(
error = PortalScrapingError.Unknown(httpStatus = null, appCode = TIMEOUT_APP_CODE),
httpStatus = null,
appCode = TIMEOUT_APP_CODE,
- retryable = null,
+ retryable = true,
message = "포털 연동이 시간 내에 완료되지 않았습니다.",
)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| companion object { | ||||||||||||||||||||||||||||
| private const val POLL_INTERVAL_MS = 2_000L | ||||||||||||||||||||||||||||
| private const val MAX_POLL_COUNT = 60 | ||||||||||||||||||||||||||||
| private const val TIMEOUT_APP_CODE = "PORTAL_POLL_TIMEOUT" | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| private fun String.isTerminalSuccess(): Boolean = | ||||||||||||||||||||||||||||
| equals("succeeded", ignoreCase = true) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| private fun String.isTerminalFailure(): Boolean = | ||||||||||||||||||||||||||||
| equals("failed", ignoreCase = true) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| private fun JobStatusResponseDto.toException(): PortalScrapingException { | ||||||||||||||||||||||||||||
| val appCode = errorCode | ||||||||||||||||||||||||||||
| val error = mapToPortalScrapingError(httpStatus = null, appCode = appCode) | ||||||||||||||||||||||||||||
| return PortalScrapingException( | ||||||||||||||||||||||||||||
| error = error, | ||||||||||||||||||||||||||||
| httpStatus = null, | ||||||||||||||||||||||||||||
| appCode = appCode, | ||||||||||||||||||||||||||||
| retryable = retryable, | ||||||||||||||||||||||||||||
| message = errorMessage ?: error.defaultMessage, | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| private fun JobSummaryResponseDto.toDomain(): ScrapingResult = ScrapingResult( | ||||||||||||||||||||||||||||
| jobId = jobId, | ||||||||||||||||||||||||||||
| studentInfo = studentInfo?.toDomain(), | ||||||||||||||||||||||||||||
| status = status, | ||||||||||||||||||||||||||||
| finishedAt = finishedAt, | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| private fun StudentInfoDto.toDomain(): StudentInfo = StudentInfo( | ||||||||||||||||||||||||||||
| name = name, | ||||||||||||||||||||||||||||
| school = school, | ||||||||||||||||||||||||||||
| majorName = majorName, | ||||||||||||||||||||||||||||
| studentCode = studentCode, | ||||||||||||||||||||||||||||
| gradeLevel = gradeLevel, | ||||||||||||||||||||||||||||
| status = status, | ||||||||||||||||||||||||||||
| completedSemesterType = completedSemesterType, | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.chukchukhaksa.mobile.domain.portal.model | ||
|
|
||
| sealed class PortalScrapingError(val defaultMessage: String) { | ||
|
|
||
| data object InvalidCredentials : PortalScrapingError( | ||
| "아이디나 비밀번호가 일치하지 않습니다.\n학교 홈페이지에서 확인해주세요.", | ||
| ) | ||
|
|
||
| data object AccountLocked : PortalScrapingError( | ||
| "계정이 잠겼습니다. 포털사이트에서 비밀번호 재설정을 진행해주세요.", | ||
| ) | ||
|
|
||
| data object InvalidAcademicRecord : PortalScrapingError( | ||
| "입력하신 학적 정보로는 현재 처리가 불가능합니다.\n세부 사유를 확인해주세요.", | ||
| ) | ||
|
|
||
| data object AlreadyConnected : PortalScrapingError( | ||
| "이미 포털 연동된 학생 정보가 존재합니다.\n다른 계정으로 로그인했는지 확인해주세요.", | ||
| ) | ||
|
|
||
| data object GraduationDataNotFound : PortalScrapingError( | ||
| "사용자에게 맞는 졸업 요건 데이터가 존재하지 않습니다.\n학과/입학년도 정보를 확인해주세요.", | ||
| ) | ||
|
|
||
| data object DoubleMajorInfoMissing : PortalScrapingError( | ||
| "복수전공 이수 구분 정보가 존재하지 않아 처리할 수 없습니다.\n학사정보를 확인해주세요.", | ||
| ) | ||
|
|
||
| data object TransferStudentNotSupported : PortalScrapingError( | ||
| "편입생 학적 정보는 현재 지원되지 않습니다.\n추후 지원 예정입니다.", | ||
| ) | ||
|
|
||
| data class Unknown( | ||
| val httpStatus: Int?, | ||
| val appCode: String?, | ||
| ) : PortalScrapingError( | ||
| "알 수 없는 오류가 발생했어요.\n잠시 후 다시 시도해주세요.", | ||
| ) | ||
|
Comment on lines
+3
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 도메인 계층에 사용자 문구를 고정하지 않는 편이 좋습니다.
🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.chukchukhaksa.mobile.domain.portal.model | ||
|
|
||
| class PortalScrapingException( | ||
| val error: PortalScrapingError, | ||
| val httpStatus: Int?, | ||
| val appCode: String?, | ||
| val retryable: Boolean? = null, | ||
| override val message: String = error.defaultMessage, | ||
| ) : RuntimeException(message) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.chukchukhaksa.mobile.domain.portal.model | ||
|
|
||
| sealed interface ScrapingProgress { | ||
| val jobId: String | ||
|
|
||
| data class Accepted( | ||
| override val jobId: String, | ||
| ) : ScrapingProgress | ||
|
|
||
| data class InProgress( | ||
| override val jobId: String, | ||
| val status: String, | ||
| ) : ScrapingProgress | ||
|
|
||
| data class Completed( | ||
| override val jobId: String, | ||
| val result: ScrapingResult, | ||
| ) : ScrapingProgress | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.chukchukhaksa.mobile.domain.portal.model | ||
|
|
||
| data class ScrapingResult( | ||
| val jobId: String?, | ||
| val studentInfo: StudentInfo?, | ||
| val status: String?, | ||
| val finishedAt: String?, | ||
| ) | ||
|
|
||
| data class StudentInfo( | ||
| val name: String?, | ||
| val school: String?, | ||
| val majorName: String?, | ||
| val studentCode: String?, | ||
| val gradeLevel: Int?, | ||
| val status: String?, | ||
| val completedSemesterType: Int?, | ||
| ) | ||
|
Comment on lines
+3
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
Line 6, Line 15의 🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.chukchukhaksa.mobile.domain.portal.repository | ||
|
|
||
| import com.chukchukhaksa.mobile.domain.portal.model.ScrapingProgress | ||
| import kotlinx.coroutines.flow.Flow | ||
|
|
||
| interface PortalRepository { | ||
| fun linkPortal( | ||
| portalType: String, | ||
| username: String, | ||
| password: String, | ||
| idempotencyKey: String, | ||
| ): Flow<ScrapingProgress> | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,28 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| package com.chukchukhaksa.mobile.domain.portal.usecase | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.domain.portal.model.ScrapingProgress | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.chukchukhaksa.mobile.domain.portal.repository.PortalRepository | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import kotlinx.coroutines.flow.Flow | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import kotlin.uuid.ExperimentalUuidApi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| import kotlin.uuid.Uuid | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| class LinkPortalUseCase( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| private val portalRepository: PortalRepository, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| @OptIn(ExperimentalUuidApi::class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| operator fun invoke( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| username: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| password: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| portalType: String = DEFAULT_PORTAL_TYPE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| idempotencyKey: String = Uuid.random().toString(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): Flow<ScrapingProgress> = portalRepository.linkPortal( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| portalType = portalType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| username = username, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| password = password, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| idempotencyKey = idempotencyKey, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UseCase 시그니처와 에러 처리 패턴을 가이드라인에 맞춰 주세요. 현재 🔧 제안 변경안- `@OptIn`(ExperimentalUuidApi::class)
- operator fun invoke(
+ `@OptIn`(ExperimentalUuidApi::class)
+ suspend operator fun invoke(
username: String,
password: String,
portalType: String = DEFAULT_PORTAL_TYPE,
idempotencyKey: String = Uuid.random().toString(),
- ): Flow<ScrapingProgress> = portalRepository.linkPortal(
- portalType = portalType,
- username = username,
- password = password,
- idempotencyKey = idempotencyKey,
- )
+ ): Result<Flow<ScrapingProgress>> = runCatchingIgnoreCancelled {
+ portalRepository.linkPortal(
+ portalType = portalType,
+ username = username,
+ password = password,
+ idempotencyKey = idempotencyKey,
+ )
+ }As per coding guidelines: Use cases must use suspend operator fun invoke() that returns Result; Use runCatchingIgnoreCancelled for error handling in use cases 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| companion object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| const val DEFAULT_PORTAL_TYPE = "suwon" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
🧩 Analysis chain
🏁 Script executed:
Repository: cchaksa/cchaksa-app
Length of output: 1790
참조 저장소를 프로젝트 외부에 복제하는 것을 권장합니다.
.gitignore에/chukchuk-haksa/디렉토리를 추가하는 것은 문법적으로 올바르지만, 참조용 저장소를 현재 프로젝트의 작업 디렉토리 내부에 복제하는 것은 권장되지 않습니다.더 나은 접근 방법:
../chukchuk-haksa/)에 복제하여 작업 공간을 깨끗하게 유지🤖 Prompt for AI Agents