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: 데이터 패키지 설정 #13 #35

Merged
merged 15 commits into from
Jul 23, 2024
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
19 changes: 18 additions & 1 deletion android/Staccato_AN/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import java.io.FileInputStream
import java.util.Properties

val localProperties =
Properties().apply {
load(FileInputStream(rootProject.file("local.properties")))
}

plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsKotlinAndroid)
id("kotlin-kapt")
alias(libs.plugins.kotlinKapt)
alias(libs.plugins.kotlinSerialization)
}

android {
Expand All @@ -16,6 +25,14 @@ android {
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildConfigField("String", "BASE_URL", "${localProperties["base_url"]}")
}

buildFeatures {
defaultConfig {
buildConfig = true
}
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.woowacourse.staccato.data

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.woowacourse.staccato.BuildConfig
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit

object StaccatoClient {
private val BASE_URL = BuildConfig.BASE_URL

private val provideLoggingInterceptor =
HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}

private val provideHttpClient =
OkHttpClient.Builder()
.addInterceptor(provideLoggingInterceptor)
.build()

private val jsonBuilder = Json { coerceInputValues = true }

private val provideRetrofit =
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(provideHttpClient)
.addConverterFactory(
jsonBuilder.asConverterFactory("application/json".toMediaType()),
)
.build()

fun <T> create(service: Class<T>): T {
return provideRetrofit.create(service)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.woowacourse.staccato.data.dto

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

@Serializable
data class MemberDto(
Copy link
Contributor

Choose a reason for hiding this comment

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

dto를 미리 다 만들어주셔서 편하게 잘 쓸 것 같아요!! 감사합니다~

@SerialName("memberId") val memberId: Long,
@SerialName("nickName") val nickName: String,
@SerialName("memberImage") val memberImage: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.woowacourse.staccato.data.dto.timeline

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

@Serializable
data class TimelineMemberDto(
@SerialName("memberId") val memberId: Long,
@SerialName("memberImage") val memberImage: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.woowacourse.staccato.data.dto.timeline

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

@Serializable
data class TimelineResponse(
@SerialName("travels") val travels: List<TimelineTravelDto>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.woowacourse.staccato.data.dto.timeline

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

@Serializable
data class TimelineTravelDto(
@SerialName("travelId") val travelId: Long,
@SerialName("travelTitle") val travelTitle: String,
@SerialName("travelThumbnail") val travelThumbnail: String,
@SerialName("startAt") val startAt: String,
@SerialName("endAt") val endAt: String,
@SerialName("mates") val mates: List<TimelineMemberDto>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.woowacourse.staccato.data.dto.travel

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

@Serializable
data class TravelRequest(
@SerialName("travelThumbnail") val travelThumbnail: String? = null,
@SerialName("travelTitle") val travelTitle: String,
@SerialName("description") val description: String? = null,
@SerialName("startAt") val startAt: String,
@SerialName("endAt") val endAt: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.woowacourse.staccato.data.dto.travel

import com.woowacourse.staccato.data.dto.MemberDto
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class TravelResponse(
@SerialName("travelId") val travelId: Long,
@SerialName("travelThumbnail") val travelThumbnail: String,
@SerialName("travelTitle") val travelTitle: String,
@SerialName("startAt") val startAt: String,
@SerialName("endAt") val endAt: String,
@SerialName("description") val description: String,
@SerialName("mates") val mates: List<MemberDto>,
@SerialName("visits") val visits: List<TravelVisitDto>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.woowacourse.staccato.data.dto.travel

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

@Serializable
data class TravelVisitDto(
@SerialName("visitId") val visitId: Long,
@SerialName("placeName") val placeName: String,
@SerialName("visitImage") val visitImage: String,
@SerialName("visitedAt") val visitedAt: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.woowacourse.staccato.data.dto.visit

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

@Serializable
data class VisitCreationRequest(
@SerialName("pinId") val pinId: Long,
@SerialName("visitedImages") val visitedImages: List<String>,
@SerialName("visitedAt") val visitedAt: String,
@SerialName("travelId") val travelId: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.woowacourse.staccato.data.dto.visit

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

@Serializable
data class VisitLogDto(
@SerialName("visitLogId") val visitLogId: Long,
@SerialName("memberId") val memberId: Long,
@SerialName("nickName") val nickName: String,
@SerialName("memberImage") val memberImage: String,
@SerialName("content") val content: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.woowacourse.staccato.data.dto.visit

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

@Serializable
data class VisitResponse(
@SerialName("visitId") val visitId: Long,
@SerialName("placeName") val placeName: String,
@SerialName("visitedImages") val visitedImages: List<String>,
@SerialName("address") val address: String,
@SerialName("visitedAt") val visitedAt: String,
@SerialName("visitedCount") val visitedCount: Long,
@SerialName("visitLogs") val visitLogs: List<VisitLogDto>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.woowacourse.staccato.data.dto.visit

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

@Serializable
data class VisitUpdateRequest(
@SerialName("visitedImages") val visitedImages: List<String>,
@SerialName("visitedAt") val visitedAt: String,
)
2 changes: 2 additions & 0 deletions android/Staccato_AN/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ plugins {
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.jetbrainsKotlinAndroid) apply false
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.kotlinKapt) apply false
alias(libs.plugins.kotlinSerialization) apply false
}

buildscript {
Expand Down
2 changes: 2 additions & 0 deletions android/Staccato_AN/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ androidx-navigation-ui-ktx = { group = "androidx.navigation", name = "navigation
androidApplication = { id = "com.android.application", version.ref = "agp" }
jetbrainsKotlinAndroid = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }
kotlinKapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" }
kotlinSerialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
Loading