-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2주차 과제 #5
2주차 과제 #5
Changes from all commits
6d82052
e6dc0b9
43fcf30
20d19db
1258288
d5239e9
d178f32
46a6330
452d0cc
648d94a
23ad2b8
2543a4c
2d1dadf
a727d71
71391fc
6da4b76
d16f85a
ef46d8f
441d51f
c19baf4
3df156d
8d2b63f
37cb1b4
a5fe4fd
f166fe4
196c735
e497073
d22ae9c
4d19124
c2a5cde
3134883
279f31a
8303fa8
e11252e
cdce226
26ccb0d
c95f509
044bdc0
05f07ff
a937fb6
d42434f
0e48b4f
6e46d3b
0aca1c3
275cc69
e26fad1
d315c1c
6d67df8
2020d61
4e5a826
1c9bf4b
f2312fa
81dcfd7
7e68625
c078ac7
91ba7d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.dosopttemplate.data.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity | ||
|
||
@Database( | ||
entities = [ | ||
FriendInfoEntity::class | ||
], version = 1 | ||
) | ||
abstract class FriendDataBase : RoomDatabase() { | ||
abstract fun friendInfoDao(): FriendInfoDao | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.sopt.dosopttemplate.data.database | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Delete | ||
import androidx.room.Insert | ||
import androidx.room.Query | ||
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity | ||
|
||
@Dao | ||
interface FriendInfoDao { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Room 쓰는거 폼 진짜 말안되네 이남자... ..... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Room? 당장 구글링 해봐야겠다. |
||
@Query("SELECT * FROM table_friend_info") | ||
suspend fun getAll(): List<FriendInfoEntity> | ||
|
||
@Insert | ||
suspend fun addFriend(friendInfoEntity: FriendInfoEntity) | ||
|
||
@Insert | ||
suspend fun addFriends(friendList: List<FriendInfoEntity>) | ||
|
||
@Delete | ||
suspend fun deleteFriend(friendInfoEntity: FriendInfoEntity) | ||
|
||
@Query("DELETE FROM table_friend_info WHERE id = :id") | ||
suspend fun deleteFriendById(id: Int) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.sopt.dosopttemplate.data.datasource | ||
|
||
import org.sopt.dosopttemplate.data.database.FriendDataBase | ||
import org.sopt.dosopttemplate.data.local.FriendLocalDataSource | ||
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity | ||
import javax.inject.Inject | ||
|
||
class FriendLocalDataSourceImpl @Inject constructor( | ||
private val friendDataBase: FriendDataBase | ||
) : FriendLocalDataSource { | ||
override suspend fun getAll(): List<FriendInfoEntity> { | ||
return friendDataBase.friendInfoDao().getAll() | ||
} | ||
|
||
override suspend fun addFriend(friendInfoEntity: FriendInfoEntity) { | ||
friendDataBase.friendInfoDao().addFriend(friendInfoEntity) | ||
} | ||
|
||
override suspend fun addFriends(friendList: List<FriendInfoEntity>) { | ||
friendDataBase.friendInfoDao().addFriends(friendList) | ||
} | ||
|
||
override suspend fun deleteFriend(friendInfoEntity: FriendInfoEntity) { | ||
friendDataBase.friendInfoDao().deleteFriend(friendInfoEntity) | ||
} | ||
|
||
override suspend fun deleteFriendById(id: Int) { | ||
friendDataBase.friendInfoDao().deleteFriendById(id) | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.sopt.dosopttemplate.data.local | ||
|
||
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity | ||
|
||
interface FriendLocalDataSource { | ||
suspend fun getAll(): List<FriendInfoEntity> | ||
suspend fun addFriend(friendInfoEntity: FriendInfoEntity) | ||
suspend fun addFriends(friendList: List<FriendInfoEntity>) | ||
suspend fun deleteFriend(friendInfoEntity: FriendInfoEntity) | ||
suspend fun deleteFriendById(id: Int) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.sopt.dosopttemplate.data.model.local | ||
|
||
import androidx.room.ColumnInfo | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import org.sopt.dosopttemplate.domain.entity.Friend | ||
import java.time.LocalDate | ||
|
||
@Entity(tableName = "table_friend_info") | ||
data class FriendInfoEntity( | ||
@PrimaryKey(autoGenerate = true) | ||
val id: Int?, | ||
val name: String, | ||
val birthday: String, | ||
val music: String?, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 진짜... 모든 걸 다 구현한.. 멋져요.... 뒤에서 후광이..!! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오 생일과 뮤직도 구현하셨네요 ㅎㅎ 저는 시험 이슈로 안 했는데 저도 이제 슬슬 구현해보겠어유 |
||
@ColumnInfo(name = "image_uri") | ||
val imageUri: String?, | ||
) { | ||
companion object { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. companion object 개념을 처음 봐요. 정적 멤버를 정의할 때 사용하는거군여..? 또 하나 알아가요! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호 companion object 메모메모 합니다 |
||
fun toFriend(friendInfoList: List<FriendInfoEntity>) = friendInfoList.map { data -> | ||
Friend( | ||
id = data.id, | ||
name = data.name, | ||
birthday = LocalDate.parse(data.birthday), | ||
music = data.music, | ||
imageUri = data.imageUri | ||
) | ||
} | ||
|
||
fun toFriendInfoEntity(friendList: List<Friend>) = friendList.map { data -> | ||
FriendInfoEntity( | ||
id = data.id, | ||
name = data.name, | ||
birthday = data.birthday.toString(), | ||
music = data.music, | ||
imageUri = data.imageUri | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.sopt.dosopttemplate.data.repository | ||
|
||
import org.sopt.dosopttemplate.data.local.FriendLocalDataSource | ||
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity.Companion.toFriend | ||
import org.sopt.dosopttemplate.data.model.local.FriendInfoEntity.Companion.toFriendInfoEntity | ||
import org.sopt.dosopttemplate.domain.entity.Friend | ||
import org.sopt.dosopttemplate.domain.repository.FriendLocalRepository | ||
import javax.inject.Inject | ||
|
||
class FriendLocalRepositoryImpl @Inject constructor( | ||
private val friendLocalDataSource: FriendLocalDataSource | ||
) : FriendLocalRepository { | ||
override suspend fun getAll(): Result<List<Friend>> = | ||
runCatching { | ||
toFriend(friendLocalDataSource.getAll()) | ||
} | ||
|
||
override suspend fun addFriend(friend: Friend) { | ||
friendLocalDataSource.addFriend(toFriendInfoEntity(listOf(friend)).first()) | ||
} | ||
|
||
override suspend fun addFriends(friendList: List<Friend>) { | ||
friendLocalDataSource.addFriends(toFriendInfoEntity(friendList)) | ||
} | ||
|
||
override suspend fun deleteFriend(friend: Friend) { | ||
friendLocalDataSource.deleteFriend(toFriendInfoEntity(listOf(friend)).first()) | ||
} | ||
|
||
override suspend fun deleteFriendById(id: Int) { | ||
friendLocalDataSource.deleteFriendById(id) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.sopt.dosopttemplate.di | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.dosopttemplate.data.database.FriendDataBase | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object DataBaseModule { | ||
@Singleton | ||
@Provides | ||
fun provideDataBase( | ||
@ApplicationContext context: Context | ||
): FriendDataBase = | ||
Room.databaseBuilder(context, FriendDataBase::class.java, "sopt_friend.db") | ||
.createFromAsset("databases/sopt_friend.db").build() | ||
|
||
@Singleton | ||
@Provides | ||
fun provideFriendDao(friendDataBase: FriendDataBase) = friendDataBase.friendInfoDao() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.sopt.dosopttemplate.domain.entity | ||
|
||
import java.time.LocalDate | ||
|
||
data class Friend( | ||
val id: Int?, | ||
val name: String, | ||
val birthday: LocalDate?, | ||
val music: String?, | ||
val imageUri: String?, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ data class User( | |
val id: String? = "", | ||
val pw: String? = "", | ||
val nickname: String? = "", | ||
val hobby: String? = "" | ||
val discription: String? = "" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 취미도 궁금해요~ |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.sopt.dosopttemplate.domain.repository | ||
|
||
import org.sopt.dosopttemplate.domain.entity.Friend | ||
|
||
interface FriendLocalRepository { | ||
suspend fun getAll(): Result<List<Friend>> | ||
suspend fun addFriend(friend: Friend) | ||
suspend fun addFriends(friendList: List<Friend>) | ||
suspend fun deleteFriend(friend: Friend) | ||
suspend fun deleteFriendById(id: Int) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저는 한번도 직접 구현하는 코드에서 abstract를 사용해본 경험이 없는데.. 많이 배워가요..!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저도 room 이번에 한번 공부해봐야겠어요..!