Skip to content
This repository has been archived by the owner on Apr 27, 2023. It is now read-only.

Commit

Permalink
[feature/net-module] 네트워크 모듈 쪽 Config (#35)
Browse files Browse the repository at this point in the history
* .DS_STORE 파일 ignore 등록

* feat: Add BuildConfig api properties

* [feature/net-module] 상수 주입받는 모듈 생성

* [feature/net-module] 어노테이션 명 변경

* [feature/net-module] Json, Retrofit, OkHttp 설정

* [feature/net-module] kotlinx-datetime 의존성 추가

* [feature/net-module] kotlinx-datatime 의존성 추가

* [feature/net-module] DTO 패키지/모델 추가

* [feature/net-module] Model명 변경

* [feature/net-module] 리모트 모듈 정의하고 StampService 만들기

* [feature/net-module] Lint 정리

* [feature/net-module] yml에 apiKey 정보 넣기

* [feature/net-module] Action 빌드 스텝 이름 변경

* [feature/net-module] 스탬프 수정 API

* [feature/net-module] 스탬프 등록 API

Co-authored-by: jinsu4755 <parkjinsu4755@gmail.com>
  • Loading branch information
l2hyunwoo and jinsu4755 committed Jan 5, 2023
1 parent 088d101 commit e063211
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/develop_PR_builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ jobs:
- name: Change gradlew permissions
run: chmod +x ./gradlew

- name: Add Network Base Url
env:
API_KEY: ${{ secrets.API_KEY }}
run: echo apiKey=\"$API_KEY\" >> ./local.properties

- name: Access Firebase Service
run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > ./app/google-services.json

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/develop_merge_builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ jobs:
- name: Change gradlew permissions
run: chmod +x ./gradlew

- name: Add Network Base Url
env:
API_KEY: ${{ secrets.API_KEY }}
run: echo apiKey=\"$API_KEY\" >> ./local.properties

- name: Access Firebase Service
run: echo '${{ secrets.GOOGLE_SERVICES_JSON }}' > ./app/google-services.json

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,5 @@ fabric.properties
!/gradle/wrapper/gradle-wrapper.jar

# End of https://www.toptal.com/developers/gitignore/api/android,androidstudio

.DS_Store
6 changes: 6 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ plugins {
alias libs.plugins.kotlinx.serialization
}

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

android {
namespace 'org.sopt.stamp'
compileSdk 33
Expand All @@ -25,6 +28,8 @@ android {
vectorDrawables {
useSupportLibrary true
}

buildConfigField "String", "SOPTAMP_API_KEY", properties["apiKey"]
}

buildTypes {
Expand Down Expand Up @@ -62,6 +67,7 @@ android {
}

dependencies {
implementation libs.kotlin.datetime
implementation libs.kotlin.serialization.json
implementation libs.core.ktx
implementation libs.bundles.compose
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sopt.stamp.data.model.response

import kotlinx.serialization.Serializable

@Serializable
data class ResponseModifyStampDto(
val stampId: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.sopt.stamp.data.model.response

import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable

@Serializable
data class ResponseStampDto(
val createdAt: Instant? = null,
val updatedAt: Instant? = null,
val id: Long,
val contents: String,
val images: List<String>,
val userId: Long,
val missionId: Int,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.sopt.stamp.data.remote.service

import okhttp3.MultipartBody
import okhttp3.RequestBody
import org.sopt.stamp.data.model.response.ResponseModifyStampDto
import org.sopt.stamp.data.model.response.ResponseStampDto
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Part
import retrofit2.http.Path

interface StampService {
@GET("stamp/{missionId}")
suspend fun retrieveStamp(
@Path("missionId") missionId: Int
): ResponseStampDto

@Multipart
@PUT("stamp/{missionId}")
suspend fun modifyStamp(
@Path("missionId") missionId: Int,
@Part stampContent: RequestBody,
@Part imageUrl: MultipartBody.Part? = null,
): ResponseModifyStampDto

@Multipart
@POST("stamp/{missionId}")
suspend fun registerStamp(
@Path("missionId") missionId: Int,
@Part stampContent: RequestBody,
@Part imageUrl: MultipartBody.Part? = null,
): ResponseStampDto
}
44 changes: 44 additions & 0 deletions app/src/main/java/org/sopt/stamp/di/ConfigModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.sopt.stamp.di

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import org.sopt.stamp.di.constant.Constant
import org.sopt.stamp.di.constant.Strings
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ConfigModule {
@Provides
@Singleton
fun provideSerializer() = Json {
prettyPrint = true
isLenient = true
}

@Provides
@Singleton
fun provideHttpClient() = OkHttpClient.Builder()
.build()

@OptIn(ExperimentalSerializationApi::class)
@Provides
@Singleton
fun provideRetrofit(
@Strings(Constant.SOPTAMP_API_KEY) baseUrl: String,
client: OkHttpClient,
json: Json
): Retrofit = Retrofit.Builder()
.baseUrl(baseUrl)
.client(client)
.addConverterFactory(json.asConverterFactory("application/json".toMediaType()))
.build()
}
19 changes: 19 additions & 0 deletions app/src/main/java/org/sopt/stamp/di/ConstantModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.sopt.stamp.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.stamp.BuildConfig
import org.sopt.stamp.di.constant.Strings
import org.sopt.stamp.di.constant.Constant
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ConstantModule {
@Provides
@Singleton
@Strings(Constant.SOPTAMP_API_KEY)
fun provideBaseUrl() = BuildConfig.SOPTAMP_API_KEY
}
19 changes: 19 additions & 0 deletions app/src/main/java/org/sopt/stamp/di/RemoteModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.sopt.stamp.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.stamp.data.remote.service.StampService
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
internal object RemoteModule {
@Provides
@Singleton
fun provideStampService(
retrofit: Retrofit
): StampService = retrofit.create(StampService::class.java)
}
11 changes: 11 additions & 0 deletions app/src/main/java/org/sopt/stamp/di/constant/Constant.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.stamp.di.constant

import javax.inject.Qualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class Strings(val value: Constant)

enum class Constant {
SOPTAMP_API_KEY
}
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
kotlin = "1.7.20"
kotlinx-serialization-json = "1.4.1"
kotlinx-serialization-converter = "0.8.0"
kotlinx-datetime = "0.4.0"
compose = "1.3.1"
corektx = "1.9.0"
appcompat = "1.5.1"
Expand Down Expand Up @@ -45,6 +46,7 @@ lottie = "5.2.0"
agp = { module = "com.android.tools.build:gradle", version.ref = "gradleplugin" }
kotlin-gradleplugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx-serialization-json", version.ref = "kotlinx-serialization-json" }
kotlin-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" }

core-ktx = { module = "androidx.core:core-ktx", version.ref = "corektx" }
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
Expand Down

0 comments on commit e063211

Please sign in to comment.