-
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
4주차 세미나 과제 #9
4주차 세미나 과제 #9
Changes from all commits
59988f8
fe37b7a
4b7768a
ebaa9b0
d3c3115
2e8e9e5
e7d9d64
a532abb
a1e8550
95b1324
38648d3
aec7577
386777b
5e9e42a
3529471
10a8f42
33d310c
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,12 @@ | ||
package org.android.go.sopt.data.entity.remote.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestPostSignInDto( | ||
@SerialName("id") | ||
val id: String, | ||
@SerialName("password") | ||
val password: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.android.go.sopt.data.entity.remote.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestPostSignUpDto( | ||
@SerialName("id") | ||
val id: String, | ||
@SerialName("password") | ||
val password: String, | ||
@SerialName("name") | ||
val name: String, | ||
@SerialName("skill") | ||
val skill: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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( | ||
id = follower.id, | ||
name = "${follower.firstName} ${follower.lastName}", | ||
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. 오 이렇게도 할 수 있구낭..! |
||
profile = follower.avatar, | ||
email = follower.email, | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.android.go.sopt.data.entity.remote.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponsePostSignInDto( | ||
@SerialName("id") | ||
val id: String, | ||
@SerialName("name") | ||
val name: String, | ||
@SerialName("skill") | ||
val skill: String?, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.android.go.sopt.data.entity.remote.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponsePostSignUpDto( | ||
@SerialName("name") | ||
val name: String, | ||
@SerialName("skill") | ||
val skill: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.android.go.sopt.data.entity.remote.response.wrapper | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BaseResponse<T>( | ||
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. 와 이거 쇽샥해도 되나요 ? ㅋㅋ 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.
저희 다 오픈소스잖아요 🤭 |
||
@SerialName("status") | ||
val status: Int, | ||
@SerialName("message") | ||
val message: String, | ||
@SerialName("data") | ||
val data: T? = null, | ||
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. 오오오 Response에서 data의 타입만 달라지니까 제네릭으로 만들 수 있군요! 한수 배워갑니다👍👍 |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,42 @@ | ||
package org.android.go.sopt.data.repository | ||
|
||
import org.android.go.sopt.data.source.LocalPrefDataSource | ||
import org.android.go.sopt.data.entity.remote.request.RequestPostSignInDto | ||
import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto | ||
import org.android.go.sopt.data.entity.remote.response.ResponsePostSignInDto | ||
import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto | ||
import org.android.go.sopt.data.source.local.SharedPrefDataSource | ||
import org.android.go.sopt.data.source.remote.AuthDataSource | ||
import org.android.go.sopt.domain.model.User | ||
import org.android.go.sopt.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class AuthRepositoryImpl @Inject constructor( | ||
private val localPrefDataSource: LocalPrefDataSource, | ||
private val authDataSource: AuthDataSource, | ||
private val sharedPrefDataSource: SharedPrefDataSource, | ||
) : AuthRepository { | ||
override suspend fun postSignup(requestPostSignUpDto: RequestPostSignUpDto): Result<ResponsePostSignUpDto?> = | ||
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. Result 타입을 사용한 이유가 궁금합니다 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. 좀 더 간결하게 이벤트를 처리하기 위해 runCatching을 활용해서 반환 타입을 Result로 지정해주었습니당 |
||
runCatching { | ||
authDataSource.postSignup(requestPostSignUpDto).data | ||
} | ||
|
||
override suspend fun postSignin(requestPostSignInDto: RequestPostSignInDto): Result<ResponsePostSignInDto?> = | ||
runCatching { | ||
authDataSource.postSignIn(requestPostSignInDto).data | ||
} | ||
|
||
override fun setAutoLogin(isAutoLogin: Boolean) { | ||
localPrefDataSource.isAutoLogin = isAutoLogin | ||
sharedPrefDataSource.isAutoLogin = isAutoLogin | ||
} | ||
|
||
override fun getAutoLogin(): Boolean = localPrefDataSource.isAutoLogin | ||
override fun getAutoLogin(): Boolean = sharedPrefDataSource.isAutoLogin | ||
|
||
override fun setSignedUpUser(user: User) { | ||
localPrefDataSource.signedUpUser = user | ||
sharedPrefDataSource.signedUpUser = user | ||
} | ||
|
||
override fun getSignedUpUser(): User? = localPrefDataSource.signedUpUser | ||
override fun getSignedUpUser(): User? = sharedPrefDataSource.signedUpUser | ||
|
||
override fun clearLocalPref() { | ||
localPrefDataSource.clearLocalPref() | ||
sharedPrefDataSource.clearLocalPref() | ||
} | ||
} |
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() | ||
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. 오 처음부터 api url 에 page 숫자를 명시해준게 아닌, 인자로 받아서 여러 페이지 접근할 수 있도록 해주셨군요 짱이십니다 👍 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. 22 |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.android.go.sopt.data.service | ||
|
||
import org.android.go.sopt.data.entity.remote.request.RequestPostSignInDto | ||
import org.android.go.sopt.data.entity.remote.request.RequestPostSignUpDto | ||
import org.android.go.sopt.data.entity.remote.response.ResponsePostSignInDto | ||
import org.android.go.sopt.data.entity.remote.response.ResponsePostSignUpDto | ||
import org.android.go.sopt.data.entity.remote.response.wrapper.BaseResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthService { | ||
@POST("sign-up") | ||
suspend fun postSignUp( | ||
@Body requestPostSignUpDto: RequestPostSignUpDto, | ||
): BaseResponse<ResponsePostSignUpDto> | ||
|
||
@POST("sign-in") | ||
suspend fun postSignIn( | ||
@Body requestPostSignInDto: RequestPostSignInDto, | ||
): BaseResponse<ResponsePostSignInDto> | ||
} | ||
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. 오호 함수명이랑 Dto 클래스명에 어떤 HTTP 메서드를 사용하는지 명시해주니까 더 좋은 거 같아요! |
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") | ||
suspend fun getFollowerList( | ||
@Query("page") page: Int, | ||
): ResponseGetFollowerListDto | ||
} |
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.
DiffUtill에서 아이템을 비교할 때 혹시 명확한 식별을 위해서 id도 가져오는건가용? (뭔가 나의 말이 이상한데......)
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.
넵
areItemsTheSame
에서 id 값을 비교해주고 싶어서 가져왔습니다!