-
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.
Merge pull request #348 from BCSDLab/feature/dining-notice
[Feature] 학식당 운영시간 구현
- Loading branch information
Showing
51 changed files
with
904 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<size android:height="1dp" /> | ||
<solid android:color="@color/gray15" /> | ||
</shape> |
14 changes: 14 additions & 0 deletions
14
data/src/main/java/in/koreatech/koin/data/api/CoopShopApi.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,14 @@ | ||
package `in`.koreatech.koin.data.api | ||
|
||
import `in`.koreatech.koin.data.constant.URLConstant | ||
import `in`.koreatech.koin.data.response.coopshop.CoopShopResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Path | ||
|
||
interface CoopShopApi { | ||
@GET(URLConstant.COOPSHOP) | ||
suspend fun getCoopShopAll(): List<CoopShopResponse> | ||
|
||
@GET("${URLConstant.COOPSHOP}/{coopShopId}") | ||
suspend fun getCoopShopById(@Path("coopShopId") id: Int): CoopShopResponse | ||
} |
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
34 changes: 34 additions & 0 deletions
34
data/src/main/java/in/koreatech/koin/data/error/CoopShopErrorHandlerImpl.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,34 @@ | ||
package `in`.koreatech.koin.data.error | ||
|
||
import android.content.Context | ||
import retrofit2.HttpException | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import `in`.koreatech.koin.data.R | ||
import `in`.koreatech.koin.data.util.handleCommonError | ||
import `in`.koreatech.koin.data.util.unknownErrorHandler | ||
import `in`.koreatech.koin.data.util.withUnknown | ||
import `in`.koreatech.koin.domain.error.coopshop.CoopShopErrorHandler | ||
import `in`.koreatech.koin.domain.model.error.ErrorHandler | ||
import javax.inject.Inject | ||
|
||
class CoopShopErrorHandlerImpl @Inject constructor( | ||
@ApplicationContext private val context: Context | ||
): CoopShopErrorHandler { | ||
override fun handleGetCoopShopAllError(throwable: Throwable): ErrorHandler = | ||
throwable.handleCommonError(context) { | ||
unknownErrorHandler(context) | ||
} | ||
|
||
override fun handleGetCoopShopError(throwable: Throwable): ErrorHandler = | ||
throwable.handleCommonError(context) { | ||
when (it) { | ||
is HttpException -> { | ||
when (it.code()) { | ||
404 -> ErrorHandler(it.message()) | ||
else -> ErrorHandler(context.getString(R.string.error_network)) | ||
} | ||
} | ||
else -> ErrorHandler(context.getString(R.string.error_network_unknown)) | ||
}.withUnknown(context) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
data/src/main/java/in/koreatech/koin/data/mapper/CoopShopMapper.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,36 @@ | ||
package `in`.koreatech.koin.data.mapper | ||
|
||
import `in`.koreatech.koin.data.response.coopshop.CoopShopResponse | ||
import `in`.koreatech.koin.data.response.coopshop.OpenCloseInfoResponse | ||
import `in`.koreatech.koin.domain.model.coopshop.CoopShop | ||
import `in`.koreatech.koin.domain.model.coopshop.OpenCloseInfo | ||
import `in`.koreatech.koin.domain.model.coopshop.OpenCloseTimeInfo | ||
import `in`.koreatech.koin.domain.model.coopshop.checkIfNotOpen | ||
import `in`.koreatech.koin.domain.model.coopshop.toCoopShopDayType | ||
|
||
fun CoopShopResponse.toCoopShop(): CoopShop { | ||
return CoopShop( | ||
id = id, | ||
name = name, | ||
semester = semester, | ||
opens = opens.groupByDayOfWeek(), | ||
phone = phone.orEmpty(), | ||
location = location, | ||
remarks = remarks.orEmpty(), | ||
updatedAt = updatedAt | ||
) | ||
} | ||
|
||
fun List<OpenCloseInfoResponse>.groupByDayOfWeek(): List<OpenCloseInfo> = | ||
this.groupBy { it.dayOfWeek }.map { (day, infoList) -> | ||
OpenCloseInfo( | ||
dayOfWeek = day.toCoopShopDayType, | ||
opensByDayType = infoList.map { info -> | ||
OpenCloseTimeInfo( | ||
type = info.type.orEmpty(), | ||
openTime = info.openTime.orEmpty().checkIfNotOpen, | ||
closeTime = info.closeTime.orEmpty().checkIfNotOpen | ||
) | ||
} | ||
) | ||
} |
21 changes: 21 additions & 0 deletions
21
data/src/main/java/in/koreatech/koin/data/repository/CoopShopRepositoryImpl.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,21 @@ | ||
package `in`.koreatech.koin.data.repository | ||
|
||
import `in`.koreatech.koin.data.mapper.toCoopShop | ||
import `in`.koreatech.koin.data.response.coopshop.CoopShopResponse | ||
import `in`.koreatech.koin.data.source.remote.CoopShopRemoteDataSource | ||
import `in`.koreatech.koin.domain.model.coopshop.CoopShop | ||
import `in`.koreatech.koin.domain.repository.CoopShopRepository | ||
import javax.inject.Inject | ||
|
||
class CoopShopRepositoryImpl @Inject constructor( | ||
private val coopShopRemoteDataSource: CoopShopRemoteDataSource | ||
): CoopShopRepository { | ||
override suspend fun getCoopShopAll(): List<CoopShop> { | ||
return coopShopRemoteDataSource.getCoopShopAll().map(CoopShopResponse::toCoopShop) | ||
} | ||
|
||
override suspend fun getCoopShopById(id: Int): CoopShop { | ||
return coopShopRemoteDataSource.getCoopShopById(id).toCoopShop() | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
data/src/main/java/in/koreatech/koin/data/response/coopshop/CoopShopResponse.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,22 @@ | ||
package `in`.koreatech.koin.data.response.coopshop | ||
|
||
import com.google.gson.annotations.SerializedName | ||
import java.time.LocalDateTime | ||
|
||
data class CoopShopResponse( | ||
@SerializedName("id") val id: Int, | ||
@SerializedName("name") val name: String, | ||
@SerializedName("semester") val semester: String, | ||
@SerializedName("opens") val opens: List<OpenCloseInfoResponse>, | ||
@SerializedName("phone") val phone: String?, | ||
@SerializedName("location") val location: String, | ||
@SerializedName("remarks") val remarks: String?, | ||
@SerializedName("updated_at") val updatedAt: String | ||
) | ||
|
||
data class OpenCloseInfoResponse( | ||
@SerializedName("day_of_week") val dayOfWeek: String, | ||
@SerializedName("type") val type: String?, | ||
@SerializedName("open_time") val openTime: String?, | ||
@SerializedName("close_time") val closeTime: String?, | ||
) |
17 changes: 17 additions & 0 deletions
17
data/src/main/java/in/koreatech/koin/data/source/remote/CoopShopRemoteDataSource.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,17 @@ | ||
package `in`.koreatech.koin.data.source.remote | ||
|
||
import `in`.koreatech.koin.data.api.CoopShopApi | ||
import `in`.koreatech.koin.data.response.coopshop.CoopShopResponse | ||
import javax.inject.Inject | ||
|
||
class CoopShopRemoteDataSource @Inject constructor( | ||
private val coopShopApi: CoopShopApi | ||
) { | ||
suspend fun getCoopShopAll(): List<CoopShopResponse> { | ||
return coopShopApi.getCoopShopAll() | ||
} | ||
|
||
suspend fun getCoopShopById(id: Int): CoopShopResponse { | ||
return coopShopApi.getCoopShopById(id) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
domain/src/main/java/in/koreatech/koin/domain/error/coopshop/CoopShopErrorHandler.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,8 @@ | ||
package `in`.koreatech.koin.domain.error.coopshop | ||
|
||
import `in`.koreatech.koin.domain.model.error.ErrorHandler | ||
|
||
interface CoopShopErrorHandler { | ||
fun handleGetCoopShopAllError(throwable: Throwable) : ErrorHandler | ||
fun handleGetCoopShopError(throwable: Throwable) : ErrorHandler | ||
} |
12 changes: 12 additions & 0 deletions
12
domain/src/main/java/in/koreatech/koin/domain/model/coopshop/CoopShop.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 `in`.koreatech.koin.domain.model.coopshop | ||
|
||
data class CoopShop( | ||
val id: Int, | ||
val name: String, | ||
val semester: String, | ||
val opens: List<OpenCloseInfo>, | ||
val phone: String, | ||
val location: String, | ||
val remarks: String, | ||
val updatedAt: String | ||
) |
15 changes: 15 additions & 0 deletions
15
domain/src/main/java/in/koreatech/koin/domain/model/coopshop/CoopShopDayType.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,15 @@ | ||
package `in`.koreatech.koin.domain.model.coopshop | ||
|
||
enum class CoopShopDayType( | ||
val value: String | ||
) { | ||
Weekday("평일"), | ||
Weekend("주말") | ||
} | ||
|
||
val String.toCoopShopDayType | ||
get() = when (this) { | ||
"평일" -> CoopShopDayType.Weekday | ||
"주말" -> CoopShopDayType.Weekend | ||
else -> throw IllegalArgumentException("Invalid day type") | ||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/in/koreatech/koin/domain/model/coopshop/CoopShopType.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 `in`.koreatech.koin.domain.model.coopshop | ||
|
||
enum class CoopShopType( | ||
val id: Int | ||
) { | ||
Dining(1) | ||
} |
15 changes: 15 additions & 0 deletions
15
domain/src/main/java/in/koreatech/koin/domain/model/coopshop/OpenCloseInfo.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,15 @@ | ||
package `in`.koreatech.koin.domain.model.coopshop | ||
|
||
data class OpenCloseInfo( | ||
val dayOfWeek: CoopShopDayType, | ||
val opensByDayType: List<OpenCloseTimeInfo> | ||
) | ||
|
||
data class OpenCloseTimeInfo( | ||
val type: String, | ||
val openTime: String, | ||
val closeTime: String | ||
) | ||
|
||
val String.checkIfNotOpen get() = | ||
if (this == "휴점(예약)") "미운영" else this |
8 changes: 8 additions & 0 deletions
8
domain/src/main/java/in/koreatech/koin/domain/repository/CoopShopRepository.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,8 @@ | ||
package `in`.koreatech.koin.domain.repository | ||
|
||
import `in`.koreatech.koin.domain.model.coopshop.CoopShop | ||
|
||
interface CoopShopRepository { | ||
suspend fun getCoopShopAll(): List<CoopShop> | ||
suspend fun getCoopShopById(id: Int): CoopShop | ||
} |
20 changes: 20 additions & 0 deletions
20
domain/src/main/java/in/koreatech/koin/domain/usecase/coopshop/GetCoopShopAllUseCase.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,20 @@ | ||
package `in`.koreatech.koin.domain.usecase.coopshop | ||
|
||
import `in`.koreatech.koin.domain.error.coopshop.CoopShopErrorHandler | ||
import `in`.koreatech.koin.domain.model.coopshop.CoopShop | ||
import `in`.koreatech.koin.domain.model.error.ErrorHandler | ||
import `in`.koreatech.koin.domain.repository.CoopShopRepository | ||
import javax.inject.Inject | ||
|
||
class GetCoopShopAllUseCase @Inject constructor( | ||
private val coopShopRepository: CoopShopRepository, | ||
private val coopShopErrorHandler: CoopShopErrorHandler | ||
) { | ||
suspend operator fun invoke(): Pair<List<CoopShop>?, ErrorHandler?> { | ||
return try { | ||
coopShopRepository.getCoopShopAll() to null | ||
} catch (t: Throwable) { | ||
null to coopShopErrorHandler.handleGetCoopShopAllError(t) | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
domain/src/main/java/in/koreatech/koin/domain/usecase/coopshop/GetCoopShopUseCase.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,21 @@ | ||
package `in`.koreatech.koin.domain.usecase.coopshop | ||
|
||
import `in`.koreatech.koin.domain.error.coopshop.CoopShopErrorHandler | ||
import `in`.koreatech.koin.domain.model.coopshop.CoopShop | ||
import `in`.koreatech.koin.domain.model.coopshop.CoopShopType | ||
import `in`.koreatech.koin.domain.model.error.ErrorHandler | ||
import `in`.koreatech.koin.domain.repository.CoopShopRepository | ||
import javax.inject.Inject | ||
|
||
class GetCoopShopUseCase @Inject constructor( | ||
private val coopShopRepository: CoopShopRepository, | ||
private val coopShopErrorHandler: CoopShopErrorHandler | ||
) { | ||
suspend operator fun invoke(type: CoopShopType): Pair<CoopShop?, ErrorHandler?> { | ||
return try { | ||
coopShopRepository.getCoopShopById(type.id) to null | ||
} catch (t: Throwable) { | ||
null to coopShopErrorHandler.handleGetCoopShopError(t) | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -56,6 +56,7 @@ android { | |
} | ||
buildFeatures { | ||
dataBinding = true | ||
viewBinding = true | ||
} | ||
} | ||
|
||
|
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
Oops, something went wrong.