generated from GO-SOPT-ANDROID/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.
[ADD/#8] get follower list 서버통신 함수 설계
- Loading branch information
Showing
10 changed files
with
136 additions
and
1 deletion.
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
51 changes: 51 additions & 0 deletions
51
...c/main/java/org/android/go/sopt/data/entity/remote/response/ResponseGetFollowerListDto.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,51 @@ | ||
package org.android.go.sopt.data.entity.remote.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import org.android.go.sopt.domain.model.Follower | ||
|
||
@Serializable | ||
data class ResponseGetFollowerListDto( | ||
@SerialName("page") | ||
val page: Int, | ||
@SerialName("per_page") | ||
val perPage: Int, | ||
@SerialName("total") | ||
val total: Int, | ||
@SerialName("total_pages") | ||
val totalPages: Int, | ||
@SerialName("data") | ||
val data: List<Follower>, | ||
@SerialName("support") | ||
val support: Support, | ||
) { | ||
@Serializable | ||
data class Follower( | ||
@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, | ||
) | ||
|
||
@Serializable | ||
data class Support( | ||
@SerialName("url") | ||
val url: String, | ||
@SerialName("text") | ||
val text: String, | ||
) | ||
|
||
fun toFollower() = data.map { follower -> | ||
Follower( | ||
name = "${follower.firstName} ${follower.lastName}", | ||
profile = follower.avatar, | ||
email = follower.email, | ||
) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/org/android/go/sopt/data/repository/FollowerRepositoryImpl.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 org.android.go.sopt.data.repository | ||
|
||
import org.android.go.sopt.data.source.remote.FollowerDataSource | ||
import org.android.go.sopt.domain.model.Follower | ||
import org.android.go.sopt.domain.repository.FollowerRepository | ||
import javax.inject.Inject | ||
|
||
class FollowerRepositoryImpl @Inject constructor( | ||
private val followerDataSource: FollowerDataSource, | ||
) : FollowerRepository { | ||
override suspend fun getFollowerList(page: Int): Result<List<Follower>> = | ||
runCatching { | ||
followerDataSource.getFollowerList(page).toFollower() | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/android/go/sopt/data/service/FollowerService.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 org.android.go.sopt.data.service | ||
|
||
import org.android.go.sopt.data.entity.remote.response.ResponseGetFollowerListDto | ||
import retrofit2.http.GET | ||
import retrofit2.http.Query | ||
|
||
interface FollowerService { | ||
@GET("users") | ||
fun getFollowerList( | ||
@Query("page") page: Int, | ||
): ResponseGetFollowerListDto | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/android/go/sopt/data/source/remote/FollowerDataSource.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 org.android.go.sopt.data.source.remote | ||
|
||
import org.android.go.sopt.data.entity.remote.response.ResponseGetFollowerListDto | ||
import org.android.go.sopt.data.service.FollowerService | ||
import javax.inject.Inject | ||
|
||
class FollowerDataSource @Inject constructor( | ||
private val followerService: FollowerService, | ||
) { | ||
fun getFollowerList(page: Int): ResponseGetFollowerListDto = | ||
followerService.getFollowerList(page) | ||
} |
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/org/android/go/sopt/domain/model/Follower.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 org.android.go.sopt.domain.model | ||
|
||
data class Follower( | ||
val name: String, | ||
val profile: String, | ||
val email: String, | ||
) |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/org/android/go/sopt/domain/repository/FollowerRepository.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 org.android.go.sopt.domain.repository | ||
|
||
import org.android.go.sopt.domain.model.Follower | ||
|
||
interface FollowerRepository { | ||
suspend fun getFollowerList(page: Int): Result<List<Follower>> | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/org/android/go/sopt/util/type/BaseUrlType.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 org.android.go.sopt.util.type | ||
|
||
enum class BaseUrlType { | ||
SOPT, REQRES | ||
} |