Skip to content

Commit 807cdd6

Browse files
authored
API 직렬화 라이브러리를 Kotlin Serialization으로 통합 (#729)
* refactor: AcademicEvent API 수정 - DefaultResponse를 적용 * refactor: Department API 수정 - DefaultResponse를 적용 - Gson에서 Kotlin Serialization으로 마이그레이션 * refactor: Notice API 수정 - DefaultResponse를 적용 - Gson에서 Kotlin Serialization으로 마이그레이션 * refactor: User API 수정 - DefaultResponse 타입을 Nothing에서 Unit으로 변경 - Gson에서 Kotlin Serialization으로 마이그레이션 * refactor: NoticeComment API 수정 - DefaultResponse 타입을 Nothing에서 Unit으로 변경 * refactor: Report API 수정 - DefaultResponse 타입을 Nothing에서 Unit으로 변경 * refactor: Staff API 수정 - DefaultResponse를 적용 - Gson에서 Kotlin Serialization으로 마이그레이션 * refactor: Verification API 수정 - DefaultResponse 타입을 Nothing에서 Unit으로 변경 - Gson에서 Kotlin Serialization으로 마이그레이션 * refactor: Library API 수정 - Gson에서 Kotlin Serialization으로 마이그레이션 * refactor: AppVersion API 수정 - Gson에서 Kotlin Serialization으로 마이그레이션 * refactor: Gson 제거 및 NetworkModule 리팩토링 * refactor: Retrofit에 Qualifier 적용 * chore: 테스트 json 파일 수정 * chore: 잔여 Gson 코드를 정리 * fix: 테스트코드 수정 * fix: 리뷰 반영 * chore: 응답 클래스 필드에 SerialName 추가 * test: API 테스트 코드 추가 - 동아리 목록 및 동아리 정보 - 학과 목록 - 깃허브에 저장된 앱 최소 스펙 - 교수 목록 - 로그인 응답 * fix: 검색 응답 필드에 방어값 추가
1 parent 7cad12a commit 807cdd6

92 files changed

Lines changed: 1002 additions & 587 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build-logic/src/main/kotlin/com/ku_stacks/ku_ring/buildlogic/primitive/RetrofitPlugin.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class RetrofitPlugin: Plugin<Project> {
1313
dependencies {
1414
implementationPlatform(libs.library("retrofit-bom"))
1515
implementation(libs.library("retrofit"))
16-
implementation(libs.library("retrofit-converter-gson"))
1716
implementation(libs.library("retrofit-converter-kotlinx-serialization"))
1817
}
1918
}

data/academicevent/src/main/java/com/ku_stacks/ku_ring/academicevent/repository/AcademicEventRepositoryImpl.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class AcademicEventRepositoryImpl @Inject constructor(
2626
endDate: String?,
2727
): Result<Unit> = suspendRunCatching {
2828
val response = academicEventClient.fetchAcademicEvents(startDate, endDate)
29-
val eventEntities = response.data.toEntity()
30-
insertAcademicEventsIntoDB(eventEntities)
29+
if (response.isSuccessAndDataExists) {
30+
insertAcademicEventsIntoDB(response.data!!.toEntity())
31+
}
3132
}
3233

3334
private suspend fun insertAcademicEventsIntoDB(eventEntities: List<AcademicEventEntity>) =

data/academicevent/src/test/java/com/ku_stacks/ku_ring/academicevent/AcademicEventTestUtil.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.ku_stacks.ku_ring.academicevent
22

3-
import com.ku_stacks.ku_ring.remote.academicevent.response.AcademicEventListResponse
43
import com.ku_stacks.ku_ring.remote.academicevent.response.AcademicEventResponse
4+
import com.ku_stacks.ku_ring.remote.util.DefaultResponse
55

66
object AcademicEventTestUtil {
7-
fun mockAcademicEventListResponse() = AcademicEventListResponse(
8-
code = 200,
9-
message = "조회되었습니다.",
7+
fun mockAcademicEventListResponse() = DefaultResponse(
8+
resultCode = 200,
9+
resultMsg = "조회되었습니다.",
1010
data = listOf(
1111
AcademicEventResponse(
1212
id = 2417,

data/academicevent/src/test/java/com/ku_stacks/ku_ring/academicevent/AcademicRepositoryTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class AcademicRepositoryTest {
6060
fun `insert and get academic event test`() = runTest {
6161
//given
6262
val response = AcademicEventTestUtil.mockAcademicEventListResponse()
63-
val entities = response.data.map { it.toEntity() }
63+
val entities = requireNotNull(response.data?.map { it.toEntity() })
6464
academicEventDao.insertAcademicEvents(entities)
6565

6666
//when

data/department/src/test/java/com/ku_stacks/ku_ring/department/repository/DepartmentRepositoryTest.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import com.ku_stacks.ku_ring.local.room.DepartmentDao
99
import com.ku_stacks.ku_ring.local.room.KuRingDatabase
1010
import com.ku_stacks.ku_ring.preferences.PreferenceUtil
1111
import com.ku_stacks.ku_ring.remote.department.DepartmentClient
12-
import com.ku_stacks.ku_ring.remote.department.response.DepartmentListResponse
1312
import com.ku_stacks.ku_ring.remote.department.response.DepartmentResponse
13+
import com.ku_stacks.ku_ring.remote.util.DefaultResponse
1414
import junit.framework.Assert
1515
import kotlinx.coroutines.Dispatchers
1616
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -94,7 +94,13 @@ class DepartmentRepositoryTest {
9494
)
9595
}
9696
Mockito.`when`(departmentClient.fetchDepartmentList())
97-
.thenReturn(DepartmentListResponse(200, "success", updatedDepartmentsResponse))
97+
.thenReturn(
98+
DefaultResponse(
99+
200,
100+
"success",
101+
updatedDepartmentsResponse
102+
)
103+
)
98104
departmentRepository.updateDepartmentsFromRemote()
99105

100106
// then

data/library/src/test/java/com/ku_stacks/ku_ring/library/LibraryTestUtil.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ object LibraryTestUtil {
2424
roomName = "열람실",
2525
sortOrder = 1
2626
),
27-
awaitable = true,
2827
isChargeable = true,
2928
branch = LibraryRoomBranchResponse(
3029
id = 1,

data/notice/src/main/java/com/ku_stacks/ku_ring/notice/mapper/ResponseToDomain.kt

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,10 @@
11
package com.ku_stacks.ku_ring.notice.mapper
22

33
import com.ku_stacks.ku_ring.domain.Notice
4-
import com.ku_stacks.ku_ring.remote.notice.response.NoticeListResponse
5-
import com.ku_stacks.ku_ring.remote.notice.response.SearchNoticeListResponse
4+
import com.ku_stacks.ku_ring.remote.notice.response.SearchNoticeDataResponse
5+
import com.ku_stacks.ku_ring.remote.util.DefaultResponse
66

7-
fun NoticeListResponse.toNoticeList(type: String): List<Notice> {
8-
return if (type == "lib") {
9-
noticeResponse.map {
10-
val transformedDate = it.postedDate.let { date ->
11-
if (date.length == 19) { //도서관의 경우에는 특별하게 millisecond 단위로 나옴
12-
return@let date.substring(0, 4) + date.substring(5, 7) + date.substring(8, 10)
13-
} else {
14-
return@let date
15-
}
16-
}
17-
18-
Notice(
19-
postedDate = transformedDate,
20-
subject = it.subject.trim(),
21-
category = it.category,
22-
url = it.url,
23-
articleId = it.articleId,
24-
id = it.id,
25-
isNew = false,
26-
isRead = false,
27-
isSubscribing = false,
28-
isSaved = false,
29-
isReadOnStorage = false,
30-
isImportant = it.isImportant,
31-
tag = emptyList(),
32-
commentCount = it.commentCount
33-
)
34-
}
35-
} else {
36-
noticeResponse.map {
37-
Notice(
38-
postedDate = it.postedDate,
39-
subject = it.subject.trim(),
40-
category = it.category,
41-
url = it.url,
42-
articleId = it.articleId,
43-
id = it.id,
44-
isNew = false,
45-
isRead = false,
46-
isSubscribing = false,
47-
isSaved = false,
48-
isReadOnStorage = false,
49-
isImportant = it.isImportant,
50-
tag = emptyList(),
51-
commentCount = it.commentCount,
52-
)
53-
}
54-
}
55-
}
56-
57-
fun SearchNoticeListResponse.toNoticeList(): List<Notice> {
7+
fun DefaultResponse<SearchNoticeDataResponse>.toNoticeList(): List<Notice> {
588
return data?.noticeList?.map {
599
return@map Notice(
6010
postedDate = it.postedDate,

data/notice/src/main/java/com/ku_stacks/ku_ring/notice/repository/NoticeRepositoryImpl.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ class NoticeRepositoryImpl @Inject constructor(
139139
}
140140

141141
override suspend fun fetchSubscriptionFromRemote(token: String): List<String> {
142-
return noticeClient.fetchSubscribe(token).categoryList.map { it.koreanName }
142+
val response = noticeClient.fetchSubscribe(token)
143+
return when {
144+
response.isSuccessAndDataExists -> response.data!!.map { it.koreanName }
145+
else -> throw IllegalStateException(response.resultMsg)
146+
}
143147
}
144148

145149
override suspend fun saveSubscriptionToRemote(
@@ -161,10 +165,12 @@ class NoticeRepositoryImpl @Inject constructor(
161165

162166
override suspend fun getNoticeSearchResult(query: String): List<Notice> =
163167
withContext(Dispatchers.IO) {
164-
val result = noticeClient.fetchNoticeList(query).takeIf { it.isSuccess }?.toNoticeList()
165-
?: emptyList()
168+
val result =
169+
noticeClient.fetchNoticeList(query).takeIf { it.isSuccess }?.toNoticeList()
170+
?: emptyList()
166171

167-
val savedArticleIdSet = noticeDao.getSavedNoticeList(true).map { it.articleId }.toSet()
172+
val savedArticleIdSet =
173+
noticeDao.getSavedNoticeList(true).map { it.articleId }.toSet()
168174

169175
result.map {
170176
it.copy(isSaved = savedArticleIdSet.contains(it.articleId))

data/notice/src/main/java/com/ku_stacks/ku_ring/notice/source/CategoryNoticeMediator.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ class CategoryNoticeMediator(
3737
}
3838

3939
return suspendRunCatching {
40-
val noticeResponse = noticeClient.fetchNoticeList(categoryShortName, page, ITEM_SIZE)
41-
insertNotices(noticeResponse.noticeResponse)
40+
val noticeResponses =
41+
noticeClient.fetchNoticeList(categoryShortName, page, ITEM_SIZE).data
42+
?: throw IllegalStateException("noticeResponse is null")
4243

43-
MediatorResult.Success(endOfPaginationReached = noticeResponse.noticeResponse.isEmpty())
44+
insertNotices(noticeResponses)
45+
46+
MediatorResult.Success(endOfPaginationReached = noticeResponses.isEmpty())
4447
}.getOrElse {
4548
MediatorResult.Error(it)
4649
}

data/notice/src/main/java/com/ku_stacks/ku_ring/notice/source/DepartmentNoticeMediator.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ class DepartmentNoticeMediator(
4343
page = page,
4444
size = ITEM_SIZE
4545
)
46+
val data = noticeResponse.data ?: throw IllegalStateException("noticeResponse is null")
4647

4748
val startDate = getAppStartedDate()
48-
val entities = noticeResponse.data.toEntityList(shortName, startDate)
49+
val entities = data.toEntityList(shortName, startDate)
4950
insertNotices(entities, page)
5051

51-
val isPageEnd = noticeResponse.data.isEmpty()
52+
val isPageEnd = data.isEmpty()
5253
MediatorResult.Success(endOfPaginationReached = isPageEnd)
5354
} catch (e: Exception) {
5455
MediatorResult.Error(e)
@@ -62,9 +63,13 @@ class DepartmentNoticeMediator(
6263
size = ITEM_SIZE,
6364
important = true
6465
)
66+
val data =
67+
importNoticesResponse.data
68+
?: throw IllegalStateException("importNoticesResponse is null")
69+
6570

6671
val startDate = getAppStartedDate()
67-
val entities = importNoticesResponse.data.toEntityList(shortName, startDate)
72+
val entities = data.toEntityList(shortName, startDate)
6873
insertNotices(entities, 0)
6974
}
7075

0 commit comments

Comments
 (0)