Skip to content

Commit cc31b92

Browse files
authored
Merge pull request #89 from boostcampwm-2022/feature/ui/globe-detail-moment
글로브 안에 모먼트 추가하기 UI 구현
2 parents 277e181 + a15c7e9 commit cc31b92

Some content is hidden

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

41 files changed

+624
-155
lines changed

data/src/main/java/com/wakeup/data/database/dao/GlobeDao.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,7 @@ interface GlobeDao {
3636

3737
@Query("SELECT COUNT(moment_id) FROM moment_globe WHERE globe_id = :globeId")
3838
suspend fun getMomentCountByGlobe(globeId: Long): Int
39+
40+
@Query("SELECT * FROM moment WHERE moment_id NOT IN (SELECT moment_id FROM moment_globe WHERE globe_id = :globeId)")
41+
fun getMomentsNotInGlobe(globeId: Long): PagingSource<Int, MomentWithGlobesAndPictures>
3942
}

data/src/main/java/com/wakeup/data/repository/GlobeRepositoryImpl.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.map
1313
import javax.inject.Inject
1414

1515
class GlobeRepositoryImpl @Inject constructor(
16-
private val globeLocalDataSource: GlobeLocalDataSource
16+
private val globeLocalDataSource: GlobeLocalDataSource,
1717
) : GlobeRepository {
1818

1919
override suspend fun createGlobe(globe: Globe) {
@@ -46,4 +46,10 @@ class GlobeRepositoryImpl @Inject constructor(
4646
override suspend fun getMomentCountByGlobe(globeId: Long): Int {
4747
return globeLocalDataSource.getMomentCountByGlobe(globeId)
4848
}
49+
50+
override fun getMomentsNotInGlobe(globeId: Long): Flow<PagingData<Moment>> {
51+
return globeLocalDataSource.getMomentsNotInGlobe(globeId).map { pagingData ->
52+
pagingData.map { momentXRefs -> momentXRefs.toDomain() }
53+
}
54+
}
4955
}

data/src/main/java/com/wakeup/data/repository/MomentRepositoryImpl.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ class MomentRepositoryImpl @Inject constructor(
3030

3131
override fun getAllMoments(query: String): Flow<List<Moment>> =
3232
momentLocalDataSource.getAllMoments(query).map { momentInfoList ->
33-
momentInfoList.map { momentInfo ->
34-
momentInfo.toDomain()
35-
}
33+
momentInfoList.map { momentXRefs -> momentXRefs.toDomain() }
3634
}
3735

3836
override suspend fun getMoment(id: Long): Moment {

data/src/main/java/com/wakeup/data/source/local/globe/GlobeLocalDataSource.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ interface GlobeLocalDataSource {
2020
suspend fun getFirstMomentByGlobe(globeId: Long): MomentWithGlobesAndPictures?
2121

2222
suspend fun getMomentCountByGlobe(globeId: Long): Int
23+
24+
fun getMomentsNotInGlobe(globeId: Long): Flow<PagingData<MomentWithGlobesAndPictures>>
2325
}

data/src/main/java/com/wakeup/data/source/local/globe/GlobeLocalDataSourceImpl.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ class GlobeLocalDataSourceImpl @Inject constructor(
4747
return globeDao.getMomentCountByGlobe(globeId)
4848
}
4949

50+
51+
override fun getMomentsNotInGlobe(globeId: Long): Flow<PagingData<MomentWithGlobesAndPictures>> =
52+
Pager(
53+
config = PagingConfig(
54+
pageSize = PAGE_SIZE,
55+
enablePlaceholders = false,
56+
initialLoadSize = PAGE_SIZE,
57+
),
58+
pagingSourceFactory = {
59+
globeDao.getMomentsNotInGlobe(globeId)
60+
}
61+
).flow
62+
5063
companion object {
5164
const val PAGE_SIZE = 10
5265
}

data/src/main/java/com/wakeup/data/source/local/moment/MomentLocalDataSourceImpl.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,5 @@ class MomentLocalDataSourceImpl @Inject constructor(
7070
companion object {
7171
const val PREFETCH_PAGE = 2
7272
const val ITEMS_PER_PAGE = 10
73-
const val EXIST_INSERT_ERROR_CODE = -1L
7473
}
7574
}

data/src/main/java/com/wakeup/data/source/local/picture/PictureLocalDataSourceImpl.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.wakeup.data.source.local.picture
22

33
import com.wakeup.data.database.dao.PictureDao
44
import com.wakeup.data.database.entity.PictureEntity
5-
import com.wakeup.data.source.local.moment.MomentLocalDataSourceImpl
65
import javax.inject.Inject
76

87
class PictureLocalDataSourceImpl @Inject constructor(
@@ -11,11 +10,15 @@ class PictureLocalDataSourceImpl @Inject constructor(
1110
override suspend fun savePictures(pictures: List<PictureEntity>): List<Long> {
1211
val indexResult = pictureDao.savePictures(pictures).toMutableList()
1312
indexResult.forEachIndexed { pictureIndex, id ->
14-
if (id == MomentLocalDataSourceImpl.EXIST_INSERT_ERROR_CODE) {
13+
if (id == EXIST_INSERT_ERROR_CODE) {
1514
indexResult[pictureIndex] =
1615
pictureDao.getPictureIdByByteArray(pictures[pictureIndex].path)
1716
}
1817
}
1918
return indexResult.toList()
2019
}
20+
21+
companion object {
22+
const val EXIST_INSERT_ERROR_CODE = -1L
23+
}
2124
}

domain/src/main/java/com/wakeup/domain/repository/GlobeRepository.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ interface GlobeRepository {
2020
suspend fun getFirstMomentByGlobe(globeId: Long): Moment?
2121

2222
suspend fun getMomentCountByGlobe(globeId: Long): Int
23+
24+
fun getMomentsNotInGlobe(globeId: Long): Flow<PagingData<Moment>>
2325
}

domain/src/main/java/com/wakeup/domain/usecase/GetAllMomentsUseCase.kt

Whitespace-only changes.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.wakeup.domain.usecase
2+
3+
import androidx.paging.PagingData
4+
import com.wakeup.domain.model.Moment
5+
import com.wakeup.domain.repository.GlobeRepository
6+
import kotlinx.coroutines.flow.Flow
7+
import javax.inject.Inject
8+
9+
class GetMomentsNotInGlobeUseCase @Inject constructor(
10+
private val globeRepository: GlobeRepository
11+
) {
12+
operator fun invoke(globeId: Long): Flow<PagingData<Moment>> {
13+
return globeRepository.getMomentsNotInGlobe(globeId)
14+
}
15+
}

0 commit comments

Comments
 (0)