Skip to content

Commit

Permalink
[Feat] 인터넷 권한 추가, gradle 설정, DTO + ApiService 기본 툴 구축 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed May 2, 2024
1 parent 6ce662f commit 4c26d69
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 6 deletions.
21 changes: 19 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ plugins {
id 'org.jetbrains.kotlin.android'
}

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())

android {
namespace 'com.sopt.now'
compileSdk 34
Expand All @@ -15,6 +18,7 @@ android {
versionName "1.0"

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

buildTypes {
Expand All @@ -32,21 +36,34 @@ android {
}
buildFeatures {
viewBinding true
buildConfig true
}
}

dependencies {

implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.core:core-ktx:1.13.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

// Lifecycle Viewmodel
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0'

// Fragment && Activity
implementation 'androidx.fragment:fragment-ktx:1.6.2'
implementation 'androidx.activity:activity-ktx:1.8.2'
implementation 'androidx.activity:activity-ktx:1.9.0'

// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1'
implementation 'com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0'

// OKHttp
implementation platform('com.squareup.okhttp3:okhttp-bom:4.10.0')
implementation 'com.squareup.okhttp3:okhttp'
implementation 'com.squareup.okhttp3:logging-interceptor'
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<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 Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.sopt.now.data
package com.sopt.now.data.model

import androidx.annotation.DrawableRes

Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/RequestSignUpDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.sopt.now.data.model

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

@Serializable
data class RequestSignUpDto(
@SerialName("authenticationId")
val authenticationId: String,
@SerialName("password")
val password: String,
@SerialName("nickname")
val nickname: String,
@SerialName("phone")
val phone: String,
)
12 changes: 12 additions & 0 deletions app/src/main/java/com/sopt/now/data/model/ResponseSignUpDto.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sopt.now.data.model

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

@Serializable
data class ResponseSignUpDto(
@SerialName("code")
val code: Int,
@SerialName("message")
val message: String,
)
25 changes: 25 additions & 0 deletions app/src/main/java/com/sopt/now/data/module/ApiFactory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.sopt.now.data.module

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.sopt.now.BuildConfig
import com.sopt.now.data.network.AuthService
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import retrofit2.Retrofit

object ApiFactory {
private const val BASE_URL: String = BuildConfig.AUTH_BASE_URL

val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.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>()
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/sopt/now/data/network/AuthService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sopt.now.data.network

import com.sopt.now.data.model.RequestSignUpDto
import com.sopt.now.data.model.ResponseSignUpDto
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST

interface AuthService {
@POST("member/join")
fun signUp(
@Body request: RequestSignUpDto,
): Call<ResponseSignUpDto>
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/sopt/now/ui/adapter/ItemAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.sopt.now.data.ItemData
import com.sopt.now.data.model.ItemData
import com.sopt.now.databinding.ItemFriendBinding
import com.sopt.now.databinding.ItemMyProfileBinding

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/sopt/now/ui/home/HomFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import com.sopt.now.data.ItemData
import com.sopt.now.data.model.ItemData
import com.sopt.now.databinding.FragmentHomeBinding
import com.sopt.now.ui.adapter.ItemAdapter
import com.sopt.now.ui.home.viewModel.HomeViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.sopt.now.ui.home.viewModel

import androidx.lifecycle.ViewModel
import com.sopt.now.R
import com.sopt.now.data.ItemData
import com.sopt.now.data.model.ItemData

class HomeViewModel : ViewModel() {
val friendList = mutableListOf(
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ plugins {
id 'com.android.application' version '8.3.1' apply false
id 'com.android.library' version '8.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
id("org.jetbrains.kotlin.plugin.serialization") version "1.9.20" apply false
}

0 comments on commit 4c26d69

Please sign in to comment.