Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//import org.jetbrains.kotlin.konan.properties.Properties
import java.util.Properties

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
Expand All @@ -18,6 +21,15 @@ android {

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"


// defaultConfig 블록 안에 추가
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 {
Expand All @@ -38,6 +50,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
}

Expand Down Expand Up @@ -74,4 +87,11 @@ 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)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.kuit6_android_api.data.api

import com.example.kuit6_android_api.data.model.response.BaseResponse
import com.example.kuit6_android_api.data.model.response.PostResponse
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Body
import retrofit2.http.Query


interface ApiService {
@GET(value = "/api/posts")
suspend fun getPosts(): BaseResponse<List<PostResponse>>

@POST("/api/posts")
suspend fun createPost(
@Query("author") author: String = "규빈",
@Body request: PostCreateRequest
): BaseResponse<PostResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.kuit6_android_api.data.model.request

import kotlinx.serialization.SerialName

data class PostCreateRequest(
@SerialName( value = "title" ) val title: String,
@SerialName( value = "content" ) val content: String,
@SerialName(value = "imageUrl" ) val imageUrl: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.kuit6_android_api.data.model.response

import kotlinx.serialization.SerialName

data class AuthorResponse(
@SerialName(value = "id") val id: Long,
@SerialName(value = "username") val username: String,
@SerialName(value = "profileImageUrl") val profileImageUrl: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.kuit6_android_api.data.model.response

import kotlinx.serialization.SerialName

data class BaseResponse<T>(
@SerialName(value = "success") val success: Boolean,
@SerialName(value = "message") val message: String?,
@SerialName(value = "data") val data: T?,//데이터가 안 올 수도 ?
@SerialName(value = "timestamp") val timestamp: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.kuit6_android_api.data.model.response

import kotlinx.serialization.SerialName

data class PostResponse(
@SerialName(value = "id") val id: Long,
@SerialName(value = "title") val title: String,
@SerialName(value = "content") val content: String,
@SerialName(value = "imageUrl") val imageUrl: String?,
@SerialName(value = "author") val author: AuthorResponse,
@SerialName(value = "createdAt") val createdAt: String,
@SerialName(value = "updatedAt") val updatedAt: String
)