-
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주차 과제 #8
base: develop
Are you sure you want to change the base?
Changes from all commits
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,7 @@ | ||
package org.sopt.and.data.datalocal.datasource | ||
|
||
interface UserInfoLocalDataSource { | ||
var accessToken: String | ||
var nickname: String | ||
fun clear() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import androidx.core.content.edit | ||
import org.sopt.and.data.datalocal.datasource.UserInfoLocalDataSource | ||
|
||
class UserInfoLocalDataSourceImpl(context: Context) : UserInfoLocalDataSource { | ||
|
||
private val sharedPreferences: SharedPreferences = | ||
context.getSharedPreferences(PREFERENCES_NAME, Context.MODE_PRIVATE) | ||
|
||
override var accessToken: String | ||
get() = sharedPreferences.getString(TOKEN, INITIAL_VALUE).toString() | ||
set(value) = sharedPreferences.edit { putString(TOKEN, value) } | ||
|
||
override var nickname: String | ||
get() = sharedPreferences.getString(NICKNAME, INITIAL_VALUE).toString() | ||
set(value) = sharedPreferences.edit { putString(NICKNAME, value) } | ||
|
||
override fun clear() = sharedPreferences.edit { clear() } | ||
|
||
companion object { | ||
const val PREFERENCES_NAME = "user_preferences" | ||
const val TOKEN = "token" | ||
const val NICKNAME = "nickname" | ||
const val INITIAL_VALUE = "" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.and.data.model.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestLoginDto( | ||
@SerialName("username") | ||
val username: String, | ||
@SerialName("password") | ||
val password: String | ||
) | ||
|
||
|
||
Comment on lines
+13
to
+14
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. 2줄 ! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.sopt.and.data.model.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestSignUpDto( | ||
@SerialName("username") | ||
val username: String, | ||
@SerialName("password") | ||
val password: String, | ||
@SerialName("hobby") | ||
val hobby: String | ||
) |
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에 해당하는 부분 data class를 아예 외부에 분리해서 짰었는데 뭔가 기능상에 차이점이 있나요?? 이 방식이 가독성 측면에선 훨씬 좋은 것 같아보이네요 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.sopt.and.data.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
|
||
Comment on lines
+5
to
+6
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. 2줄 ! |
||
@Serializable | ||
data class ResponseLoginDto( | ||
@SerialName("result") | ||
val result: Result | ||
) { | ||
Comment on lines
+7
to
+11
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. 해당 부분이 계속 공통되는 것 같은데 BaseResponse를 사용하시는 것도 방법이 될 것 같네요! |
||
@Serializable | ||
data class Result( | ||
@SerialName("token") | ||
val token: String | ||
) | ||
} |
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를 아예 밖에 분리하는 거랑 앞처럼 본문 안에 써주는거랑 차이점이 있는지 궁금합니다!! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.sopt.and.data.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseMyHobbyDto( | ||
@SerialName("result") | ||
val result: Result? = null, | ||
@SerialName("code") | ||
val code: String? = null | ||
) | ||
|
||
@Serializable | ||
data class Result( | ||
@SerialName("hobby") | ||
val hobby: String | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.sopt.and.data.model.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseFailedDto( | ||
@SerialName("code") | ||
val code: String | ||
) | ||
|
||
@Serializable | ||
data class ResponseSignUpDto( | ||
@SerialName("result") | ||
val result: Result | ||
) { | ||
@Serializable | ||
data class Result( | ||
@SerialName("no") | ||
val no: Int | ||
) | ||
} | ||
|
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. 저도 Gson사용으로 바꿔봐야 겠어요 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.sopt.and.data.service | ||
|
||
import org.sopt.and.BuildConfig | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
object RetrofitInstance { | ||
private const val BASE_URL = BuildConfig.BASE_URL | ||
|
||
private val retrofit: Retrofit by lazy { | ||
Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
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. 왜 Gson을 사용하신 건지 여쭤봐두 되나염? |
||
.build() | ||
} | ||
|
||
val userService: UserService by lazy { | ||
retrofit.create(UserService::class.java) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.sopt.and.data.service | ||
|
||
import org.sopt.and.data.model.request.RequestLoginDto | ||
import org.sopt.and.data.model.request.RequestSignUpDto | ||
import org.sopt.and.data.model.response.ResponseLoginDto | ||
import org.sopt.and.data.model.response.ResponseMyHobbyDto | ||
import org.sopt.and.data.model.response.ResponseSignUpDto | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
import retrofit2.http.POST | ||
|
||
|
||
interface UserService { | ||
@POST("/user") | ||
suspend fun postSignup(@Body requestDto: RequestSignUpDto): Response<ResponseSignUpDto> | ||
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. 응답 타입이 늘 ResponseSignUpDto로 설정되어 있는데, 응답이 실패한 경우에는 어떻게 FailedDTO를 반환할 수 있는 건가요?? 저도 성공/실패 DTO를 구분했었는데, 이 부분에 반환값을 늘 성공한 경우 DTO로 줘도 되는 건지 헷갈리더라구요 .. |
||
|
||
@POST("/login") | ||
suspend fun postLogin(@Body requestDto: RequestLoginDto): Response<ResponseLoginDto> | ||
|
||
|
||
@GET("/user/my-hobby") | ||
suspend fun getUserHobby( | ||
@Header("token") token: String | ||
): Response<ResponseMyHobbyDto> | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ package org.sopt.and.domain | |
|
||
data class User( | ||
var email: String = "", | ||
var password: String = "" | ||
var password: String = "", | ||
var hobby: String = "" | ||
Comment on lines
4
to
+6
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. var로 선언하신 이유가 있나요? |
||
) |
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.
bundle을 사용해보셔도 좋을 것 같슴다 ~