Skip to content
Merged
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.

117 changes: 0 additions & 117 deletions CLAUDE.md

This file was deleted.

18 changes: 17 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import java.util.Properties

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
Expand All @@ -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")
buildConfigField("String", "BASE_URL", "\"$baseUrl\"")
}

buildTypes {
Expand All @@ -38,6 +47,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
}

Expand Down Expand Up @@ -68,10 +78,16 @@ dependencies {

// Coroutines
implementation(libs.kotlinx.coroutines.android)
implementation(libs.adapter.guava)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)
}

implementation(libs.retrofit)
implementation(libs.retrofit.converter.gson)
implementation(libs.okhttp)
implementation(libs.okhttp.logging.interceptor)
}
24 changes: 20 additions & 4 deletions app/src/main/java/com/example/kuit6_android_api/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package com.example.kuit6_android_api

import android.Manifest
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Surface
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.core.content.ContextCompat
import androidx.navigation.compose.rememberNavController
Expand All @@ -32,6 +38,7 @@ class MainActivity : ComponentActivity() {
}
}

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand All @@ -40,15 +47,24 @@ class MainActivity : ComponentActivity() {

setContent {
KUIT6_Android_APITheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background

val snackBarState = remember { SnackbarHostState() }

Scaffold (
modifier = Modifier
.fillMaxSize()
.background(MaterialTheme.colorScheme.background),
snackbarHost = {
SnackbarHost(snackBarState)
}
) {
val navController = rememberNavController()

//얘한테 넘겨주면 내부 그래프에서 스크린에서 snackbar를 넘겨줌
NavGraph(
navController = navController,
startDestination = PostListRoute
startDestination = PostListRoute,
snackBarState = snackBarState
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query

//file 들어가서 project structure 에서 retrofit2 추가 해야된
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>//반환 값

@GET(value = "/api/posts/{id}")
suspend fun getPostDetail(
@Path("id") id: Long
): BaseResponse<PostResponse>

@DELETE("/api/posts/{id}")
suspend fun deletePost(
@Path("id") id: Long
): BaseResponse<PostResponse>

@PUT("/api/posts/{id}")
suspend fun editPost(
@Path("id") id: Long,
@Body request: PostCreateRequest
): BaseResponse<PostResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.kuit6_android_api.data.api

import com.example.kuit6_android_api.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object RetrofitClient {

//로그캣을 사용해서 어떤 통신이 오고가는지 확인 가능
private val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}

private val okHttpClient = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS)
.build()

private val retrofit: Retrofit = Retrofit.Builder()
.baseUrl(BuildConfig.BASE_URL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build()


val apiService: ApiService = retrofit.create(ApiService::class.java)
}
17 changes: 0 additions & 17 deletions app/src/main/java/com/example/kuit6_android_api/data/model/Post.kt

This file was deleted.

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
)
Loading