-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs:readme.md * feat: step0 code upload with package, mocking * docs: readme.md * build: dependencies & settings * feat: MyApplication - Hilt * feat: mapitem - room db * feat: dao define * feat: room database * feat: hilt app module * feat: MapRepository abstracton * feat: ViewModel * feat: ui - main, search * fix: api key 로컬에서는 수정해두었는데 반영되지 않은 브랜치로 pr을 올린 거 같습니다. 다음부턴 주의하겠습니다. --------- Co-authored-by: 유지예 <[email protected]>
- Loading branch information
Showing
14 changed files
with
151 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
# android-map-refactoring | ||
### KakaoTechCampus 2기 Step2 - 5주차 과제 : 리팩토링 | ||
|
||
### 0단계. 4주차 코드 반영하기 | ||
### 1단계. 의존성 주입 | ||
|
||
### 기능 구현 | ||
- [ ] build 파일 의존성 추가 | ||
- [ ] Hilt 의존성 적용한 MyApplication 구현 | ||
- [ ] Room Database 정의 | ||
- [ ] DAO 정의 | ||
- [ ] Room Database와 DAO에 Hilt 모듈 설정 구현 | ||
- [ ] 데이터 추상화 구현 | ||
- [ ] ViewModel 및 UI hilt 의존성 및 room 적용 수정 | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package campus.tech.kakao.map.database | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import campus.tech.kakao.map.model.MapItem | ||
|
||
@Dao | ||
interface MapItemDao { | ||
|
||
@Insert | ||
suspend fun insert(mapItem: MapItem) | ||
|
||
@Query("SELECT * FROM MapItem WHERE place_name LIKE :query") | ||
suspend fun searchItems(query: String): List<MapItem> | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/campus/tech/kakao/map/database/AppDatabase.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,10 @@ | ||
package campus.tech.kakao.map.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import campus.tech.kakao.map.model.MapItem | ||
|
||
@Database(entities = [MapItem::class], version = 1, exportSchema = false) | ||
abstract class AppDatabase : RoomDatabase() { | ||
abstract fun mapItemDao(): MapItemDao | ||
} |
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,31 @@ | ||
package campus.tech.kakao.map.di | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import campus.tech.kakao.map.database.AppDatabase | ||
import campus.tech.kakao.map.database.MapItemDao | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object AppModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideDatabase(appContext: Context): AppDatabase { | ||
return Room.databaseBuilder( | ||
appContext, | ||
AppDatabase::class.java, | ||
"map_database" | ||
).build() | ||
} | ||
|
||
@Provides | ||
fun provideMapItemDao(database: AppDatabase): MapItemDao { | ||
return database.mapItemDao() | ||
} | ||
} |
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,12 +1,14 @@ | ||
package campus.tech.kakao.map.model | ||
|
||
//이름 보다 알기 쉽게 변경 - api맞춰서 | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "MapItem") | ||
data class MapItem( | ||
val id: String, | ||
@PrimaryKey val id: Int, | ||
val place_name: String, | ||
val road_address_name: String, | ||
val category_group_name: String, | ||
val x: Double, | ||
val y: Double | ||
|
||
) |
24 changes: 18 additions & 6 deletions
24
app/src/main/java/campus/tech/kakao/map/repository/MapRepository.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,17 +1,29 @@ | ||
package campus.tech.kakao.map.repository | ||
|
||
import android.app.Application | ||
import campus.tech.kakao.map.database.MapItemDao | ||
import campus.tech.kakao.map.network.KakaoApiService | ||
import campus.tech.kakao.map.model.MapItem | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
interface MapRepository { | ||
suspend fun searchItems(query: String): List<MapItem> | ||
} | ||
|
||
class MapRepositoryImpl(private val application: Application) : MapRepository { | ||
|
||
private val mapAccess = MapAccess(application) | ||
class MapRepositoryImpl @Inject constructor( | ||
private val mapItemDao: MapItemDao, | ||
private val apiService: KakaoApiService | ||
) : MapRepository { | ||
|
||
override suspend fun searchItems(query: String): List<MapItem> { | ||
return mapAccess.searchItems(query) | ||
return withContext(Dispatchers.IO) { | ||
val response = apiService.searchPlaces(Constants.KAKAO_API_KEY, query) | ||
if (response.isSuccessful) { | ||
response.body()?.documents ?: emptyList() | ||
} else { | ||
emptyList() | ||
} | ||
} | ||
} | ||
} | ||
} |
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.