diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index a2cf405..639c779 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -9,8 +9,8 @@
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 0c6dbbc..54940a1 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -1,3 +1,5 @@
+import java.util.Properties
+
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
@@ -18,6 +20,13 @@ android {
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
+ val properties = Properties()
+ val localPropertiesFile = rootProject.file("local.properties")
+ if (localPropertiesFile.exists()) {
+ properties.load(localPropertiesFile.inputStream())
+ }
+ val baseUrl = properties.getProperty("BASE_URL")// ?: "http://10.0.2.2:8080/"
+ buildConfigField("String", "BASE_URL", "\"$baseUrl\"")
}
buildTypes {
@@ -38,6 +47,7 @@ android {
}
buildFeatures {
compose = true
+ buildConfig = true
}
}
@@ -74,4 +84,10 @@ dependencies {
androidTestImplementation(libs.androidx.espresso.core)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)
+
+ // Retrofit & OkHttp
+ implementation(libs.retrofit)
+ implementation(libs.retrofit.converter.gson)
+ implementation(libs.okhttp)
+ implementation(libs.okhttp.logging.interceptor)
}
diff --git a/app/src/main/java/com/example/kuit6_android_api/data/api/ApiService.kt b/app/src/main/java/com/example/kuit6_android_api/data/api/ApiService.kt
new file mode 100644
index 0000000..a264c8d
--- /dev/null
+++ b/app/src/main/java/com/example/kuit6_android_api/data/api/ApiService.kt
@@ -0,0 +1,51 @@
+package com.example.kuit6_android_api.data.api
+
+
+import com.example.kuit6_android_api.data.model.request.PostCreateRequest
+import com.example.kuit6_android_api.data.model.response.BaseResponse
+import com.example.kuit6_android_api.data.model.response.PostResponse
+import okhttp3.MultipartBody
+import retrofit2.http.Body
+import retrofit2.http.DELETE
+import retrofit2.http.GET
+import retrofit2.http.Multipart
+import retrofit2.http.POST
+import retrofit2.http.PUT
+import retrofit2.http.Part
+import retrofit2.http.Path
+import retrofit2.http.Query
+
+interface ApiService {
+ // http://3.34.136.227:8080/api/posts
+ @GET(value = "/api/posts")
+ suspend fun getPosts(): BaseResponse> // suspend fun: 일시 중단 될 수도 있는 함수
+
+ // http://3.34.136.227:8080/api/posts
+ @POST(value = "/api/posts")
+ suspend fun createPost(
+ @Query(value = "author") author: String = "anonymous",
+ @Body request: PostCreateRequest
+ ): BaseResponse
+
+ @GET(value = "/api/posts/{id}")
+ suspend fun getDetail(
+ @Path("id") id: Long
+ ): BaseResponse
+
+ @PUT(value = "/api/posts/{id}")
+ suspend fun updatePost(
+ @Path(value = "id") id: Long,
+ @Body request: PostCreateRequest
+ ): BaseResponse
+
+ @DELETE(value = "/api/posts/{id}")
+ suspend fun deletePost(
+ @Path("id") id: Long
+ ): BaseResponse // 서버가 data 없으면 Unit/Any? 로 받기
+
+ @Multipart
+ @POST("/api/images/upload")
+ suspend fun uploadImage(
+ @Part file: MultipartBody.Part
+ ): BaseResponse