Skip to content
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/week4 essential #9

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
22 changes: 21 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.20'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
android {
namespace 'org.sopt.dosopttemplate'
compileSdk 33
Expand All @@ -16,10 +18,15 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField "String", "REQRES_BASE_URL", properties["reqres.base.url"]
buildConfigField "String", "AUTH_BASE_URL", properties["base.url"]


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ‚­μ œν•΄μ£Όμ„Έμš”~

}
buildFeatures {
viewBinding true
dataBinding true
buildConfig true
}
buildTypes {
release {
Expand Down Expand Up @@ -49,4 +56,17 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0'

// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.10.0"))

// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")

implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
}
20 changes: 11 additions & 9 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand All @@ -11,22 +11,24 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.DoSoptTemplate"
tools:targetApi="31">
tools:targetApi="31"
android:usesCleartextTraffic="true">
<activity
android:name=".presentation.login.LoginActivity"
android:exported="false">
android:exported="true">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".presentation.signup.SingUpActivity"
android:exported="false"></activity>
android:exported="false">
</activity>
<activity
android:name=".presentation.home.HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
android:exported="false">
</activity>
<activity
android:name=".presentation.editMyPage.EditMyPageActivity"
Expand Down
49 changes: 49 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/API/APIFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.sopt.dosopttemplate.API

import android.util.Log
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import kotlinx.serialization.json.Json
import okhttp3.Interceptor
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.sopt.dosopttemplate.BuildConfig
import retrofit2.Retrofit

object ApiFactory {
lateinit var url: String
private fun getLogOkHttpClient(): Interceptor {
val loggingInterceptor = HttpLoggingInterceptor { message ->
Log.d("Retrofit2", "CONNECTION INFO -> $message")
}
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
return loggingInterceptor
}

val okHttpClient = OkHttpClient.Builder()
.addInterceptor(getLogOkHttpClient())
.build()

val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(url)
.client(okHttpClient)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}

inline fun <reified T> create(url: String): T {
this.url = url
return retrofit.create<T>(T::class.java)
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url생성을 κ΅¬λΆ„ν•˜μ—¬ μƒμ„±ν•˜λŠ”κ±° 쒋은거 κ°™μŠ΅λ‹ˆλ‹€!

}

object ServicePool {
private const val BASE_URL = BuildConfig.AUTH_BASE_URL
private const val REQRES_BASE_URL = BuildConfig.REQRES_BASE_URL

val authService = ApiFactory.create<AuthService>(BASE_URL)
val followerService = ApiFactory.create<FollowerService>(REQRES_BASE_URL)
}


19 changes: 19 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/API/AuthService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.sopt.dosopttemplate.API

import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST

interface AuthService {
@POST("api/v1/members/sign-in")
fun login(
@Body request: RequestLoginDto,
): Call<ResponseLoginDto>

@POST("api/v1/members")
fun signUp(
@Body request: RequestSignUpDto,
): Call<Unit>
}


10 changes: 10 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/API/FollowerService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.dosopttemplate.API

import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET

interface FollowerService {
@GET("https://reqres.in/api/users?page=2")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μ™œ 여기에 url이 μ „λΆ€ λ“€μ–΄κ°”μ„κΉŒμš”?
Base url λ”°λ‘œ λΆ„λ¦¬ν•΄μ£Όμ„Έμš”!

? 이 μžˆλŠ” 경우 μ‚¬μš©ν•˜λŠ” μ–΄λ…Έν…Œμ΄μ…˜μ΄ μžˆμŠ΅λ‹ˆλ‹€. μ§€κΈˆμ€ 2번 νŽ˜μ΄μ§€λ§Œ κ³ μ •μœΌλ‘œ λ°›μ•„μ˜€κ³  μžˆλ„€μš”!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ„€μ—‘...!

fun getFollowerList(): Call<ResponseGetFollwerDto>
}
12 changes: 12 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/API/RequestLoginDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.dosopttemplate.API

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestLoginDto(
@SerialName("username")
val username: String,
@SerialName("password")
val password: String,
)
14 changes: 14 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/API/RequestSignUpDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.dosopttemplate.API

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestSignUpDto(
@SerialName("username")
val username: String,
@SerialName("nickname")
val nickname: String,
@SerialName("password")
val password: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.sopt.dosopttemplate.API

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseData(
@SerialName("id")
val id: Int,
@SerialName("email")
val email: String,
@SerialName("first_name")
val first_name: String,
@SerialName("last_name")
val last_name: String,
@SerialName("avatar")
val avatar: String,
)

@Serializable
data class ResponseSupport(
@SerialName("url")
val url: String,
@SerialName("text")
val text: String
)

@Serializable
data class ResponseGetFollwerDto(
@SerialName("page")
val page: Int,
@SerialName("per_page")
val per_page: Int,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Camel, snake 쀑 ν•˜λ‚˜λ§Œ κ³¨λΌμ„œ μ μš©ν•΄λ³ΌκΉŒμš”? λ‹€λ₯Έ data classλŠ” μΉ΄λ©œμ΄λ„€μš”!

@SerialName("total")
val total: Int,
@SerialName("total_pages")
val total_pages: Int,
@SerialName("data")
val data: List<ResponseData>,
@SerialName("support")
val support: ResponseSupport
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

λ³„κ±΄μ•„λ‹Œλ° μˆœμ„œλ•œμ— 가독성이 μ•ˆμ’‹μ•„λ³΄μ—¬μš” γ… 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μˆ˜μ •ν•˜κ² μŠ΅λ‹ˆλ‹€!

)
14 changes: 14 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/API/ResponseLoginDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.dosopttemplate.API

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseLoginDto(
@SerialName("id")
val id: Int,
@SerialName("username")
val username: String,
@SerialName("nickname")
val nickname: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.sopt.dosopttemplate.API

sealed class SignupResponse {
data class ResponseSignUpDto(
val location: String
)
}
26 changes: 2 additions & 24 deletions app/src/main/java/org/sopt/dosopttemplate/data/Music.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,9 @@ package org.sopt.dosopttemplate.data

import android.os.Parcel
import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class Music(val title: String, val artist: String) : Parcelable {
val string: String = "🎧$title - $artist"

constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readString()!!
)

override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(title)
parcel.writeString(artist)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<Music> {
override fun createFromParcel(parcel: Parcel): Music {
return Music(parcel)
}

override fun newArray(size: Int): Array<Music?> {
return arrayOfNulls(size)
}
}
}
Loading