generated from AND-SOPT-ANDROID/and-sopt-android-template
-
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/#4] 4주차 필수과제 #9
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ce4217f
[add/#8] 서버통신 의존성 추가
SYAAINN 1875f18
[del/#8] 미사용하게 된 data class를 삭제합니다.
SYAAINN 8075f87
[chore/#8] 패키지 이름을 utils -> util로 변경합니다.
SYAAINN 265bb45
[feat/#8] 서버통신을 위한 dto를 생성합니다.
SYAAINN 7d6c91f
[chore/#8] localProperties 변수명을 수정합니다.
SYAAINN a99668b
[del/#8] 미사용 object를 삭제합니다.
SYAAINN 75e5dc5
[feat/#8] 서버통신 api를 구현합니다.
SYAAINN 376f458
[feat/#8] 서버통신 response에 대한 템플릿을 생성합니다.
SYAAINN 135e9ff
[feat/#8] 서버통신을 위한 retrofit 객체를 생성합니다.
SYAAINN d16061b
[feat/#8] 로그인 시 받은 token 값을 불러오는 dataSource를 구현합니다.
SYAAINN 98f2445
[feat/#8] token을 위한 repository를 생성합니다.
SYAAINN e1323ca
[feat/#8] 의존성 주입을 위한 module을 생성합니다.
SYAAINN e845e52
[feat/#8] 의존성 주입을 위한 module을 생성합니다.
SYAAINN 3ba2ba5
[add/#8] 마이페이지 서버통신 상태를 저장할 State를 생성합니다.
SYAAINN c08635f
[chore/#8] 서버통신에 맞추어 SignInState, SignUpState를 수정합니다.
SYAAINN bf155e7
[feat/#8] 서버통신 로직을 viewModel에 적용합니다.
SYAAINN 7e6b0c6
[refactor/#8] viewModel 선언 위치를 navHost 에서 Route 단으로 변경합니다.
SYAAINN c4f2044
[refactor/#8] navigate 함수를 상위 컴포저블로 이동합니다.
SYAAINN 35bed35
[refactor/#8] 바텀 네비게이션 구조를 수정합니다.
SYAAINN bf3dd10
[refactor/#8] clearInfo()를 token만 지우는 removeToken()으로 변경합니다.
SYAAINN 6e98a04
[move/#8] domain layer를 생성하고 패키지를 이동합니다.
SYAAINN a74daf4
[refactor/#8] TokenRepository를 수정합니다.
SYAAINN 188a9fa
[chore/#8] data layer의 model을 수정합니다.
SYAAINN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/org/sopt/and/data/local/TokenLocalDataSource.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,6 @@ | ||
package org.sopt.and.data.local | ||
|
||
interface TokenLocalDataSource { | ||
var token: String | ||
fun removeToken() | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/sopt/and/data/local/TokenLocalDataSourceImpl.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,20 @@ | ||
package org.sopt.and.data.local | ||
|
||
import android.content.SharedPreferences | ||
import javax.inject.Inject | ||
|
||
class TokenLocalDataSourceImpl @Inject constructor( | ||
private val sharedPreferences: SharedPreferences | ||
): TokenLocalDataSource { | ||
override var token: String | ||
get() = sharedPreferences.getString(TOKEN, "") ?: "" | ||
set(value) = sharedPreferences.edit().putString(TOKEN, value).apply() | ||
|
||
override fun removeToken() { | ||
sharedPreferences.edit().remove(TOKEN).apply() | ||
} | ||
|
||
companion object { | ||
private const val TOKEN = "TOKEN" | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/sopt/and/data/remote/model/base/ApiResponse.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 org.sopt.and.data.remote.model.base | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ApiResponse<T>( | ||
@SerialName("result") val result: T | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/org/sopt/and/data/remote/model/request/LoginRequestDto.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,10 @@ | ||
package org.sopt.and.data.remote.model.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LoginRequestDto( | ||
@SerialName("username") val username: String, | ||
@SerialName("password") val password: String, | ||
) |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/org/sopt/and/data/remote/model/request/UserRegistrationRequestDto.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,11 @@ | ||
package org.sopt.and.data.remote.model.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UserRegistrationRequestDto ( | ||
@SerialName("username") val username: String, | ||
@SerialName("password") val password: String, | ||
@SerialName("hobby") val hobby: String, | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/sopt/and/data/remote/model/response/GetMyHobbyResponseDto.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 org.sopt.and.data.remote.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class GetMyHobbyResponseDto( | ||
@SerialName("hobby") val hobby: String | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/sopt/and/data/remote/model/response/LoginResponseDto.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 org.sopt.and.data.remote.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class LoginResponseDto ( | ||
@SerialName("token") val token: String | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/sopt/and/data/remote/model/response/UserRegistrationResponseDto.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 org.sopt.and.data.remote.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class UserRegistrationResponseDto( | ||
@SerialName("no") val no: Int | ||
) |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/org/sopt/and/data/remote/service/AuthService.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,21 @@ | ||
package org.sopt.and.data.remote.service | ||
|
||
import org.sopt.and.data.remote.model.request.LoginRequestDto | ||
import org.sopt.and.data.remote.model.request.UserRegistrationRequestDto | ||
import org.sopt.and.data.remote.model.response.LoginResponseDto | ||
import org.sopt.and.data.remote.model.response.UserRegistrationResponseDto | ||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthService { | ||
@POST("user") | ||
fun registerUser( | ||
@Body userRegistrationRequestDto: UserRegistrationRequestDto | ||
): Call<UserRegistrationResponseDto> | ||
|
||
@POST("login") | ||
fun login( | ||
@Body loginRequestDto: LoginRequestDto | ||
): Call<LoginResponseDto> | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/sopt/and/data/remote/service/UserService.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 org.sopt.and.data.remote.service | ||
|
||
import org.sopt.and.data.remote.model.response.GetMyHobbyResponseDto | ||
import retrofit2.Call | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
|
||
interface UserService { | ||
@GET("user/my-hobby") | ||
fun getMyHobby( | ||
@Header("token") token: String | ||
): Call<GetMyHobbyResponseDto> | ||
} |
19 changes: 19 additions & 0 deletions
19
app/src/main/java/org/sopt/and/data/repositoryimpl/TokenRepositoryImpl.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,19 @@ | ||
package org.sopt.and.data.repositoryimpl | ||
|
||
import org.sopt.and.data.local.TokenLocalDataSource | ||
import org.sopt.and.domain.repository.TokenRepository | ||
import javax.inject.Inject | ||
|
||
class TokenRepositoryImpl @Inject constructor( | ||
private val tokenLocalDataSource: TokenLocalDataSource | ||
) : TokenRepository { | ||
override fun getToken(): String = tokenLocalDataSource.token | ||
|
||
override fun setToken(token: String) { | ||
tokenLocalDataSource.token = token | ||
} | ||
|
||
override fun removeToken() { | ||
tokenLocalDataSource.removeToken() | ||
} | ||
} |
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,38 @@ | ||
package org.sopt.and.di | ||
|
||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.sopt.and.BuildConfig | ||
import org.sopt.and.data.remote.service.AuthService | ||
import org.sopt.and.data.remote.service.UserService | ||
import retrofit2.Retrofit | ||
|
||
object ApiFactory { | ||
private const val BASE_URL: String = BuildConfig.BASE_URL | ||
|
||
private val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
} | ||
|
||
private val client = OkHttpClient.Builder() | ||
.addInterceptor(loggingInterceptor) | ||
.build() | ||
|
||
val retrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(client) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
} | ||
|
||
inline fun <reified T> create(): T = retrofit.create(T::class.java) | ||
} | ||
|
||
object ServicePool { | ||
val authService = ApiFactory.create<AuthService>() | ||
val userService = ApiFactory.create<UserService>() | ||
} |
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,19 @@ | ||
package org.sopt.and.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.domain.repository.TokenRepository | ||
import org.sopt.and.data.repositoryimpl.TokenRepositoryImpl | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class RepositoryModule { | ||
@Binds | ||
@Singleton | ||
abstract fun bindTokenRepository( | ||
tokenRepositoryImpl: TokenRepositoryImpl | ||
): TokenRepository | ||
} | ||
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/sopt/and/di/SharedPreferencesModule.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,20 @@ | ||
package org.sopt.and.di | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.android.qualifiers.ApplicationContext | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object SharedPreferencesModule { | ||
@Provides | ||
@Singleton | ||
fun provideSharedPreferences(@ApplicationContext context: Context): SharedPreferences { | ||
return context.getSharedPreferences("token_prefs", Context.MODE_PRIVATE) | ||
} | ||
} |
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,20 @@ | ||
package org.sopt.and.di | ||
|
||
import android.content.SharedPreferences | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.local.TokenLocalDataSource | ||
import org.sopt.and.data.local.TokenLocalDataSourceImpl | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object TokenLocalDataSourceModule { | ||
@Provides | ||
@Singleton | ||
fun provideTokenLocalDataSource(sharedPreferences: SharedPreferences): TokenLocalDataSource { | ||
return TokenLocalDataSourceImpl(sharedPreferences) | ||
} | ||
} |
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.sopt.and.domain | ||
|
||
data class User( | ||
val name: String, | ||
val password: String, | ||
val hobby: String | ||
) |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/org/sopt/and/domain/repository/TokenRepository.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.sopt.and.domain.repository | ||
|
||
interface TokenRepository { | ||
fun getToken(): String | ||
fun setToken(token: String) | ||
fun removeToken() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@Bind @provide 의 차이를 알고 계신가요 ?