-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
f28a00e
commit 74f54f7
Showing
7 changed files
with
112 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
app/src/main/kotlin/jp/co/yumemi/android/code_check/data/local/SearchDao.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,24 @@ | ||
package jp.co.yumemi.android.code_check.data.local | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import jp.co.yumemi.android.code_check.data.local.model.SearchEntity | ||
|
||
@Dao | ||
interface SearchDao { | ||
|
||
@Query( | ||
value = """ | ||
SELECT `query` FROM SearchEntity | ||
WHERE `result` == 1 | ||
GROUP BY `query` | ||
ORDER BY COUNT(`query`) DESC | ||
LIMIT 10 | ||
""" | ||
) | ||
suspend fun topSearched(): List<String> | ||
|
||
@Insert | ||
suspend fun insertSearchResult(entity: SearchEntity) | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/kotlin/jp/co/yumemi/android/code_check/data/local/SearchDatabase.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,18 @@ | ||
package jp.co.yumemi.android.code_check.data.local | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import jp.co.yumemi.android.code_check.data.local.model.SearchEntity | ||
|
||
@Database( | ||
entities = [SearchEntity::class], | ||
version = 1, | ||
) | ||
abstract class SearchDatabase: RoomDatabase() { | ||
|
||
abstract val searchDao: SearchDao | ||
|
||
companion object { | ||
const val DATABASE_NAME = "search_result_db" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/kotlin/jp/co/yumemi/android/code_check/data/local/model/SearchEntity.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 jp.co.yumemi.android.code_check.data.local.model | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity | ||
data class SearchEntity( | ||
val query: String, | ||
val result: Boolean, | ||
val searchedAt: Long, | ||
@PrimaryKey val id: Int? = null | ||
) |
8 changes: 8 additions & 0 deletions
8
...src/main/kotlin/jp/co/yumemi/android/code_check/data/repository/SearchResultRepository.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 jp.co.yumemi.android.code_check.data.repository | ||
|
||
interface SearchResultRepository { | ||
|
||
suspend fun getTopSearched(): List<String> | ||
|
||
suspend fun insertRecord(query: String, result: Boolean) | ||
} |
24 changes: 24 additions & 0 deletions
24
...main/kotlin/jp/co/yumemi/android/code_check/data/repository/SearchResultRepositoryImpl.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,24 @@ | ||
package jp.co.yumemi.android.code_check.data.repository | ||
|
||
import jp.co.yumemi.android.code_check.data.local.SearchDao | ||
import jp.co.yumemi.android.code_check.data.local.model.SearchEntity | ||
import java.util.* | ||
|
||
class SearchResultRepositoryImpl( | ||
private val searchDao: SearchDao, | ||
) : SearchResultRepository { | ||
|
||
override suspend fun getTopSearched(): List<String> { | ||
return searchDao.topSearched() | ||
} | ||
|
||
override suspend fun insertRecord(query: String, result: Boolean) { | ||
return searchDao.insertSearchResult( | ||
SearchEntity( | ||
query = query, | ||
result = result, | ||
searchedAt = Calendar.getInstance().time.time, | ||
) | ||
) | ||
} | ||
} |
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