generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
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.
- Loading branch information
1 parent
60827e8
commit b8eb673
Showing
16 changed files
with
146 additions
and
18 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
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/sopt/now/compose/data/datasource/FriendRemoteDataSource.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,7 @@ | ||
package com.sopt.now.compose.data.datasource | ||
|
||
import com.sopt.now.compose.data.model.response.ResponseFriendsDto | ||
|
||
interface FriendRemoteDataSource { | ||
suspend fun getFriendsList(page: Int): ResponseFriendsDto | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/sopt/now/compose/data/datasourceImpl/FriendRemoteDatasourceImpl.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.sopt.now.compose.data.datasourceImpl | ||
|
||
import com.sopt.now.compose.data.datasource.FriendRemoteDataSource | ||
import com.sopt.now.compose.data.model.response.ResponseFriendsDto | ||
import com.sopt.now.compose.data.service.FriendService | ||
import javax.inject.Inject | ||
|
||
class FriendRemoteDatasourceImpl @Inject constructor( | ||
private val friendService: FriendService | ||
) : FriendRemoteDataSource { | ||
override suspend fun getFriendsList(page: Int): ResponseFriendsDto = | ||
friendService.getFriendsList(page = page) | ||
} |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/com/sopt/now/compose/data/model/response/ResponseFriendsDto.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,58 @@ | ||
package com.sopt.now.compose.data.model.response | ||
|
||
import com.sopt.now.compose.domain.model.Friend | ||
import com.sopt.now.compose.domain.model.FriendsList | ||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseFriendsDto( | ||
@SerialName("page") | ||
val page: Int = 2, | ||
@SerialName("per_page") | ||
val perPage: Int, | ||
@SerialName("total") | ||
val total: Int, | ||
@SerialName("total_pages") | ||
val totalPages: Int, | ||
@SerialName("data") | ||
val data: List<ResponseFriend>, | ||
@SerialName("support") | ||
val support: ResponseFriendsListSupportDto, | ||
) { | ||
@Serializable | ||
data class ResponseFriend( | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("email") | ||
val email: String, | ||
@SerialName("first_name") | ||
val firstName: String, | ||
@SerialName("last_name") | ||
val lastName: String, | ||
@SerialName("avatar") | ||
val avatar: String, | ||
) { | ||
fun toFriendEntity(): Friend = | ||
Friend( | ||
id = this.id, | ||
email = this.email, | ||
firstName = this.firstName, | ||
lastName = this.lastName, | ||
avatar = this.avatar | ||
) | ||
} | ||
|
||
@Serializable | ||
data class ResponseFriendsListSupportDto( | ||
@SerialName("url") | ||
val url: String, | ||
@SerialName("text") | ||
val text: String, | ||
) | ||
|
||
fun toFriendsList(): FriendsList = | ||
FriendsList( | ||
friendsList = this.data.map { it.toFriendEntity() } | ||
) | ||
} |
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
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/sopt/now/compose/data/repository/FriendsRepositoryImpl.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,15 @@ | ||
package com.sopt.now.compose.data.repository | ||
|
||
import com.sopt.now.compose.data.datasource.FriendRemoteDataSource | ||
import com.sopt.now.compose.domain.model.FriendsList | ||
import com.sopt.now.compose.domain.repository.FriendRepository | ||
import javax.inject.Inject | ||
|
||
class FriendsRepositoryImpl @Inject constructor( | ||
private val friendRemoteDataSource: FriendRemoteDataSource, | ||
) : FriendRepository { | ||
override suspend fun getFriendsList(page: Int): Result<FriendsList> = | ||
runCatching { | ||
friendRemoteDataSource.getFriendsList(page = page).toFriendsList() | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/sopt/now/compose/data/service/FriendService.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,12 @@ | ||
package com.sopt.now.compose.data.service | ||
|
||
import com.sopt.now.compose.data.model.response.ResponseFriendsDto | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface FriendService { | ||
@GET("api/users") | ||
suspend fun getFriendsList( | ||
@Query("page") page: Int, | ||
): ResponseFriendsDto | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/com/sopt/now/compose/domain/model/Friend.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,9 @@ | ||
package com.sopt.now.compose.domain.model | ||
|
||
data class Friend( | ||
val id: Int, | ||
val email: String, | ||
val firstName: String, | ||
val lastName: String, | ||
val avatar: String, | ||
) |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/sopt/now/compose/domain/model/FriendsList.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,5 @@ | ||
package com.sopt.now.compose.domain.model | ||
|
||
data class FriendsList( | ||
val friendsList: List<Friend> | ||
) |
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
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/sopt/now/compose/domain/repository/FriendRepository.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,7 @@ | ||
package com.sopt.now.compose.domain.repository | ||
|
||
import com.sopt.now.compose.domain.model.FriendsList | ||
|
||
interface FriendRepository { | ||
suspend fun getFriendsList(page: Int): Result<FriendsList> | ||
} |
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