-
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.
Merge branch 'feat/#179-map-location-search' of https://github.com/SO…
…PT-all/35-APPJAM-ANDROID-SPOONY into feat/#179-map-location-search
- Loading branch information
Showing
21 changed files
with
252 additions
and
34 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
48 changes: 48 additions & 0 deletions
48
app/src/main/java/com/spoony/spoony/core/database/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,48 @@ | ||
package com.spoony.spoony.core.database | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import androidx.room.Transaction | ||
import com.spoony.spoony.core.database.entity.SearchEntity | ||
|
||
@Dao | ||
interface SearchDao { | ||
// 검색어 추가 | ||
@Insert | ||
suspend fun insertSearch(searchEntity: SearchEntity) | ||
|
||
// 특정 검색어 삭제 | ||
@Query("DELETE FROM search WHERE text = :searchText") | ||
suspend fun deleteSearchByText(searchText: String) | ||
|
||
// 전체 검색어 삭제 | ||
@Query("DELETE FROM search") | ||
suspend fun deleteAllSearches() | ||
|
||
// 최신순으로 최대 6개의 검색어 가져오기 | ||
@Query("SELECT * FROM search ORDER BY id DESC LIMIT 6") | ||
suspend fun getRecentSearches(): List<SearchEntity> | ||
|
||
// 검색어 추가 시, 최근 6개만 유지하도록 처리 | ||
@Transaction | ||
suspend fun addSearchWithLimit(searchEntity: SearchEntity) { | ||
// 검색어 추가 | ||
insertSearch(searchEntity) | ||
|
||
// 총 검색어 수가 6개를 초과하면 오래된 검색어 삭제 | ||
val allSearches = getAllSearches() // 모든 검색어 가져오기 | ||
if (allSearches.size > 6) { | ||
val excessSearches = allSearches.drop(6) // 초과된 검색어 | ||
excessSearches.forEach { deleteSearchById(it.id) } | ||
} | ||
} | ||
|
||
// 특정 ID 검색어 삭제 | ||
@Query("DELETE FROM search WHERE id = :id") | ||
suspend fun deleteSearchById(id: Int) | ||
|
||
// 전체 검색어 가져오기 | ||
@Query("SELECT * FROM search ORDER BY id DESC") | ||
suspend fun getAllSearches(): List<SearchEntity> | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/spoony/spoony/core/database/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,13 @@ | ||
package com.spoony.spoony.core.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import com.spoony.spoony.core.database.entity.SearchEntity | ||
|
||
@Database( | ||
entities = [SearchEntity::class], | ||
version = 1 | ||
) | ||
abstract class SearchDatabase : RoomDatabase() { | ||
abstract fun SearchDao(): SearchDao | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/spoony/spoony/core/database/di/DatabaseModule.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,28 @@ | ||
package com.spoony.spoony.core.database.di | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import com.spoony.spoony.core.database.SearchDatabase | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DBModule { | ||
@Singleton | ||
@Provides | ||
fun providesDataBase( | ||
@ApplicationContext context: Context | ||
): SearchDatabase = | ||
Room.databaseBuilder(context, SearchDatabase::class.java, "search-database").build() | ||
|
||
@Singleton | ||
@Provides | ||
fun providesDao( | ||
searchDatabase: SearchDatabase | ||
) = searchDatabase.SearchDao() | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/spoony/spoony/core/database/entity/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,13 @@ | ||
package com.spoony.spoony.core.database.entity | ||
|
||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity( | ||
tableName = "search" | ||
) | ||
data class SearchEntity( | ||
@PrimaryKey(autoGenerate = true) | ||
val id: Int = 0, | ||
val text: String | ||
) |
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
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
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.