Skip to content

Commit

Permalink
[feat/#76] 출석 QR Text api usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnseo committed Feb 7, 2024
1 parent 63680ce commit 156575c
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature
android:name="android.hardware.camera"
android:required="false" />

<application
android:name=".KusitmsApp"
Expand Down Expand Up @@ -34,6 +37,9 @@
<meta-data
android:name="android.app.lib_name"
android:value="" />
<meta-data
android:name="com.google.mlkit.vision.DEPENDENCIES"
android:value="barcode" />
</activity>
</application>

Expand Down
16 changes: 16 additions & 0 deletions data/src/main/java/com/kusitms/data/remote/api/KusitmsApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,5 +209,21 @@ interface KusitmsApi {
@GET("v1/attend")
suspend fun getAttendScore(): BaseResponse<AttendPayload>

//출석 QR 조회
@GET("v1/attend/text/{curriculumId}")
suspend fun getQrText(
@Path("curriculumId") curriculumId: Int
):BaseResponse<AttendQrTextPayload>

//결석 처리
@POST("v1/attend/absent/{curriculumId}")
suspend fun postAbsent(
@Path("curriculumId") curriculumId: Int
): BaseResponse<Unit>

//출석 처리
@POST("v1/attend")
suspend fun attendCheck(
@Body attendCheckRequestBody: AttendCheckRequestBody
): BaseResponse<Unit>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kusitms.data.remote.entity.request

import com.kusitms.domain.model.home.AttendCheckModel

data class AttendCheckRequestBody(
val curriculumId: Int,
val text: String
)

fun AttendCheckModel.toBody() =
AttendCheckRequestBody(
curriculumId, text
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.kusitms.data.remote.entity.response.home

import com.kusitms.domain.model.home.AttendQRModel

data class AttendQrTextPayload(
val qrText: String
)

fun AttendQrTextPayload.toModel() =
AttendQRModel(
qrText = qrText
)

Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,19 @@ class HomeRepositoryImpl @Inject constructor(
Result.failure(e)
}
}

override suspend fun getAttendQrText(
curriculumId: Int
): Result<AttendQRModel> {
return try {
val response = kusitmsApi.getQrText(curriculumId)
if(response.result.code == 200) {
Result.success(response.payload.toModel())
} else {
Result.failure(RuntimeException("QR 코드 조회 실패: ${response.result.message}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.kusitms.domain.model.home

data class AttendCheckModel(
val curriculumId: Int,
val text :String
)

data class AttendQRModel(
val qrText: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ interface HomeRepository {
suspend fun getAttendCurrentList(): Result<List<AttendCurrentModel>>
suspend fun getAttendInfo(): Result<AttendInfoModel>
suspend fun getAttendScore(): Result<AttendModel>
suspend fun getAttendQrText(
curriculumId: Int
): Result<AttendQRModel>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.kusitms.domain.usecase.home

import com.kusitms.domain.model.home.AttendQRModel
import com.kusitms.domain.repository.HomeRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class GetAttendQrUseCase @Inject constructor(
private val homeRepository: HomeRepository
) {
operator fun invoke(
curriculumId: Int
): Flow<AttendQRModel> = flow {
homeRepository.getAttendQrText(
curriculumId = curriculumId
).onSuccess {
return@flow emit(it)
}.onFailure {
throw it
}
}
}

0 comments on commit 156575c

Please sign in to comment.