Skip to content

Commit

Permalink
chore: MapItem->MapItemEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
유지예 authored and 유지예 committed Jul 28, 2024
1 parent c630779 commit fff87f5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
7 changes: 3 additions & 4 deletions app/src/main/java/campus/tech/kakao/map/dao/MapItemDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ 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

import campus.tech.kakao.map.model.MapItemEntity
@Dao
interface MapItemDao {

@Insert
suspend fun insert(mapItem: MapItem)
suspend fun insert(mapItem: MapItemEntity)

@Query("SELECT * FROM MapItem WHERE place_name LIKE :query")
suspend fun searchItems(query: String): List<MapItem>
suspend fun searchItems(query: String): List<MapItemEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package campus.tech.kakao.map.database

import androidx.room.Database
import androidx.room.RoomDatabase
import campus.tech.kakao.map.model.MapItem
import campus.tech.kakao.map.model.MapItemEntity

@Database(entities = [MapItem::class], version = 1, exportSchema = false)
@Database(entities = [MapItemEntity::class], version = 1, exportSchema = false)
abstract class AppDatabase : RoomDatabase() {
abstract fun mapItemDao(): MapItemDao
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package campus.tech.kakao.map.model

import campus.tech.kakao.map.model.MapItem
import campus.tech.kakao.map.model.MapItemEntity

//MapItem 넘겨받기 -> 매핑
data class KakaoSearchResponse(
val documents: List<MapItem>
val documents: List<MapItemEntity>
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "MapItem")
data class MapItem(
data class MapItemEntity(
@PrimaryKey val id: Int,
val place_name: String,
val road_address_name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ package campus.tech.kakao.map.repository

import campus.tech.kakao.map.database.MapItemDao
import campus.tech.kakao.map.network.KakaoApiService
import campus.tech.kakao.map.model.MapItem
import campus.tech.kakao.map.model.MapItemEntity
import campus.tech.kakao.map.util.Constants
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import javax.inject.Inject

interface MapRepository {
suspend fun searchItems(query: String): List<MapItem>
suspend fun searchItems(query: String): List<MapItemEntity>
}

class MapRepositoryImpl @Inject constructor(
private val mapItemDao: MapItemDao,
private val apiService: KakaoApiService
) : MapRepository {

override suspend fun searchItems(query: String): List<MapItem> {
override suspend fun searchItems(query: String): List<MapItemEntity> {
return withContext(Dispatchers.IO) {
val response = apiService.searchPlaces(Constants.KAKAO_API_KEY, query)
if (response.isSuccessful) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/campus/tech/kakao/map/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.kakao.vectormap.*
import campus.tech.kakao.map.R
import campus.tech.kakao.map.model.MapItem
import campus.tech.kakao.map.model.MapItemEntity
import campus.tech.kakao.map.viewmodel.MapViewModel
import com.kakao.vectormap.camera.CameraAnimation
import com.kakao.vectormap.camera.CameraUpdateFactory
Expand All @@ -39,7 +39,7 @@ class MainActivity : AppCompatActivity() {
private lateinit var bottomSheetTitle: TextView
private lateinit var bottomSheetAddress: TextView
private lateinit var bottomSheetLayout: FrameLayout
private var selectedItems = mutableListOf<MapItem>()
private var selectedItems = mutableListOf<MapItemEntity>()
private val viewModel: MapViewModel by viewModels()

companion object {
Expand Down Expand Up @@ -159,7 +159,7 @@ class MainActivity : AppCompatActivity() {
val category_group_name = it.getStringExtra("category_group_name_$i") ?: ""
val x = it.getDoubleExtra("x_$i", 0.0)
val y = it.getDoubleExtra("y_$i", 0.0)
selectedItems.add(MapItem(id, place_name, road_address_name, category_group_name, x, y))
selectedItems.add(MapItemEntity(id, place_name, road_address_name, category_group_name, x, y))
}

// 마커 위치 저장
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/campus/tech/kakao/map/ui/SearchActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import android.app.Activity
import android.content.Intent
import campus.tech.kakao.map.viewmodel.MapViewModel
import campus.tech.kakao.map.R
import campus.tech.kakao.map.model.MapItem
import campus.tech.kakao.map.model.MapItemEntity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -36,15 +36,15 @@ class SearchActivity : AppCompatActivity() {
observeViewModel()

val selectedItemsSize = intent.getIntExtra("selectedItemsSize", 0)
val selectedItems = mutableListOf<MapItem>()
val selectedItems = mutableListOf<MapItemEntity>()
for (i in 0 until selectedItemsSize) {
val id = intent.getIntExtra("id_$i", 0)
val place_name = intent.getStringExtra("place_name_$i") ?: ""
val road_address_name = intent.getStringExtra("road_address_name_$i") ?: ""
val category_group_name = intent.getStringExtra("category_group_name_$i") ?: ""
val x = intent.getDoubleExtra("x_$i", 0.0)
val y = intent.getDoubleExtra("y_$i", 0.0)
selectedItems.add(MapItem(id, place_name, road_address_name, category_group_name, x, y))
selectedItems.add(MapItemEntity(id, place_name, road_address_name, category_group_name, x, y))
}
viewModel.setSelectedItems(selectedItems)
}
Expand Down Expand Up @@ -116,7 +116,7 @@ class SearchActivity : AppCompatActivity() {
viewModel.searchQuery.value = query
}

fun setResultAndFinish(selectedItem: MapItem) {
fun setResultAndFinish(selectedItem: MapItemEntity) {
val intent = Intent().apply {
putExtra("place_name", selectedItem.place_name)
putExtra("road_address_name", selectedItem.road_address_name)
Expand Down

0 comments on commit fff87f5

Please sign in to comment.