-
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.
- Room 추가 - Database 작업 - DI 모듈 작성
- Loading branch information
Showing
16 changed files
with
390 additions
and
157 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
data/src/main/java/ny/photomap/data/db/PhotoLocationDao.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,66 @@ | ||
package ny.photomap.data.db | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import androidx.room.Update | ||
|
||
@Dao | ||
interface PhotoLocationDao { | ||
|
||
@Query("SELECT * FROM photo_location_table") | ||
suspend fun getAll(): List<PhotoLocationEntity> | ||
|
||
@Query( | ||
"SELECT * FROM photo_location_table WHERE (latitude BETWEEN :latitude - :range AND :latitude + :range) " + | ||
"AND (longitude BETWEEN :longitude - :range AND :longitude + :range)" | ||
) | ||
suspend fun getLocationOf( | ||
latitude: Double, | ||
longitude: Double, | ||
range: Double, | ||
): List<PhotoLocationEntity> | ||
|
||
@Query( | ||
"SELECT * FROM photo_location_table WHERE (latitude BETWEEN :latitude - :range AND :latitude + :range) " + | ||
"AND (longitude BETWEEN :longitude - :range AND :longitude + :range) " + | ||
"AND (generatedTime BETWEEN :fromTime AND :toTime)" | ||
) | ||
suspend fun getLocationAndDateOf( | ||
latitude: Double, | ||
longitude: Double, | ||
range: Double, | ||
fromTime: Long, | ||
toTime: Long, | ||
): List<PhotoLocationEntity> | ||
|
||
@Query( | ||
"SELECT COUNT(*) FROM photo_location_table WHERE (latitude BETWEEN :latitude - :range AND :latitude + :range) " + | ||
"AND (longitude BETWEEN :longitude - :range AND :longitude + :range) " + | ||
"AND (generatedTime BETWEEN :fromTime AND :toTime)" | ||
) | ||
suspend fun getCountOfLocationAndDate( | ||
latitude: Double, | ||
longitude: Double, | ||
range: Double, | ||
fromTime: Long, | ||
toTime: Long, | ||
): Int | ||
|
||
@Insert | ||
suspend fun insert(entity: PhotoLocationEntity) | ||
|
||
@Insert | ||
suspend fun insertAll(entityList: List<PhotoLocationEntity>) | ||
|
||
@Update | ||
suspend fun update(entity: PhotoLocationEntity) | ||
|
||
@Delete | ||
suspend fun delete(entity: PhotoLocationEntity) | ||
|
||
@Delete | ||
suspend fun deleteAll(entityList: List<PhotoLocationEntity>) | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
data/src/main/java/ny/photomap/data/db/PhotoLocationDatabase.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,20 @@ | ||
package ny.photomap.data.db | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
|
||
@Database(entities = [PhotoLocationEntity::class], version = 1) | ||
abstract class PhotoLocationDatabase : RoomDatabase() { | ||
abstract fun photoLocationDao(): PhotoLocationDao | ||
|
||
companion object { | ||
fun getInstance(context: Context): PhotoLocationDatabase = Room.databaseBuilder( | ||
context, | ||
PhotoLocationDatabase::class.java, | ||
"photo_location.db" | ||
) | ||
.build() | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
data/src/main/java/ny/photomap/data/db/PhotoLocationEntity.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,20 @@ | ||
package ny.photomap.data.db | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "photo_location_table") | ||
data class PhotoLocationEntity( | ||
val uri: String, | ||
val name: String?, | ||
val latitude: Double, | ||
val longitude: Double, | ||
val generatedTime: String?, | ||
val addedTime: String?, | ||
@ColumnInfo(typeAffinity = ColumnInfo.BLOB) | ||
val thumbNail: ByteArray?, | ||
) { | ||
@PrimaryKey(autoGenerate = true) | ||
var id: Long = 0 | ||
} |
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,22 @@ | ||
package ny.photomap.data.di | ||
|
||
import android.content.Context | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import ny.photomap.data.db.PhotoLocationDao | ||
import ny.photomap.data.db.PhotoLocationDatabase | ||
|
||
@InstallIn(SingletonComponent::class) | ||
@Module | ||
object DatabaseModule { | ||
@Provides | ||
fun providePhotoLocationDatabase(@ApplicationContext context: Context): PhotoLocationDatabase = | ||
PhotoLocationDatabase.getInstance(context) | ||
|
||
@Provides | ||
fun providePhotoLocationDao(photoLocationDatabase: PhotoLocationDatabase): PhotoLocationDao = | ||
photoLocationDatabase.photoLocationDao() | ||
} |
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
Binary file not shown.
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,6 +1,7 @@ | ||
#Mon Nov 04 20:49:31 KST 2024 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip | ||
networkTimeout=10000 | ||
validateDistributionUrl=true | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.