-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
151 additions
and
114 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
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
10 changes: 9 additions & 1 deletion
10
core/data/src/main/java/com/android/mediproject/core/data/search/SearchHistoryRepository.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 |
---|---|---|
@@ -1,14 +1,22 @@ | ||
package com.android.mediproject.core.data.search | ||
|
||
import androidx.annotation.WorkerThread | ||
import com.android.mediproject.core.database.searchhistory.SearchHistoryDto | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
interface SearchHistoryRepository { | ||
suspend fun insertSearchHistory(query: String) | ||
@WorkerThread | ||
suspend fun insertSearchHistory(searchHistoryDto: SearchHistoryDto) | ||
|
||
@WorkerThread | ||
|
||
suspend fun getSearchHistoryList(count: Int = 5): Flow<List<SearchHistoryDto>> | ||
|
||
@WorkerThread | ||
|
||
suspend fun deleteSearchHistory(id: Long) | ||
|
||
@WorkerThread | ||
|
||
suspend fun deleteAllSearchHistory() | ||
} |
39 changes: 14 additions & 25 deletions
39
...ata/src/main/java/com/android/mediproject/core/data/search/SearchHistoryRepositoryImpl.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 |
---|---|---|
@@ -1,44 +1,33 @@ | ||
package com.android.mediproject.core.data.search | ||
|
||
import com.android.mediproject.core.common.network.Dispatcher | ||
import com.android.mediproject.core.common.network.MediDispatchers | ||
import com.android.mediproject.core.database.searchhistory.SearchHistoryDao | ||
import com.android.mediproject.core.database.searchhistory.SearchHistoryDto | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.withContext | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
import kotlinx.coroutines.runBlocking | ||
import javax.inject.Inject | ||
|
||
class SearchHistoryRepositoryImpl @Inject constructor( | ||
private val searchHistoryDao: SearchHistoryDao, @Dispatcher(MediDispatchers.IO) private val ioDispatcher: CoroutineDispatcher | ||
private val searchHistoryDao: SearchHistoryDao, | ||
) : SearchHistoryRepository { | ||
override suspend fun insertSearchHistory(query: String) { | ||
withContext(ioDispatcher) { | ||
searchHistoryDao.insert( | ||
SearchHistoryDto( | ||
query = query, id = 0L, searchDateTime = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) | ||
) | ||
) | ||
override suspend fun insertSearchHistory(searchHistoryDto: SearchHistoryDto) = runBlocking { | ||
searchHistoryDto.apply { | ||
query = query.trim() | ||
} | ||
if (!searchHistoryDao.isExist(searchHistoryDto.query)) searchHistoryDao.insert(searchHistoryDto) | ||
} | ||
|
||
override suspend fun getSearchHistoryList(count: Int): Flow<List<SearchHistoryDto>> = withContext(ioDispatcher) { | ||
searchHistoryDao.select(count) | ||
} | ||
|
||
override suspend fun getSearchHistoryList(count: Int): Flow<List<SearchHistoryDto>> = searchHistoryDao.select(count) | ||
|
||
override suspend fun deleteSearchHistory(id: Long) { | ||
withContext(ioDispatcher) { | ||
searchHistoryDao.delete(id) | ||
} | ||
|
||
override suspend fun deleteSearchHistory(id: Long) = runBlocking { | ||
searchHistoryDao.delete(id) | ||
} | ||
|
||
override suspend fun deleteAllSearchHistory() { | ||
withContext(ioDispatcher) { | ||
searchHistoryDao.deleteAll() | ||
} | ||
|
||
override suspend fun deleteAllSearchHistory() = runBlocking { | ||
searchHistoryDao.deleteAll() | ||
} | ||
|
||
|
||
} |
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
7 changes: 5 additions & 2 deletions
7
.../src/main/java/com/android/mediproject/core/database/searchhistory/SearchHistoryMapper.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 |
---|---|---|
@@ -1,9 +1,12 @@ | ||
package com.android.mediproject.core.database.searchhistory | ||
|
||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
fun SearchHistoryDto.toSearchHistoryItemDto(): com.android.mediproject.core.model.search.local.SearchHistoryItemDto { | ||
return com.android.mediproject.core.model.search.local.SearchHistoryItemDto( | ||
id = id, query = query, searchedAt = LocalDateTime.parse(this.searchDateTime) | ||
id = id, query = query, searchedAt = LocalDateTime.parse(this.searchDateTime, dateTimeFormatter) | ||
) | ||
} | ||
} | ||
|
||
private val dateTimeFormatter by lazy { DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss") } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,6 @@ class ButtonChip<T> : Chip { | |
listener.onClick(data) | ||
} | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.