-
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
[FEAT/#10] 6주차 필수 과제 #11
base: develop
Are you sure you want to change the base?
Changes from all commits
afb7302
d04a893
445350c
3d0c989
f208a23
ca58023
1b58cf5
d40f648
f2267b7
0c86067
b0fb4b2
8ce0128
b1f252e
a19e632
fc3c526
584d977
bc20526
98dea2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.sopt.and.core.data.datasource | ||
|
||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.response.GetHobbyResponse | ||
|
||
interface HobbyDataSource { | ||
suspend fun getHobby( | ||
token: String | ||
): BaseResponse<GetHobbyResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.sopt.and.core.data.datasource | ||
|
||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.reqeust.LoginRequest | ||
import org.sopt.and.core.data.dto.response.LoginResponse | ||
|
||
interface SignInDataSource { | ||
suspend fun postSignIn( | ||
request: LoginRequest | ||
): BaseResponse<LoginResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.sopt.and.core.data.datasource | ||
|
||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.reqeust.CreateUserRequest | ||
import org.sopt.and.core.data.dto.response.CreateUserResponse | ||
|
||
interface SignUpDataSource { | ||
suspend fun postSignUp( | ||
request: CreateUserRequest | ||
): BaseResponse<CreateUserResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.sopt.and.core.data.datasourceimpl | ||
|
||
import org.sopt.and.core.data.datasource.HobbyDataSource | ||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.response.GetHobbyResponse | ||
import org.sopt.and.core.data.service.HobbyService | ||
|
||
class HobbyDataSourceImpl( | ||
private val hobbyService: HobbyService | ||
) : HobbyDataSource { | ||
override suspend fun getHobby(token: String): BaseResponse<GetHobbyResponse> = hobbyService.getMyHobby(token) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.and.core.data.datasourceimpl | ||
|
||
import org.sopt.and.core.data.datasource.SignInDataSource | ||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.reqeust.LoginRequest | ||
import org.sopt.and.core.data.dto.response.LoginResponse | ||
import org.sopt.and.core.data.service.SignInService | ||
|
||
|
||
class SignInDataSourceImpl( | ||
private val signInService: SignInService | ||
) : SignInDataSource { | ||
override suspend fun postSignIn(request: LoginRequest): BaseResponse<LoginResponse> = signInService.login(request) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.sopt.and.core.data.datasourceimpl | ||
|
||
import org.sopt.and.core.data.datasource.SignUpDataSource | ||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.reqeust.CreateUserRequest | ||
import org.sopt.and.core.data.dto.response.CreateUserResponse | ||
import org.sopt.and.core.data.service.SignUpService | ||
|
||
class SignUpDataSourceImpl( | ||
private val signUpService: SignUpService | ||
) : SignUpDataSource { | ||
override suspend fun postSignUp(request: CreateUserRequest): BaseResponse<CreateUserResponse> = signUpService.signUp(request) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package org.sopt.and.core.data.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BaseResponse <T> ( | ||
val status: Int, | ||
val message: String, | ||
val data: T? = null | ||
@SerialName("result") | ||
val result: T | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,6 @@ import kotlinx.serialization.Serializable | |
|
||
@Serializable | ||
data class CreateUserResponse( | ||
@SerialName("result") | ||
val result: Result | ||
) { | ||
@Serializable | ||
data class Result( | ||
@SerialName("no") | ||
val no: Int | ||
) | ||
} | ||
@SerialName("no") | ||
val userId: Int | ||
Comment on lines
+8
to
+9
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,14 @@ | ||
package org.sopt.and.core.data.repositoryimpl | ||
|
||
import org.sopt.and.core.data.datasource.HobbyDataSource | ||
import org.sopt.and.core.data.dto.response.GetHobbyResponse | ||
import org.sopt.and.domain.entity.HobbyData | ||
import org.sopt.and.domain.entity.SignInData | ||
import org.sopt.and.domain.repository.HobbyRepository | ||
|
||
class HobbyRepositoryImpl(private val hobbyDataSource: HobbyDataSource) : HobbyRepository { | ||
override suspend fun getHobby(token: String): Result<HobbyData> = runCatching { | ||
val response = hobbyDataSource.getHobby(token) | ||
HobbyData(response.result.hobby) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.sopt.and.core.data.repositoryimpl | ||
|
||
import org.sopt.and.core.data.datasource.SignInDataSource | ||
import org.sopt.and.core.data.dto.reqeust.LoginRequest | ||
import org.sopt.and.domain.entity.SignInData | ||
import org.sopt.and.domain.repository.SignInRepository | ||
|
||
class SignInRepositoryImpl(private val signInDataSource: SignInDataSource) : SignInRepository { | ||
override suspend fun signIn(username: String, password: String): Result<SignInData> = runCatching { | ||
val response = signInDataSource.postSignIn(LoginRequest(username, password)) | ||
SignInData(response.result.token) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.and.core.data.repositoryimpl | ||
|
||
import org.sopt.and.core.data.datasource.SignUpDataSource | ||
import org.sopt.and.core.data.dto.reqeust.CreateUserRequest | ||
import org.sopt.and.core.data.dto.response.CreateUserResponse | ||
import org.sopt.and.domain.entity.SignUpData | ||
import org.sopt.and.domain.repository.SignUpRepository | ||
|
||
class SignUpRepositoryImpl(private val signUpDataSource: SignUpDataSource) : SignUpRepository { | ||
override suspend fun signUp(username: String, password: String, hobby: String): Result<SignUpData> = runCatching { | ||
val response = signUpDataSource.postSignUp(CreateUserRequest(username, password, hobby)) | ||
SignUpData(response.result.userId) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.sopt.and.core.data.service | ||
|
||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.response.GetHobbyResponse | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
|
||
interface HobbyService { | ||
@GET("user/my-hobby") | ||
suspend fun getMyHobby( | ||
@Header("token") token: String | ||
): BaseResponse<GetHobbyResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.sopt.and.core.data.service | ||
|
||
import org.sopt.and.network.RetrofitInstance | ||
|
||
object ServicePool { | ||
val signInService: SignInService = RetrofitInstance.create<SignInService>() | ||
val signUpService: SignUpService = RetrofitInstance.create<SignUpService>() | ||
val hobbyService: HobbyService = RetrofitInstance.create<HobbyService>() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.and.core.data.service | ||
|
||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.reqeust.LoginRequest | ||
import org.sopt.and.core.data.dto.response.LoginResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface SignInService { | ||
@POST("login") | ||
suspend fun login( | ||
@Body request: LoginRequest | ||
): BaseResponse<LoginResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.and.core.data.service | ||
|
||
import org.sopt.and.core.data.dto.BaseResponse | ||
import org.sopt.and.core.data.dto.reqeust.CreateUserRequest | ||
import org.sopt.and.core.data.dto.response.CreateUserResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface SignUpService { | ||
@POST("user") | ||
suspend fun signUp( | ||
@Body request: CreateUserRequest | ||
): BaseResponse<CreateUserResponse> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.sopt.and.core.util | ||
|
||
import android.content.Context | ||
import retrofit2.HttpException | ||
import org.sopt.and.R | ||
|
||
interface ErrorHandler { | ||
fun handleNetworkError(exception: Throwable?): String | ||
} | ||
|
||
class DefaultErrorHandler(private val context: Context) : ErrorHandler { | ||
override fun handleNetworkError(exception: Throwable?): String { | ||
return when (exception) { | ||
is HttpException -> when (exception.code()) { | ||
400 -> context.getString(R.string.network_error_400) | ||
403 -> context.getString(R.string.network_error_403) | ||
409 -> context.getString(R.string.network_error_409) | ||
else -> context.getString(R.string.network_error) | ||
} | ||
else -> context.getString(R.string.network_error) | ||
} | ||
} | ||
} | ||
Comment on lines
+11
to
+23
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. DefaultErrorHandler 좋네요 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,5 @@ | ||
package org.sopt.and.domain.entity | ||
|
||
data class HobbyData( | ||
val hobby: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.sopt.and.domain.entity | ||
|
||
data class SignInData( | ||
val token: String | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.sopt.and.domain.entity | ||
|
||
data class SignUpData( | ||
val userId: Int | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.core.data.dto.response.GetHobbyResponse | ||
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. 이 부분도 안쓰는 import인 것 같아용 |
||
import org.sopt.and.domain.entity.HobbyData | ||
|
||
interface HobbyRepository { | ||
suspend fun getHobby(token: String): Result<HobbyData> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.core.data.datasourceimpl.HobbyDataSourceImpl | ||
import org.sopt.and.core.data.datasourceimpl.SignInDataSourceImpl | ||
import org.sopt.and.core.data.datasourceimpl.SignUpDataSourceImpl | ||
import org.sopt.and.core.data.repositoryimpl.HobbyRepositoryImpl | ||
import org.sopt.and.core.data.repositoryimpl.SignInRepositoryImpl | ||
import org.sopt.and.core.data.repositoryimpl.SignUpRepositoryImpl | ||
import org.sopt.and.core.data.service.ServicePool | ||
|
||
object RepositoryPool { | ||
val hobbyRepository: HobbyRepository by lazy { | ||
HobbyRepositoryImpl(HobbyDataSourceImpl(ServicePool.hobbyService)) | ||
} | ||
|
||
val signInRepository: SignInRepository by lazy { | ||
SignInRepositoryImpl(SignInDataSourceImpl(ServicePool.signInService)) | ||
} | ||
|
||
val signUpRepository: SignUpRepository by lazy { | ||
SignUpRepositoryImpl(SignUpDataSourceImpl(ServicePool.signUpService)) | ||
} | ||
} | ||
Comment on lines
+11
to
+23
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. 이런 식으로 의존성 주입 로직에 관련된 코드는, viewmodelfactory라는 이름으로 생성해줘도 될 것 같아요 ~ 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. domain 레이어에는 다른 계층, 또는 서드파티 관련 import는 없어야한다고 알고있어용 RepositoryPool을 다른 곳으로 옮기는게 어떨까요! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.domain.entity.SignInData | ||
|
||
interface SignInRepository { | ||
suspend fun signIn(username: String, password: String): Result<SignInData> | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.core.data.dto.response.CreateUserResponse | ||
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. data 레이어 관련 import가 있어서 봤더니, 이 코드에서는 안 쓰이는 import인 것 같네요! 지워줍시다 ~ |
||
import org.sopt.and.domain.entity.SignUpData | ||
|
||
interface SignUpRepository { | ||
suspend fun signUp(username: String, password: String, hobby: String): Result<SignUpData> | ||
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. request에 들어가는 부분도, model을 하나 생성해서 써줘도 좋을 것 같아요 ! |
||
} |
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.
BaseResponse 수정 굿 ~