-
Notifications
You must be signed in to change notification settings - Fork 5
[Week9] Jamie #42
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
base: main
Are you sure you want to change the base?
[Week9] Jamie #42
Conversation
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.
์๋ ๋ฆฌ๋ทฐ๋ค ํ์ธํด๋ณด์๊ณ ๋ค์ ๊ตฌํํ ํ ๋ฆฌ๋ทฐ์ด ์ฌํธ์ถ ํด์ฃผ์ธ์~
์ถ๊ฐ๋ก ํ์ฌ ์ฐ๊ฒฐํ๋ ์๋ฒ์ ์ฃผ์๊ฐ http://~๋ก ์์ํ๋๋ฐ ์๋๋ก์ด๋์์๋ https ํ๋กํ ์ฝ์ด ์๋ ๊ฒฝ์ฐ ๊ธฐ๋ณธ์ ์ผ๋ก ์๋์ ๊ฐ์ ์๋ฌ ๋ฉ์์ง๋ก ํต์ ์ด ๋ถ๊ฐ๋ฅํ๊ฒ ๋์ด์์ต๋๋ค.
SIGNUP/FAILURE CLEARTEXT communication to 3.35.121.185 not permitted by network security policyhttp ํ๋กํ ์ฝ ํต์ ์ ํ์ฉํด์ฃผ๋ ค๋ฉด manifest ํ์ผ์ <application ~~ > ๋ถ๋ถ์ networkSecurityConfig ์์ฑ์ ์ ์ํด์ฃผ๊ณ usesCleartextTraffic ์์ฑ์ true๋ก ์ค์ ํด์ผ ํฉ๋๋ค. ์์ธํ ๋ฐฉ์์ ๋งํฌ๋ฅผ ์ฐธ๊ณ ํด์ ์์ ํด์ฃผ์ธ์!
| val migration_1_2 = object : Migration(1, 2) { | ||
| override fun migrate(database: SupportSQLiteDatabase) { | ||
| database.execSQL( | ||
| "ALTER TABLE UserTable Add COLUMN isChecked INTEGER NOT NULL DEFAULT 0" | ||
| ) | ||
| } | ||
|
|
||
| } | ||
| if (instance == null) { | ||
| synchronized(SongDatabase::class) { | ||
| instance = Room.databaseBuilder( | ||
| context.applicationContext, | ||
| SongDatabase::class.java, | ||
| "song-database" | ||
| ).addMigrations(migration_1_2).build() |
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.
PR ๋ด์ฉ์ ์ ์ด์ฃผ์ ๋ฌธ์ ๋ Migration์ ์คํํ๋ ์ฟผ๋ฆฌ๋ฌธ์ด ์๋ชป๋์ด์ ์๊ธด ์ค๋ฅ ๊ฐ๋ค์. ์ด์ UserTable์ ์คํค๋ง๋ email๊ณผ password ์ปฌ๋ผ๋ง ์์๋ค๋ฉด ์๋ก migrationํด ์ค ์คํค๋ง์๋ name ์ปฌ๋ผ์ด ์ถ๊ฐ๋ ๊ฒ์ด๊ธฐ ๋๋ฌธ์ ์คํํ sql๋ฌธ์ด isChecked๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด ์๋๋ผ name ์ปฌ๋ผ์ ์ถ๊ฐํ๋ ์ฟผ๋ฆฌ๋ฌธ์ผ๋ก ์์ฑํด์ฃผ์ ์ผํด์!
Name ์ปฌ๋ผ์ ์ถ๊ฐํ์ค ๋๋ ์ ์ํ์ User์ Entity ํด๋์ค์ ๋์ผํ๊ฒ (nullable์ด๋ผ๋์ง ๊ธฐ๋ณธ ๊ฐ์ด ์๋ค๋์ง ๋ฑ) ์ค์ ํด์ฃผ์ ์ผ ํ๋๋ฐ ์ด๋ ๋ง์ฝ ์ด๋ฏธ version1์ UserTable์ ๋ฐ์ดํฐ๊ฐ ๋ค์ด๊ฐ ์๊ณ default value๋ฅผ ์ค์ ํ์ง ์๊ณ ์ถ๊ฐํ๋ค๋ฉด ์๋กญ๊ฒ ์ถ๊ฐํ๋ ์ปฌ๋ผ์ ๋ํ ๋ฐ์ดํฐ๊ฐ ์๋์ผ๋ก Null๊ฐ์ด ์ค์ ๋๊ฒ ๋ฉ๋๋ค. ์ฌ๊ธฐ์ ๋ด๊ฐ ์ถ๊ฐํ๊ณ ์ ํ๋ ์ปฌ๋ผ์ nullable ์์ฑ์ด false๋ผ๋ฉด ๋ง์ด๊ทธ๋ ์ด์ ํ ๋ default value๋ฅผ ์ค์ ํด์ค์ผ ์ค๋ฅ๊ฐ ๋์ง ์์ ๊ฑฐ์์!
์ด์๋ ๋ณ๊ฐ๋ก ์ฑ์ ์ ์์ผ๋ก ์ถ์ํ๊ธฐ ์ ๊น์ง๋ RoomDB์ ์คํค๋ง๊ฐ ๋ณ๊ฒฝ๋๋ค๊ณ ํด์ version์ ์ฌ๋ฆฌ๋ค๋ณด๋ฉด ๋๋ ์์ด ์ฌ๋ผ๊ฐ ๊ฐ๋ฅ์ฑ์ด ๋๊ธฐ ๋๋ฌธ์ ๋ฒ์ ์ ์ ๋ฐ์ดํธํ์ง ์๊ณ ์คํํ๊ณ ์ถ์ผ์ค ๊ฒฝ์ฐ ์ ๋ฎฌ๋ ์ดํฐ์์ ์ฑ์ ์ญ์ ํ ๋ค์ ์คํํด์ฃผ์๋ฉด ๋ฒ์ ์ ๋ฐ์ดํธ ์์ด๋ ์๋ก์ด ์คํค๋ง๋ก RoomDB๊ฐ ์ค์ ๋ฉ๋๋ค!
| override fun onResponse(call: Call<AuthResponse>, response: Response<AuthResponse>) { | ||
| Log.d("SIGNUP/SUCCESS", response.toString()) | ||
|
|
||
| val resp: AuthResponse = response.body()!! | ||
| when(resp.code){ | ||
| 200->signUpView.onSignUpSuccess() | ||
| else->signUpView.onSignUpFailure() | ||
| } | ||
|
|
||
| } |
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.
ํ์๊ฐ์ ๊ณผ์ ์์ ์ค๋ณต ์ด๋ฉ์ผ๋ก ํ์๊ฐ์ ์ ์๋ํ์ ๋ ํ์ฌ 36๋ฒ์งธ ์ค ์ฝ๋์์ body๋ฅผ ์ฐพ์ ์ ์๋ค๋ ์๋ฌ๊ฐ ๋ฐ์ํ๊ณ ์์ต๋๋ค. ์ด์ ๊ด๋ จํ ๋ก๊ทธ๋ค์ ์ดํด๋ณด๋ฉด
34๋ฒ์งธ ์ค์ ์ฝ๋๋ก ์ฐํ๋ ๋ก๊ทธ
SIGNUP/SUCCESS com.example.flo_clone D Response{protocol=http/1.1, code=401, message=, url=http://3.35.121.185/login}(์ฌ์ค ํ์๊ฐ์ ์ ํธ์ถ๋์ด์ผ ํ api๋ /signup์ ํด๋นํ๋ api๊ฐ ํธ์ถ๋์ด์ผ ํ๋๋ฐ ์ด ๋ถ๋ถ์ ์ ๋ฒ ์คํฐ๋ ์๊ฐ์ ๋ง์๋๋ฆฐ ๋ถ๋ถ์ด๋ผ ์์ ํ์๋ฉด์ ํธ์ถํ๋ endpoint๋ ์์ ํด์ฃผ์๋ฉด ๋ ๊ฒ ๊ฐ์์!)
okHttp์ ๋ก๊น ์ธํฐ์ ํฐ๋ก ์ฐํ๋ ๋ก๊ทธ (์ค์ api ํต์ ๊ฒฐ๊ณผ Http message์ ํด๋นํ๋ ๋ก๊ทธ๋ผ๊ณ ์๊ฐํ์๋ฉด ๋๊ณ okHttp์ ๋ก๊น ์ธํฐ์ ํฐ๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด retrofit์ client๋ก ์ค์ ํด์ฃผ์๋ฉด ๋ฉ๋๋ค. ์ด ๋ถ๋ถ์ ๊ตฌ๊ธ๋งํ๋ฉด ์์ธํ ๋ฐฉ๋ฒ์ ์ฝ๊ฒ ์ฐพ์ ์ ์์ด ๋ฐ๋ก ๋งํฌ๋ ์ฒจ๋ถํ์ง ์์์ต๋๋ค.)
okhttp.OkHttpClient com.example.flo_clone I <-- 401 http://3.35.121.185/login (57ms)
okhttp.OkHttpClient com.example.flo_clone I X-Content-Type-Options: nosniff
okhttp.OkHttpClient com.example.flo_clone I X-XSS-Protection: 0
okhttp.OkHttpClient com.example.flo_clone I Cache-Control: no-cache, no-store, max-age=0, must-revalidate
okhttp.OkHttpClient com.example.flo_clone I Pragma: no-cache
okhttp.OkHttpClient com.example.flo_clone I Expires: 0
okhttp.OkHttpClient com.example.flo_clone I X-Frame-Options: DENY
okhttp.OkHttpClient com.example.flo_clone I Content-Type: application/json;charset=UTF-8
okhttp.OkHttpClient com.example.flo_clone I Content-Length: 86
okhttp.OkHttpClient com.example.flo_clone I Date: Thu, 05 Dec 2024 10:38:08 GMT
okhttp.OkHttpClient com.example.flo_clone I Keep-Alive: timeout=60
okhttp.OkHttpClient com.example.flo_clone I Connection: keep-alive
okhttp.OkHttpClient com.example.flo_clone I {"isSuccess":false,"code":"AUTH_005","message":"์ ์ ์ธ์ฆ์ ์คํจํ์ต๋๋ค."}
okhttp.OkHttpClient com.example.flo_clone I <-- END HTTP (86-byte body)์ค์ ํต์ ๊ฒฐ๊ณผ๋ก ์ฐํ๋ ๋ก๊ทธ๋ฅผ ๋ด๋ณด๋ฉด ๋ถ๋ช body ๋ถ๋ถ์ ํด๋นํ๋ ์๋ต์ด ์๋ ๊ฒ ๊ฐ์๋ฐ ์ body๋ฅผ ์ฐพ์ ์ ์๋ค๊ณ ํ๋ ๊ฒ์ผ๊น์?
์ด ๋ถ๋ถ์ 34๋ฒ์งธ ์ค์ ์ฝ๋๋ก ์ฐํ๋ ๋ก๊ทธ์ code๊ฐ์ ํ์ธํด๋ณด๋ฉด 401๋ก ์ค์ ๋์ด์๋ ๊ฒ๊ณผ ๊ด๋ จ์ด ์์ต๋๋ค. Retrofit2์์ ์ ๊ณตํ๋ Response ๊ฐ์ฒด๋ ์ด code ๊ฐ์ ๋ฐ๋ผ ์ฑ๊ณต ์๋ต์ ํด๋นํ๋์ง ์๋ฌ ์๋ต์ ํด๋นํ๋์ง๋ฅผ ๋ถ๋ฅํ์ฌ ๊ฐ๊ธฐ ๋ค๋ฅด๊ฒ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํํฉ๋๋ค.
์๋ ์ฌ์ง์ Retrofit2 ํด๋์ค์์ ๊ตฌํํ Response ํด๋์ค์ ์ผ๋ถ๋ฅผ ๊ฐ๊ณ ์จ ๊ฒ์
๋๋ค.


๊ฐ๋จํ ์ค๋ช
ํ์๋ฉด, Retrofit2๋ฅผ ์ด์ฉํ์ฌ http ํ๋กํ ์ฝ ํต์ ์ ํ ๊ฒฐ๊ณผ๋ฅผ ์ฒ๋ฆฌํ ๋ ์ฑ๊ณต ์ฝ๋์ ํด๋นํ ๊ฒฝ์ฐ์๋ ์ฒซ ๋ฒ์งธ ํจ์์ ๊ฒฐ๊ณผ๊ฐ ํด๋น api ํธ์ถ์ ๋ํ ๊ฒฐ๊ณผ Response ๊ฐ์ฒด๋ก ์ค์ ๋๊ณ , ์คํจ ์ฝ๋์ ํด๋นํ ๊ฒฝ์ฐ์๋ ๋ ๋ฒ์งธ ํจ์์ ๊ฒฐ๊ณผ๊ฐ ํด๋น api ํธ์ถ์ ๋ํ ๊ฒฐ๊ณผ Response ๊ฐ์ฒด๋ก ์ค์ ๋ฉ๋๋ค.
๊ฐ ํจ์์ ๋ฐํ๋ถ๋ถ์ ๋ณด๋ฉด success ํจ์์์๋ 2๋ฒ์งธ ์ธ์์ body๊ฐ ์ค์ ๋๊ณ , error ํจ์์์๋ 3๋ฒ์งธ ์ธ์์ body๊ฐ ์ค์ ๋๋ ๊ฒ์ ์ ์ ์์ต๋๋ค. ์ด๋ ์ฑ๊ณต ์๋ต์ ๋ํ body๋ response.body()๋ฅผ ํตํด ์ ๊ทผํ ์ ์์ง๋ง ์คํจ ์๋ต์ ๋ํ body๋ response.errorBody()๋ฅผ ํตํด ์ ๊ทผํด์ผํจ์ ์๋ฏธํฉ๋๋ค.
์ด์ ํด๋น ์ฝ๋๋ฅผ ์๋์ ๊ฐ์ด ๋ฐ๊พธ์ด์ ๋ก๊ทธ๋ฅผ ํ์ธํด๋ณด๋ฉด
override fun onResponse(call: Call<AuthResponse>, response: Response<AuthResponse>) {
Log.d("SIGNUP/SUCCESS", response.toString())
val errBody = response.errorBody()?.string()
val gson = Gson()
val resp2 = gson.fromJson(errBody, AuthResponse::class.java)
Log.d("SIGNUP/FAILURE", resp2.toString())
}์ด๋ ๊ฒ ์๋ต ๋ก๊ทธ๊ฐ ์ ์ฐํ๋ ๊ฒ์ ํ์ธํ ์ ์์ต๋๋ค!

์์ Retrofit2์์ http ์๋ต์ ์ด๋ป๊ฒ ์ฒ๋ฆฌํ๋์ง๋ฅผ ์ ๋๋ก ์ดํดํ ํ์ ์ฑ๊ณต ์๋ต์ ๋ํ ์ฒ๋ฆฌ์ ์์ธ ์ฒ๋ฆฌ ๋ก์ง์ ์์ ํด๋ณด์๋ฉด ์ข์ ๊ฒ ๊ฐ์์! (์ถ๊ฐ๋ก ํ์ฌ ์๋ฒ์์ ์ ๊ณตํ๋ api ๋ช ์ธ๋ฅผ ํ์ธํด๋ณด๋ฉด code๊ฐ์ด String์ผ๋ก ์ค๊ณ ์๊ธฐ ๋๋ฌธ์ AuthResponse ์ ์๋ ์์ ํด์ฃผ์ ์ผ ํฉ๋๋ค!)
๐ ์ด์ ๋ฒํธ
๐ป ์์ ๋ด์ฉ
๐ข ๊ธฐํ ์ฌํญ