Skip to content

Commit 154515b

Browse files
committed
refactor :: dev repository result 객체로 반환
1 parent 6c91e8c commit 154515b

13 files changed

Lines changed: 103 additions & 95 deletions

File tree

data/src/dev/kotlin/team.aliens.dms.android.data/auth/repository/AuthRepository.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ abstract class AuthRepository {
1010
password: String,
1111
deviceToken: String,
1212
autoSignIn: Boolean = true,
13-
)
13+
): Result<Unit>
1414

1515
abstract suspend fun sendEmailVerificationCode(
1616
email: String,
1717
type: EmailVerificationType,
18-
)
18+
): Result<Unit>
1919

2020
abstract suspend fun checkEmailVerificationCode(
2121
email: String,
2222
code: String,
2323
type: EmailVerificationType,
24-
)
24+
): Result<Unit>
2525

26-
abstract suspend fun checkIdExists(accountId: String): HashedEmail
26+
abstract suspend fun checkIdExists(accountId: String): Result<HashedEmail>
2727

28-
abstract suspend fun signOut()
28+
abstract suspend fun signOut(): Result<Unit>
2929
}

data/src/dev/kotlin/team.aliens.dms.android.data/auth/repository/AuthRepositoryImpl.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ internal class AuthRepositoryImpl @Inject constructor(
2626
password: String,
2727
deviceToken: String,
2828
autoSignIn: Boolean,
29-
) {
29+
): Result<Unit> = runCatching {
3030
val signInResponse = statusMapping(
3131
onBadRequest = { throw BadRequestException() },
3232
onUnauthorized = { throw PasswordMismatchException() },
@@ -53,7 +53,7 @@ internal class AuthRepositoryImpl @Inject constructor(
5353
override suspend fun sendEmailVerificationCode(
5454
email: String,
5555
type: EmailVerificationType,
56-
) {
56+
): Result<Unit> = runCatching {
5757
networkAuthDataSource.sendEmailVerificationCode(
5858
request = SendEmailVerificationCodeRequest(
5959
email = email,
@@ -66,20 +66,22 @@ internal class AuthRepositoryImpl @Inject constructor(
6666
email: String,
6767
code: String,
6868
type: EmailVerificationType,
69-
) {
69+
): Result<Unit> = runCatching {
7070
networkAuthDataSource.checkEmailVerificationCode(
7171
email = email,
7272
code = code,
7373
type = type.name,
7474
)
7575
}
7676

77-
override suspend fun checkIdExists(accountId: String): HashedEmail =
77+
override suspend fun checkIdExists(accountId: String): Result<HashedEmail> = runCatching {
7878
networkAuthDataSource.checkIdExists(
7979
accountId = accountId,
8080
).email
81+
}
82+
8183

82-
override suspend fun signOut() {
84+
override suspend fun signOut(): Result<Unit> = runCatching {
8385
jwtProvider.clearCaches()
8486
schoolProvider.clearCaches()
8587
}

data/src/dev/kotlin/team.aliens.dms.android.data/meal/repository/MealRepository.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import team.aliens.dms.android.data.meal.model.Meal
55

66
abstract class MealRepository {
77

8-
abstract suspend fun fetchMeal(date: LocalDate): Meal
8+
abstract suspend fun fetchMeal(date: LocalDate): Result<Meal>
99

10-
abstract suspend fun updateMeal(date: LocalDate): Meal
10+
abstract suspend fun updateMeal(date: LocalDate): Result<Meal>
1111
}

data/src/dev/kotlin/team.aliens.dms.android.data/meal/repository/MealRepositoryImpl.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,15 @@ internal class MealRepositoryImpl @Inject constructor(
1313
private val databaseMealDataSource: DatabaseMealDataSource,
1414
private val networkMealDataSource: NetworkMealDataSource,
1515
) : MealRepository() {
16-
override suspend fun fetchMeal(date: LocalDate): Meal = try {
16+
override suspend fun fetchMeal(date: LocalDate): Result<Meal> = runCatching {
1717
databaseMealDataSource.queryMeal(date).toModel()
18-
} catch (_: Exception) {
19-
try {
20-
this.updateMeal(date = date)
21-
} catch (_: Exception) {
22-
throw CannotFindMealException()
23-
}
18+
}.recoverCatching {
19+
updateMeal(date = date).getOrElse { throw CannotFindMealException() }
2420
}
2521

26-
override suspend fun updateMeal(date: LocalDate): Meal {
27-
return networkMealDataSource.fetchMeals(date).toModel().also { meals ->
22+
override suspend fun updateMeal(date: LocalDate): Result<Meal> = runCatching {
23+
networkMealDataSource.fetchMeals(date).toModel().also { meals ->
2824
databaseMealDataSource.saveMeals(meals.toEntity())
29-
}
30-
.find { it.date == date }!!
25+
}.find { it.date == date }!!
3126
}
3227
}

data/src/dev/kotlin/team.aliens.dms.android.data/notification/repository/NotificationRepository.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@ import team.aliens.dms.android.data.notification.model.NotificationTopicGroup
77
abstract class NotificationRepository {
88

99
// TODO core 이전 고민
10-
abstract suspend fun registerDeviceNotificationToken(deviceToken: String)
10+
abstract suspend fun registerDeviceNotificationToken(deviceToken: String): Result<Unit>
1111

1212
// TODO core 이전 고민
13-
abstract suspend fun cancelDeviceTokenRegistration(deviceToken: String)
13+
abstract suspend fun cancelDeviceTokenRegistration(deviceToken: String): Result<Unit>
1414

1515
// TODO device token 파라미터 고민
1616
abstract suspend fun subscribeNotificationTopic(
1717
deviceToken: String,
1818
topic: NotificationTopic,
19-
)
19+
): Result<Unit>
2020

2121
// TODO device token 파라미터 고민
2222
abstract suspend fun unsubscribeNotificationTopic(
2323
deviceToken: String,
2424
topic: NotificationTopic,
25-
)
25+
): Result<Unit>
2626

27-
abstract suspend fun batchUpdateNotificationTopic(subscriptions: List<NotificationTopic.Subscription>)
27+
abstract suspend fun batchUpdateNotificationTopic(subscriptions: List<NotificationTopic.Subscription>): Result<Unit>
2828

2929
// TODO device token 파라미터 고민
30-
abstract suspend fun fetchNotificationStatus(deviceToken: String): List<NotificationTopicGroup.Status>
30+
abstract suspend fun fetchNotificationStatus(deviceToken: String): Result<List<NotificationTopicGroup.Status>>
3131

32-
abstract suspend fun fetchNotifications(): List<Notification>
32+
abstract suspend fun fetchNotifications(): Result<List<Notification>>
3333

34-
abstract suspend fun saveDeviceToken(deviceToken: String)
34+
abstract suspend fun saveDeviceToken(deviceToken: String): Result<Unit>
3535

36-
abstract suspend fun getDeviceToken(): String
36+
abstract suspend fun getDeviceToken(): Result<String>
3737
}

data/src/dev/kotlin/team.aliens.dms.android.data/notification/repository/NotificationRepositoryImpl.kt

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,62 @@ internal class NotificationRepositoryImpl @Inject constructor(
1616
private val deviceDataStoreDataSource: DeviceDataStoreDataSource,
1717
) : NotificationRepository() {
1818

19-
override suspend fun registerDeviceNotificationToken(deviceToken: String) {
19+
override suspend fun registerDeviceNotificationToken(deviceToken: String): Result<Unit> = runCatching {
2020
TODO("Not yet implemented")
2121
}
2222

23-
override suspend fun cancelDeviceTokenRegistration(deviceToken: String) {
23+
override suspend fun cancelDeviceTokenRegistration(deviceToken: String): Result<Unit> = runCatching {
2424
TODO("Not yet implemented")
2525
}
2626

2727
override suspend fun subscribeNotificationTopic(
2828
deviceToken: String,
2929
topic: NotificationTopic,
30-
) = networkNotificationDataSource.subscribeNotificationTopic(
31-
request = SubscribeNotificationTopicRequest(
32-
deviceToken = deviceToken,
33-
topic = topic.name,
34-
),
35-
)
30+
): Result<Unit> = runCatching {
31+
networkNotificationDataSource.subscribeNotificationTopic(
32+
request = SubscribeNotificationTopicRequest(
33+
deviceToken = deviceToken,
34+
topic = topic.name,
35+
),
36+
)
37+
}
3638

3739
override suspend fun unsubscribeNotificationTopic(
3840
deviceToken: String,
3941
topic: NotificationTopic,
40-
) = networkNotificationDataSource.unsubscribeNotificationTopic(
41-
request = UnsubscribeNotificationTopicRequest(
42-
deviceToken = deviceToken,
43-
topic = topic.name,
44-
),
45-
)
42+
): Result<Unit> = runCatching {
43+
networkNotificationDataSource.unsubscribeNotificationTopic(
44+
request = UnsubscribeNotificationTopicRequest(
45+
deviceToken = deviceToken,
46+
topic = topic.name,
47+
),
48+
)
49+
}
4650

4751
override suspend fun batchUpdateNotificationTopic(
4852
subscriptions: List<NotificationTopic.Subscription>,
49-
) = networkNotificationDataSource.batchUpdateNotificationTopic(
50-
request = BatchUpdateNotificationTopicRequest(
51-
topics = subscriptions.toModel(),
52-
),
53-
)
53+
): Result<Unit> = runCatching {
54+
networkNotificationDataSource.batchUpdateNotificationTopic(
55+
request = BatchUpdateNotificationTopicRequest(
56+
topics = subscriptions.toModel(),
57+
),
58+
)
59+
}
5460

55-
override suspend fun fetchNotificationStatus(deviceToken: String): List<NotificationTopicGroup.Status> =
61+
override suspend fun fetchNotificationStatus(deviceToken: String): Result<List<NotificationTopicGroup.Status>> = runCatching {
5662
networkNotificationDataSource.fetchNotificationTopicStatus(deviceToken = deviceToken)
5763
.toModel()
64+
}
5865

59-
override suspend fun fetchNotifications(): List<Notification> =
66+
override suspend fun fetchNotifications(): Result<List<Notification>> = runCatching {
6067
networkNotificationDataSource.fetchNotifications().toModel()
68+
}
6169

62-
override suspend fun saveDeviceToken(deviceToken: String) {
70+
override suspend fun saveDeviceToken(deviceToken: String): Result<Unit> = runCatching {
6371
deviceDataStoreDataSource.storeDeviceToken(deviceToken)
6472
}
6573

66-
override suspend fun getDeviceToken(): String =
74+
override suspend fun getDeviceToken(): Result<String> = runCatching {
6775
deviceDataStoreDataSource.loadDeviceToken()
76+
}
6877
}

data/src/dev/kotlin/team.aliens.dms.android.data/point/repository/PointRepository.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ abstract class PointRepository {
99
type: PointType,
1010
page: Long? = null,
1111
size: Long? = null,
12-
): PointStatus
12+
): Result<PointStatus>
1313
}

data/src/dev/kotlin/team.aliens.dms.android.data/point/repository/PointRepositoryImpl.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ internal class PointRepositoryImpl @Inject constructor(
1313
type: PointType,
1414
page: Long?,
1515
size: Long?,
16-
): PointStatus = networkPointDataSource.fetchPoints(
17-
type = type.name,
18-
page = page,
19-
size = size,
20-
).toModel()
16+
): Result<PointStatus> = runCatching {
17+
networkPointDataSource.fetchPoints(
18+
type = type.name,
19+
page = page,
20+
size = size,
21+
).toModel()
22+
}
2123
}

data/src/dev/kotlin/team.aliens.dms.android.data/student/repository/StudentRepository.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,40 @@ abstract class StudentRepository {
1919
accountId: String,
2020
password: String,
2121
profileImageUrl: String?,
22-
)
22+
): Result<Unit>
2323

2424
abstract suspend fun examineStudentNumber(
2525
schoolId: UUID,
2626
grade: Int,
2727
classroom: Int,
2828
number: Int,
29-
): StudentName
29+
): Result<StudentName>
3030

3131
abstract suspend fun findId(
3232
schoolId: UUID,
3333
studentName: String,
3434
grade: Int,
3535
classRoom: Int,
3636
number: Int,
37-
): HashedEmail
37+
): Result<HashedEmail>
3838

3939
abstract suspend fun resetPassword(
4040
accountId: String,
4141
studentName: String,
4242
email: String,
4343
emailVerificationCode: String,
4444
newPassword: String,
45-
)
45+
): Result<Unit>
4646

47-
abstract suspend fun checkIdDuplication(id: String)
47+
abstract suspend fun checkIdDuplication(id: String): Result<Unit>
4848

49-
abstract suspend fun checkEmailDuplication(email: String)
49+
abstract suspend fun checkEmailDuplication(email: String): Result<Unit>
5050

51-
abstract suspend fun fetchMyPage(): MyPage
51+
abstract suspend fun fetchMyPage(): Result<MyPage>
5252

53-
abstract suspend fun editProfile(profileImageUrl: String)
53+
abstract suspend fun editProfile(profileImageUrl: String): Result<Unit>
5454

55-
abstract suspend fun withdraw()
55+
abstract suspend fun withdraw(): Result<Unit>
5656

57-
abstract suspend fun fetchStudents(): List<Student>
57+
abstract suspend fun fetchStudents(): Result<List<Student>>
5858
}

0 commit comments

Comments
 (0)