From d0109583ca08e4f4331f4a134b989665f6743f54 Mon Sep 17 00:00:00 2001 From: Gyeongrok Kim Date: Sun, 3 Mar 2024 17:23:52 +0900 Subject: [PATCH 1/3] feat: add datasource of member, briefing, scrap in network --- .gitignore | 1 + build-logic/convention/build.gradle.kts | 1 + .../app/buildlogic/extension/KotlinAndroid.kt | 4 ++ .../app/buildlogic/extension/Secret.kt | 12 ++++ .../AndroidApplicationConventionPlugin.kt | 5 ++ .../plugin/AndroidLibraryConventionPlugin.kt | 4 ++ build.gradle.kts | 6 ++ .../app/core/common/DateTimeUtil.kt | 11 +++ .../app/core/model/BriefingArticleCategory.kt | 15 ++++ .../newsbriefing/app/core/model/TimeOfDay.kt | 13 ++++ core/network/build.gradle.kts | 4 +- .../datasource/BriefingNetworkDataSource.kt | 17 +++++ .../datasource/MemberNetworkDataSource.kt | 16 +++++ .../datasource/ScrapNetworkDataSource.kt | 13 ++++ .../app/core/network/di/NetworkModule.kt | 31 ++++++++ .../app/core/network/di/RetrofitModule.kt | 42 +++++++++++ .../network/model/RetrofitCommonResponse.kt | 14 ++++ .../model/briefing/NetworkBriefingArticle.kt | 20 ++++++ .../briefing/NetworkBriefingArticleRelated.kt | 10 +++ .../briefing/NetworkBriefingArticleSummary.kt | 11 +++ .../model/member/NetworkMemberDelete.kt | 8 +++ .../model/member/NetworkMemberToken.kt | 13 ++++ .../core/network/model/scrap/NetworkScrap.kt | 20 ++++++ .../network/model/scrap/NetworkScrapCreate.kt | 14 ++++ .../network/model/scrap/NetworkScrapDelete.kt | 10 +++ .../retrofit/api/RetrofitBriefingNetwork.kt | 58 +++++++++++++++ .../retrofit/api/RetrofitMemberNetwork.kt | 70 +++++++++++++++++++ .../retrofit/api/RetrofitScrapNetwork.kt | 67 ++++++++++++++++++ gradle/libs.versions.toml | 2 + 29 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/extension/Secret.kt create mode 100644 core/common/src/main/java/store/newsbriefing/app/core/common/DateTimeUtil.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleCategory.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/TimeOfDay.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/datasource/BriefingNetworkDataSource.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/datasource/ScrapNetworkDataSource.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/di/NetworkModule.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/di/RetrofitModule.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/RetrofitCommonResponse.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticle.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleRelated.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleSummary.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberDelete.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberToken.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrap.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapCreate.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapDelete.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitBriefingNetwork.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitMemberNetwork.kt create mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitScrapNetwork.kt diff --git a/.gitignore b/.gitignore index e578810..806d39e 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ out/ build/ # Local configuration file (sdk path, etc) local.properties +secrets.properties keystore.properties output-metadata.json # Proguard folder generated by Eclipse diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 6b5ac0b..4a9a75e 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -11,6 +11,7 @@ dependencies { compileOnly(libs.android.tools.common) compileOnly(libs.kotlin.gradlePlugin) compileOnly(libs.ksp.gradlePlugin) + compileOnly(libs.secrets.gradle.plugin) } gradlePlugin { diff --git a/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/extension/KotlinAndroid.kt b/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/extension/KotlinAndroid.kt index 09f3b46..f530b5f 100644 --- a/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/extension/KotlinAndroid.kt +++ b/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/extension/KotlinAndroid.kt @@ -23,6 +23,10 @@ internal fun Project.configureKotlinAndroid( minSdk = Config.android.minSdkVersion } + buildFeatures { + buildConfig = true + } + compileOptions { sourceCompatibility = JavaVersion.VERSION_18 targetCompatibility = JavaVersion.VERSION_18 diff --git a/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/extension/Secret.kt b/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/extension/Secret.kt new file mode 100644 index 0000000..b3f5ec9 --- /dev/null +++ b/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/extension/Secret.kt @@ -0,0 +1,12 @@ +package store.newsbriefing.app.buildlogic.extension + +import com.android.build.api.dsl.CommonExtension +import com.google.android.libraries.mapsplatform.secrets_gradle_plugin.SecretsPluginExtension +import org.gradle.api.Project +import org.gradle.kotlin.dsl.configure + +internal fun Project.configureSecret() { + extensions.configure { + defaultPropertiesFileName = "secrets.properties" + } +} \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/plugin/AndroidApplicationConventionPlugin.kt b/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/plugin/AndroidApplicationConventionPlugin.kt index 351ac83..dc34510 100644 --- a/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/plugin/AndroidApplicationConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/plugin/AndroidApplicationConventionPlugin.kt @@ -1,11 +1,13 @@ package store.newsbriefing.app.buildlogic.plugin import com.android.build.api.dsl.ApplicationExtension +import com.google.android.libraries.mapsplatform.secrets_gradle_plugin.SecretsPluginExtension import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.configure import store.newsbriefing.app.buildlogic.config.Config import store.newsbriefing.app.buildlogic.extension.configureKotlinAndroid +import store.newsbriefing.app.buildlogic.extension.configureSecret class AndroidApplicationConventionPlugin : Plugin { override fun apply(target: Project) { @@ -13,6 +15,7 @@ class AndroidApplicationConventionPlugin : Plugin { with(pluginManager) { apply("com.android.application") apply("org.jetbrains.kotlin.android") + apply("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") } // android extensions.configure { @@ -32,6 +35,8 @@ class AndroidApplicationConventionPlugin : Plugin { } } } + + configureSecret() } } } \ No newline at end of file diff --git a/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/plugin/AndroidLibraryConventionPlugin.kt b/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/plugin/AndroidLibraryConventionPlugin.kt index 71fb0ca..eacdbb9 100644 --- a/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/plugin/AndroidLibraryConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/store/newsbriefing/app/buildlogic/plugin/AndroidLibraryConventionPlugin.kt @@ -6,6 +6,7 @@ import org.gradle.api.Project import org.gradle.kotlin.dsl.configure import store.newsbriefing.app.buildlogic.config.Config import store.newsbriefing.app.buildlogic.extension.configureKotlinAndroid +import store.newsbriefing.app.buildlogic.extension.configureSecret class AndroidLibraryConventionPlugin : Plugin { override fun apply(target: Project) { @@ -13,12 +14,15 @@ class AndroidLibraryConventionPlugin : Plugin { with(pluginManager) { apply("com.android.library") apply("org.jetbrains.kotlin.android") + apply("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") } extensions.configure { configureKotlinAndroid(this) defaultConfig.targetSdk = Config.android.targetSdkVersion } + + configureSecret() } } } \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 70ea996..84d625d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,4 +4,10 @@ plugins { alias(libs.plugins.ksp) apply false alias(libs.plugins.hilt) apply false alias(libs.plugins.androidLibrary) apply false +} + +buildscript { + dependencies { + classpath(libs.secrets.gradle.plugin) + } } \ No newline at end of file diff --git a/core/common/src/main/java/store/newsbriefing/app/core/common/DateTimeUtil.kt b/core/common/src/main/java/store/newsbriefing/app/core/common/DateTimeUtil.kt new file mode 100644 index 0000000..745fdc8 --- /dev/null +++ b/core/common/src/main/java/store/newsbriefing/app/core/common/DateTimeUtil.kt @@ -0,0 +1,11 @@ +package store.newsbriefing.app.core.common + +import java.time.Instant +import java.time.ZoneId +import java.time.ZonedDateTime + + +fun String.toZoneDateTime(): ZonedDateTime { + val instant = Instant.parse(this) + return instant.atZone(ZoneId.systemDefault()) +} \ No newline at end of file diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleCategory.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleCategory.kt new file mode 100644 index 0000000..248bc28 --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleCategory.kt @@ -0,0 +1,15 @@ +package store.newsbriefing.app.core.model +enum class BriefingArticleCategory(val typeId: String) { + KOREA("KOREA"), + GLOBAL("GLOBAL"), + SOCIAL("SOCIAL"), + SCIENCE("SCIENCE"), + ECONOMY("ECONOMY"); + + companion object { + fun fromTypeName(typeName: String): BriefingArticleCategory { + return values().firstOrNull { it.typeId.equals(typeName, ignoreCase = true) } + ?: throw IllegalArgumentException("Invalid typeName for ArticleType: $typeName") + } + } +} \ No newline at end of file diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/TimeOfDay.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/TimeOfDay.kt new file mode 100644 index 0000000..a0a148f --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/TimeOfDay.kt @@ -0,0 +1,13 @@ +package store.newsbriefing.app.core.model + +enum class TimeOfDay(val value: String) { + MORNING("Morning"), + EVENING("Evening"); + + companion object { + fun fromValue(value: String): TimeOfDay { + return values().firstOrNull { it.value.equals(value, ignoreCase = true) } + ?: throw IllegalArgumentException("Invalid value for TimeOfDay: $value") + } + } +} \ No newline at end of file diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index 3302eb0..18d9977 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -10,6 +10,8 @@ android { dependencies { api(projects.core.model) + api(projects.core.common) implementation(libs.retrofit.core) -} + implementation(libs.retrofit.converter.gson) +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/BriefingNetworkDataSource.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/BriefingNetworkDataSource.kt new file mode 100644 index 0000000..a5d343b --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/BriefingNetworkDataSource.kt @@ -0,0 +1,17 @@ +package store.newsbriefing.app.core.network.datasource + +import store.newsbriefing.app.core.model.BriefingArticleCategory +import store.newsbriefing.app.core.model.TimeOfDay +import store.newsbriefing.app.core.network.model.briefing.NetworkBriefingArticle +import store.newsbriefing.app.core.network.model.briefing.NetworkBriefingArticleSummary +import java.time.LocalDate + +interface BriefingNetworkDataSource { + suspend fun getBriefingArticleSummaries( + briefingArticleCategory: BriefingArticleCategory, + dateLocalDate: LocalDate?, + timeOfDay: TimeOfDay? + ): List + + suspend fun getBriefingArticle(articleId: Long): NetworkBriefingArticle +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.kt new file mode 100644 index 0000000..27dfe10 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.kt @@ -0,0 +1,16 @@ +package store.newsbriefing.app.core.network.datasource + +import store.newsbriefing.app.core.network.model.member.NetworkMemberDelete +import store.newsbriefing.app.core.network.model.member.NetworkMemberToken + +interface MemberNetworkDataSource { + suspend fun deleteMember(memberId: Long): NetworkMemberDelete + suspend fun getTokenWithSocialProvider( + provider: String, + identityToken: String + ): NetworkMemberToken + + suspend fun getRefreshedAccessToken( + refreshToken: String + ): NetworkMemberToken +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/ScrapNetworkDataSource.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/ScrapNetworkDataSource.kt new file mode 100644 index 0000000..466f4d3 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/ScrapNetworkDataSource.kt @@ -0,0 +1,13 @@ +package store.newsbriefing.app.core.network.datasource + +import store.newsbriefing.app.core.network.model.scrap.NetworkScrap +import store.newsbriefing.app.core.network.model.scrap.NetworkScrapCreate +import store.newsbriefing.app.core.network.model.scrap.NetworkScrapDelete + +interface ScrapNetworkDataSource { + suspend fun getScrap(memberId: Long): List + + suspend fun setScrap(memberId: Long, articleId: Long): NetworkScrapCreate + + suspend fun unScrap(memberId: Long, articleId: Long): NetworkScrapDelete +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/di/NetworkModule.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/di/NetworkModule.kt new file mode 100644 index 0000000..5037829 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/di/NetworkModule.kt @@ -0,0 +1,31 @@ +package store.newsbriefing.app.core.network.di + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import store.newsbriefing.app.core.network.datasource.BriefingNetworkDataSource +import store.newsbriefing.app.core.network.datasource.MemberNetworkDataSource +import store.newsbriefing.app.core.network.datasource.ScrapNetworkDataSource +import store.newsbriefing.app.core.network.retrofit.api.RetrofitBriefingNetwork +import store.newsbriefing.app.core.network.retrofit.api.RetrofitMemberNetwork +import store.newsbriefing.app.core.network.retrofit.api.RetrofitScrapNetwork + +@Module +@InstallIn(SingletonComponent::class) +internal interface NetworkModule { + @Binds + fun bindBriefingNetworkDataSource( + retrofitBriefingNetwork: RetrofitBriefingNetwork + ): BriefingNetworkDataSource + + @Binds + fun bindMemberNetworkDataSource( + retrofitMemberNetwork: RetrofitMemberNetwork + ): MemberNetworkDataSource + + @Binds + fun bindScrapNetworkDataSource( + retrofitScrapNetwork: RetrofitScrapNetwork + ): ScrapNetworkDataSource +} diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/di/RetrofitModule.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/di/RetrofitModule.kt new file mode 100644 index 0000000..00dd5ed --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/di/RetrofitModule.kt @@ -0,0 +1,42 @@ +package store.newsbriefing.app.core.network.di + +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import okhttp3.OkHttpClient +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import store.newsbriefing.app.core.network.BuildConfig +import javax.inject.Singleton + +@Module +@InstallIn(SingletonComponent::class) +object RetrofitModule { + + @Provides + @Singleton + fun provideGson(): Gson { + return GsonBuilder() + .setLenient() + .create() + } + + @Provides + @Singleton + fun provideOkHttpClient(): OkHttpClient { + return OkHttpClient.Builder().build() + } + + @Provides + @Singleton + fun provideRetrofit(gson: Gson, okHttpClient: OkHttpClient): Retrofit { + return Retrofit.Builder() + .addConverterFactory(GsonConverterFactory.create(gson)) + .client(okHttpClient) + .baseUrl(if (BuildConfig.DEBUG) BuildConfig.API_URL_DEBUG else BuildConfig.API_URL_RELEASE) + .build() + } +} diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/RetrofitCommonResponse.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/RetrofitCommonResponse.kt new file mode 100644 index 0000000..0e582b8 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/RetrofitCommonResponse.kt @@ -0,0 +1,14 @@ +package store.newsbriefing.app.core.network.model + +import com.google.gson.annotations.SerializedName + +data class RetrofitCommonResponse( + @SerializedName("isSuccess") + val isSuccess: Boolean, + @SerializedName("code") + val code: String, + @SerializedName("message") + val message: String, + @SerializedName("result") + val result: T, +) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticle.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticle.kt new file mode 100644 index 0000000..90af9da --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticle.kt @@ -0,0 +1,20 @@ +package store.newsbriefing.app.core.network.model.briefing + +import com.google.gson.annotations.SerializedName + +data class NetworkBriefingArticle( + @SerializedName("id") val id: Long, + @SerializedName("ranks") val ranks: Int, + @SerializedName("title") val title: String, + @SerializedName("subtitle") val subtitle: String, + @SerializedName("content") val content: String, + @SerializedName("date") val date: String, + @SerializedName("articles") val articles: List, + @SerializedName("isScrap") val isScrap: Boolean, + @SerializedName("isBriefingOpen") val isBriefingOpen: Boolean, + @SerializedName("isWarning") val isWarning: Boolean, + @SerializedName("scrapCount") val scrapCount: Int, + @SerializedName("gptModel") val gptModel: String, + @SerializedName("timeOfDay") val timeOfDay: String, + @SerializedName("type") val type: String +) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleRelated.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleRelated.kt new file mode 100644 index 0000000..1612aa5 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleRelated.kt @@ -0,0 +1,10 @@ +package store.newsbriefing.app.core.network.model.briefing + +import com.google.gson.annotations.SerializedName + +data class NetworkBriefingArticleRelated( + @SerializedName("id") val id: Int, + @SerializedName("press") val press: String, + @SerializedName("title") val title: String, + @SerializedName("url") val url: String +) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleSummary.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleSummary.kt new file mode 100644 index 0000000..21bbd02 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleSummary.kt @@ -0,0 +1,11 @@ +package store.newsbriefing.app.core.network.model.briefing + +import com.google.gson.annotations.SerializedName + +data class NetworkBriefingArticleSummary( + @SerializedName("id") val id: Int, + @SerializedName("ranks") val ranks: Int, + @SerializedName("title") val title: String, + @SerializedName("subtitle") val subtitle: String, + @SerializedName("scrapCount") val scrapCount: Int +) {} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberDelete.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberDelete.kt new file mode 100644 index 0000000..a0cf585 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberDelete.kt @@ -0,0 +1,8 @@ +package store.newsbriefing.app.core.network.model.member + +import com.google.gson.annotations.SerializedName + +data class NetworkMemberDelete( + @SerializedName("quitAt") + val quitAt : String) { +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberToken.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberToken.kt new file mode 100644 index 0000000..f8d3e40 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberToken.kt @@ -0,0 +1,13 @@ +package store.newsbriefing.app.core.network.model.member + +import com.google.gson.annotations.SerializedName + +data class NetworkMemberToken( + @SerializedName("memberId") + val memberId: Long, + @SerializedName("accessToken") + val accessToken: String, + @SerializedName("refreshToken") + val refreshToken: String +) { +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrap.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrap.kt new file mode 100644 index 0000000..05d2cab --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrap.kt @@ -0,0 +1,20 @@ +package store.newsbriefing.app.core.network.model.scrap + +import com.google.gson.annotations.SerializedName + +data class NetworkScrap( + @SerializedName("briefingId") + val briefingId: Int, + @SerializedName("ranks") + val ranks: Int, + @SerializedName("title") + val title: String, + @SerializedName("subtitle") + val subtitle: String, + @SerializedName("date") + val date: String, + @SerializedName("gptModel") + val gptModel: String, + @SerializedName("timeOfDay") + val timeOfDay: String, +) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapCreate.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapCreate.kt new file mode 100644 index 0000000..9976c8f --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapCreate.kt @@ -0,0 +1,14 @@ +package store.newsbriefing.app.core.network.model.scrap + +import com.google.gson.annotations.SerializedName + +data class NetworkScrapCreate( + @SerializedName("scrapId") + val scrapId: Int, + @SerializedName("memberId") + val memberId: Int, + @SerializedName("briefingId") + val briefingId: Int, + @SerializedName("createdAt") + val createdAt: String, +) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapDelete.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapDelete.kt new file mode 100644 index 0000000..750f132 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapDelete.kt @@ -0,0 +1,10 @@ +package store.newsbriefing.app.core.network.model.scrap + +import com.google.gson.annotations.SerializedName + +class NetworkScrapDelete( + @SerializedName("scrapId") + val scrapId: Int, + @SerializedName("deletedAt") + val deletedAt: String +) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitBriefingNetwork.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitBriefingNetwork.kt new file mode 100644 index 0000000..1498cb7 --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitBriefingNetwork.kt @@ -0,0 +1,58 @@ +package store.newsbriefing.app.core.network.retrofit.api + +import retrofit2.Retrofit +import retrofit2.http.Body +import retrofit2.http.DELETE +import retrofit2.http.GET +import retrofit2.http.POST +import retrofit2.http.Path +import retrofit2.http.Query +import store.newsbriefing.app.core.model.BriefingArticleCategory +import store.newsbriefing.app.core.model.TimeOfDay +import store.newsbriefing.app.core.network.datasource.BriefingNetworkDataSource +import store.newsbriefing.app.core.network.model.RetrofitCommonResponse +import store.newsbriefing.app.core.network.model.briefing.NetworkBriefingArticle +import store.newsbriefing.app.core.network.model.briefing.NetworkBriefingArticleSummary +import store.newsbriefing.app.core.network.model.member.NetworkMemberDelete +import store.newsbriefing.app.core.network.model.member.NetworkMemberToken +import java.time.LocalDate +import java.time.format.DateTimeFormatter +import javax.inject.Inject +import javax.inject.Singleton + +private interface RetrofitBriefingApi { + @GET("briefings") + suspend fun getBriefingArticleSummaries( + @Query("type") type: String, + @Query("date") date: String?, + @Query("timeOfDay") timeOfDay: String? + ): RetrofitCommonResponse> + + @GET("briefings/{id}") + suspend fun getBriefingArticle(@Path("id") id: Long): RetrofitCommonResponse +} + +@Singleton +internal class RetrofitBriefingNetwork @Inject constructor( + private val retrofit: Retrofit +) : BriefingNetworkDataSource { + private val api: RetrofitBriefingApi by lazy { + retrofit.create(RetrofitBriefingApi::class.java) + } + + override suspend fun getBriefingArticleSummaries( + briefingArticleCategory: BriefingArticleCategory, + dateLocalDate: LocalDate?, + timeOfDay: TimeOfDay? + ): List { + return api.getBriefingArticleSummaries( + type = briefingArticleCategory.typeId, + date = dateLocalDate?.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), + timeOfDay = timeOfDay?.value + ).result + } + + override suspend fun getBriefingArticle(articleId: Long): NetworkBriefingArticle { + return api.getBriefingArticle(articleId).result + } +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitMemberNetwork.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitMemberNetwork.kt new file mode 100644 index 0000000..846fd1e --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitMemberNetwork.kt @@ -0,0 +1,70 @@ +package store.newsbriefing.app.core.network.retrofit.api + +import com.google.gson.annotations.SerializedName +import retrofit2.Retrofit +import retrofit2.http.Body +import retrofit2.http.DELETE +import retrofit2.http.GET +import retrofit2.http.POST +import retrofit2.http.Path +import retrofit2.http.Query +import store.newsbriefing.app.core.network.datasource.MemberNetworkDataSource +import store.newsbriefing.app.core.network.model.member.NetworkMemberDelete +import store.newsbriefing.app.core.network.model.member.NetworkMemberToken +import store.newsbriefing.app.core.network.model.RetrofitCommonResponse +import javax.inject.Inject +import javax.inject.Singleton + +private data class PostTokenWithRefreshTokenRequest( + @SerializedName("refreshToken") + val refreshToken: String +) +private data class PostTokenWithSocialProviderRequest( + @SerializedName("identityToken") + val identityToken: String +) + +private interface RetrofitMemberApi { + @POST("members/auth/{provider}") + suspend fun postTokenWithSocialProvider( + @Query("provider") provider: String, + @Body request: PostTokenWithSocialProviderRequest + ): RetrofitCommonResponse + + @POST("members/auth/token") + suspend fun postTokenWithRefreshToken( + @Body request: PostTokenWithRefreshTokenRequest + ): RetrofitCommonResponse + + @DELETE("members/{memberId}") + suspend fun deleteMember( + @Path("memberId") memberId: Long + ): RetrofitCommonResponse +} + +@Singleton +internal class RetrofitMemberNetwork @Inject constructor( + private val retrofit: Retrofit +) : MemberNetworkDataSource { + private val api: RetrofitMemberApi by lazy { + retrofit.create(RetrofitMemberApi::class.java) + } + + override suspend fun deleteMember(memberId: Long): NetworkMemberDelete { + val response = api.deleteMember(memberId) + return response.result + } + + override suspend fun getTokenWithSocialProvider( + provider: String, + identityToken: String + ): NetworkMemberToken { + val response = api.postTokenWithSocialProvider(provider, PostTokenWithSocialProviderRequest(identityToken)) + return response.result + } + + override suspend fun getRefreshedAccessToken(refreshToken: String): NetworkMemberToken { + val response = api.postTokenWithRefreshToken(PostTokenWithRefreshTokenRequest(refreshToken)) + return response.result + } +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitScrapNetwork.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitScrapNetwork.kt new file mode 100644 index 0000000..ace8e6f --- /dev/null +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitScrapNetwork.kt @@ -0,0 +1,67 @@ +package store.newsbriefing.app.core.network.retrofit.api + +import com.google.gson.annotations.SerializedName +import retrofit2.Retrofit +import retrofit2.http.Body +import retrofit2.http.DELETE +import retrofit2.http.GET +import retrofit2.http.POST +import retrofit2.http.Path +import retrofit2.http.Query +import store.newsbriefing.app.core.network.datasource.ScrapNetworkDataSource +import store.newsbriefing.app.core.network.model.RetrofitCommonResponse +import store.newsbriefing.app.core.network.model.member.NetworkMemberDelete +import store.newsbriefing.app.core.network.model.member.NetworkMemberToken +import store.newsbriefing.app.core.network.model.scrap.NetworkScrap +import store.newsbriefing.app.core.network.model.scrap.NetworkScrapCreate +import store.newsbriefing.app.core.network.model.scrap.NetworkScrapDelete +import javax.inject.Inject +import javax.inject.Singleton + +private data class PostScrapRequest( + @SerializedName("memberId") + val memberId: Long, + @SerializedName("briefingId") + val briefingId: Long, +) + +private interface RetrofitScrapApi { + @GET("scraps/briefings/members/{memberId}") + suspend fun getScrap( + @Path("memberId") memberId: Long, + ): RetrofitCommonResponse> + + @POST("scraps/briefings") + suspend fun setScrap( + @Body request: PostScrapRequest, + ): RetrofitCommonResponse + + @DELETE("scraps/briefings/{briefingId}/members/{memberId}") + suspend fun setUnScrap( + @Path("briefingId") briefingId: Long, + @Path("memberId") memberId: Long, + ): RetrofitCommonResponse +} + +@Singleton +internal class RetrofitScrapNetwork @Inject constructor( + private val retrofit: Retrofit +) : ScrapNetworkDataSource { + private val api: RetrofitScrapApi by lazy { + retrofit.create(RetrofitScrapApi::class.java) + } + + override suspend fun getScrap(memberId: Long): List { + return api.getScrap(memberId).result + } + + override suspend fun setScrap(memberId: Long, articleId: Long): NetworkScrapCreate { + val response = api.setScrap(PostScrapRequest(memberId, articleId)) + return response.result + } + + override suspend fun unScrap(memberId: Long, articleId: Long): NetworkScrapDelete { + val response = api.setUnScrap(articleId, memberId) + return response.result + } +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b2f19ff..482c02e 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -16,6 +16,7 @@ androidxAppCompat = "1.6.1" androidxActivity = "1.8.2" retrofit = "2.9.0" material = "1.11.0" +secretsGradlePlugin = "2.0.1" [libraries] core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "core-ktx" } @@ -38,6 +39,7 @@ androidx-compose-ui-tooling = { group = "androidx.compose.ui", name = "ui-toolin androidx-compose-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } androidx-compose-ui-util = { group = "androidx.compose.ui", name = "ui-util" } +secrets-gradle-plugin = { module = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin", version.ref = "secretsGradlePlugin" } ui = { group = "androidx.compose.ui", name = "ui" } ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } From 46591e2e18e569c34e4fc13f3ab850a12d5de61c Mon Sep 17 00:00:00 2001 From: Gyeongrok Kim Date: Sun, 3 Mar 2024 17:38:37 +0900 Subject: [PATCH 2/3] feat: add common models --- .../app/core/model/BriefingArticle.kt | 20 +++++++++++++++++++ .../app/core/model/BriefingArticleRelated.kt | 8 ++++++++ .../app/core/model/BriefingArticleSummary.kt | 9 +++++++++ .../app/core/model/MemberDeleteResult.kt | 7 +++++++ .../app/core/model/MemberToken.kt | 7 +++++++ .../newsbriefing/app/core/model/Scrap.kt | 13 ++++++++++++ .../app/core/model/ScrapCreateResult.kt | 10 ++++++++++ .../app/core/model/ScrapDeleteResult.kt | 8 ++++++++ .../datasource/ScrapNetworkDataSource.kt | 7 ++++--- ...kBriefingArticle.kt => NetworkBriefing.kt} | 17 +++++++++++++++- ...NetworkMemberToken.kt => NetworkMember.kt} | 9 ++++++--- .../network/model/{scrap => }/NetworkScrap.kt | 20 ++++++++++++++++++- .../briefing/NetworkBriefingArticleRelated.kt | 10 ---------- .../briefing/NetworkBriefingArticleSummary.kt | 11 ---------- .../model/member/NetworkMemberDelete.kt | 8 -------- .../network/model/scrap/NetworkScrapCreate.kt | 14 ------------- .../network/model/scrap/NetworkScrapDelete.kt | 10 ---------- .../retrofit/api/RetrofitBriefingNetwork.kt | 6 ++---- .../retrofit/api/RetrofitMemberNetwork.kt | 4 ++-- .../retrofit/api/RetrofitScrapNetwork.kt | 8 +++----- 20 files changed, 134 insertions(+), 72 deletions(-) create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticle.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleRelated.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleSummary.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/MemberDeleteResult.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/MemberToken.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/Scrap.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/ScrapCreateResult.kt create mode 100644 core/model/src/main/java/store/newsbriefing/app/core/model/ScrapDeleteResult.kt rename core/network/src/main/java/store/newsbriefing/app/core/network/model/{briefing/NetworkBriefingArticle.kt => NetworkBriefing.kt} (60%) rename core/network/src/main/java/store/newsbriefing/app/core/network/model/{member/NetworkMemberToken.kt => NetworkMember.kt} (65%) rename core/network/src/main/java/store/newsbriefing/app/core/network/model/{scrap => }/NetworkScrap.kt (50%) delete mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleRelated.kt delete mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleSummary.kt delete mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberDelete.kt delete mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapCreate.kt delete mode 100644 core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapDelete.kt diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticle.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticle.kt new file mode 100644 index 0000000..d8b94ff --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticle.kt @@ -0,0 +1,20 @@ +package store.newsbriefing.app.core.model + +import java.time.ZonedDateTime + +data class BriefingArticle( + val id: Long, + val ranks: Int, + val title: String, + val subtitle: String, + val content: String, + val date: ZonedDateTime, + val articles: List, + val isScrap: Boolean, + val isBriefingOpen: Boolean, + val isWarning: Boolean, + val scrapCount: Int, + val gptModel: String, + val timeOfDay: String, + val type: String +) diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleRelated.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleRelated.kt new file mode 100644 index 0000000..ce9c81d --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleRelated.kt @@ -0,0 +1,8 @@ +package store.newsbriefing.app.core.model + +data class BriefingArticleRelated( + val id: Int, + val press: String, + val title: String, + val url: String +) \ No newline at end of file diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleSummary.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleSummary.kt new file mode 100644 index 0000000..6f11350 --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/BriefingArticleSummary.kt @@ -0,0 +1,9 @@ +package store.newsbriefing.app.core.model + +data class BriefingArticleSummary( + val id: Int, + val ranks: Int, + val title: String, + val subtitle: String, + val scrapCount: Int +) \ No newline at end of file diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/MemberDeleteResult.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/MemberDeleteResult.kt new file mode 100644 index 0000000..e0debb4 --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/MemberDeleteResult.kt @@ -0,0 +1,7 @@ +package store.newsbriefing.app.core.model + +import java.time.ZonedDateTime + +data class MemberDeleteResult( + val quitAt: ZonedDateTime +) \ No newline at end of file diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/MemberToken.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/MemberToken.kt new file mode 100644 index 0000000..069efdf --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/MemberToken.kt @@ -0,0 +1,7 @@ +package store.newsbriefing.app.core.model + +data class MemberToken( + val memberId: Long, + val accessToken: String, + val refreshToken: String +) \ No newline at end of file diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/Scrap.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/Scrap.kt new file mode 100644 index 0000000..becd602 --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/Scrap.kt @@ -0,0 +1,13 @@ +package store.newsbriefing.app.core.model + +import java.time.ZonedDateTime + +data class Scrap( + val briefingId: Int, + val ranks: Int, + val title: String, + val subtitle: String, + val date: ZonedDateTime, + val gptModel: String, + val timeOfDay: String, +) \ No newline at end of file diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/ScrapCreateResult.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/ScrapCreateResult.kt new file mode 100644 index 0000000..d6ba5b1 --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/ScrapCreateResult.kt @@ -0,0 +1,10 @@ +package store.newsbriefing.app.core.model + +import java.time.ZonedDateTime + +data class ScrapCreateResult( + val scrapId: Int, + val memberId: Int, + val briefingId: Int, + val createdAt: ZonedDateTime, +) \ No newline at end of file diff --git a/core/model/src/main/java/store/newsbriefing/app/core/model/ScrapDeleteResult.kt b/core/model/src/main/java/store/newsbriefing/app/core/model/ScrapDeleteResult.kt new file mode 100644 index 0000000..b81cc35 --- /dev/null +++ b/core/model/src/main/java/store/newsbriefing/app/core/model/ScrapDeleteResult.kt @@ -0,0 +1,8 @@ +package store.newsbriefing.app.core.model + +import java.time.ZonedDateTime + +data class ScrapDeleteResult( + val scrapId: Int, + val deletedAt: ZonedDateTime +) diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/ScrapNetworkDataSource.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/ScrapNetworkDataSource.kt index 466f4d3..b84a9a3 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/ScrapNetworkDataSource.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/ScrapNetworkDataSource.kt @@ -1,8 +1,9 @@ package store.newsbriefing.app.core.network.datasource -import store.newsbriefing.app.core.network.model.scrap.NetworkScrap -import store.newsbriefing.app.core.network.model.scrap.NetworkScrapCreate -import store.newsbriefing.app.core.network.model.scrap.NetworkScrapDelete +import store.newsbriefing.app.core.network.model.NetworkScrap +import store.newsbriefing.app.core.network.model.NetworkScrapCreate +import store.newsbriefing.app.core.network.model.NetworkScrapDelete + interface ScrapNetworkDataSource { suspend fun getScrap(memberId: Long): List diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticle.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkBriefing.kt similarity index 60% rename from core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticle.kt rename to core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkBriefing.kt index 90af9da..5060321 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticle.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkBriefing.kt @@ -1,4 +1,4 @@ -package store.newsbriefing.app.core.network.model.briefing +package store.newsbriefing.app.core.network.model import com.google.gson.annotations.SerializedName @@ -17,4 +17,19 @@ data class NetworkBriefingArticle( @SerializedName("gptModel") val gptModel: String, @SerializedName("timeOfDay") val timeOfDay: String, @SerializedName("type") val type: String +) + +data class NetworkBriefingArticleRelated( + @SerializedName("id") val id: Int, + @SerializedName("press") val press: String, + @SerializedName("title") val title: String, + @SerializedName("url") val url: String +) + +data class NetworkBriefingArticleSummary( + @SerializedName("id") val id: Int, + @SerializedName("ranks") val ranks: Int, + @SerializedName("title") val title: String, + @SerializedName("subtitle") val subtitle: String, + @SerializedName("scrapCount") val scrapCount: Int ) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberToken.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkMember.kt similarity index 65% rename from core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberToken.kt rename to core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkMember.kt index f8d3e40..515141c 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberToken.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkMember.kt @@ -1,7 +1,11 @@ -package store.newsbriefing.app.core.network.model.member +package store.newsbriefing.app.core.network.model import com.google.gson.annotations.SerializedName +data class NetworkMemberDelete( + @SerializedName("quitAt") + val quitAt : String) + data class NetworkMemberToken( @SerializedName("memberId") val memberId: Long, @@ -9,5 +13,4 @@ data class NetworkMemberToken( val accessToken: String, @SerializedName("refreshToken") val refreshToken: String -) { -} \ No newline at end of file +) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrap.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkScrap.kt similarity index 50% rename from core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrap.kt rename to core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkScrap.kt index 05d2cab..c2e5890 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrap.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkScrap.kt @@ -1,4 +1,4 @@ -package store.newsbriefing.app.core.network.model.scrap +package store.newsbriefing.app.core.network.model import com.google.gson.annotations.SerializedName @@ -17,4 +17,22 @@ data class NetworkScrap( val gptModel: String, @SerializedName("timeOfDay") val timeOfDay: String, +) + +data class NetworkScrapCreate( + @SerializedName("scrapId") + val scrapId: Int, + @SerializedName("memberId") + val memberId: Int, + @SerializedName("briefingId") + val briefingId: Int, + @SerializedName("createdAt") + val createdAt: String, +) + +class NetworkScrapDelete( + @SerializedName("scrapId") + val scrapId: Int, + @SerializedName("deletedAt") + val deletedAt: String ) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleRelated.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleRelated.kt deleted file mode 100644 index 1612aa5..0000000 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleRelated.kt +++ /dev/null @@ -1,10 +0,0 @@ -package store.newsbriefing.app.core.network.model.briefing - -import com.google.gson.annotations.SerializedName - -data class NetworkBriefingArticleRelated( - @SerializedName("id") val id: Int, - @SerializedName("press") val press: String, - @SerializedName("title") val title: String, - @SerializedName("url") val url: String -) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleSummary.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleSummary.kt deleted file mode 100644 index 21bbd02..0000000 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/briefing/NetworkBriefingArticleSummary.kt +++ /dev/null @@ -1,11 +0,0 @@ -package store.newsbriefing.app.core.network.model.briefing - -import com.google.gson.annotations.SerializedName - -data class NetworkBriefingArticleSummary( - @SerializedName("id") val id: Int, - @SerializedName("ranks") val ranks: Int, - @SerializedName("title") val title: String, - @SerializedName("subtitle") val subtitle: String, - @SerializedName("scrapCount") val scrapCount: Int -) {} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberDelete.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberDelete.kt deleted file mode 100644 index a0cf585..0000000 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/member/NetworkMemberDelete.kt +++ /dev/null @@ -1,8 +0,0 @@ -package store.newsbriefing.app.core.network.model.member - -import com.google.gson.annotations.SerializedName - -data class NetworkMemberDelete( - @SerializedName("quitAt") - val quitAt : String) { -} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapCreate.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapCreate.kt deleted file mode 100644 index 9976c8f..0000000 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapCreate.kt +++ /dev/null @@ -1,14 +0,0 @@ -package store.newsbriefing.app.core.network.model.scrap - -import com.google.gson.annotations.SerializedName - -data class NetworkScrapCreate( - @SerializedName("scrapId") - val scrapId: Int, - @SerializedName("memberId") - val memberId: Int, - @SerializedName("briefingId") - val briefingId: Int, - @SerializedName("createdAt") - val createdAt: String, -) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapDelete.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapDelete.kt deleted file mode 100644 index 750f132..0000000 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/scrap/NetworkScrapDelete.kt +++ /dev/null @@ -1,10 +0,0 @@ -package store.newsbriefing.app.core.network.model.scrap - -import com.google.gson.annotations.SerializedName - -class NetworkScrapDelete( - @SerializedName("scrapId") - val scrapId: Int, - @SerializedName("deletedAt") - val deletedAt: String -) \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitBriefingNetwork.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitBriefingNetwork.kt index 1498cb7..8b6d284 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitBriefingNetwork.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitBriefingNetwork.kt @@ -10,11 +10,9 @@ import retrofit2.http.Query import store.newsbriefing.app.core.model.BriefingArticleCategory import store.newsbriefing.app.core.model.TimeOfDay import store.newsbriefing.app.core.network.datasource.BriefingNetworkDataSource +import store.newsbriefing.app.core.network.model.NetworkBriefingArticle +import store.newsbriefing.app.core.network.model.NetworkBriefingArticleSummary import store.newsbriefing.app.core.network.model.RetrofitCommonResponse -import store.newsbriefing.app.core.network.model.briefing.NetworkBriefingArticle -import store.newsbriefing.app.core.network.model.briefing.NetworkBriefingArticleSummary -import store.newsbriefing.app.core.network.model.member.NetworkMemberDelete -import store.newsbriefing.app.core.network.model.member.NetworkMemberToken import java.time.LocalDate import java.time.format.DateTimeFormatter import javax.inject.Inject diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitMemberNetwork.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitMemberNetwork.kt index 846fd1e..0a5fda8 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitMemberNetwork.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitMemberNetwork.kt @@ -9,8 +9,8 @@ import retrofit2.http.POST import retrofit2.http.Path import retrofit2.http.Query import store.newsbriefing.app.core.network.datasource.MemberNetworkDataSource -import store.newsbriefing.app.core.network.model.member.NetworkMemberDelete -import store.newsbriefing.app.core.network.model.member.NetworkMemberToken +import store.newsbriefing.app.core.network.model.NetworkMemberDelete +import store.newsbriefing.app.core.network.model.NetworkMemberToken import store.newsbriefing.app.core.network.model.RetrofitCommonResponse import javax.inject.Inject import javax.inject.Singleton diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitScrapNetwork.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitScrapNetwork.kt index ace8e6f..742dac0 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitScrapNetwork.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/retrofit/api/RetrofitScrapNetwork.kt @@ -9,12 +9,10 @@ import retrofit2.http.POST import retrofit2.http.Path import retrofit2.http.Query import store.newsbriefing.app.core.network.datasource.ScrapNetworkDataSource +import store.newsbriefing.app.core.network.model.NetworkScrap +import store.newsbriefing.app.core.network.model.NetworkScrapCreate +import store.newsbriefing.app.core.network.model.NetworkScrapDelete import store.newsbriefing.app.core.network.model.RetrofitCommonResponse -import store.newsbriefing.app.core.network.model.member.NetworkMemberDelete -import store.newsbriefing.app.core.network.model.member.NetworkMemberToken -import store.newsbriefing.app.core.network.model.scrap.NetworkScrap -import store.newsbriefing.app.core.network.model.scrap.NetworkScrapCreate -import store.newsbriefing.app.core.network.model.scrap.NetworkScrapDelete import javax.inject.Inject import javax.inject.Singleton From a57c3e939d7b7491e1e21227734421c68090441f Mon Sep 17 00:00:00 2001 From: Gyeongrok Kim Date: Sun, 3 Mar 2024 18:29:31 +0900 Subject: [PATCH 3/3] feat: add repositories of data source added --- core/data/build.gradle.kts | 5 +++ .../data/repository/BriefingRepository.kt | 18 ++++++++ .../repository/DefaultBriefingRepository.kt | 36 +++++++++++++++ .../repository/DefaultMemberRepository.kt | 29 ++++++++++++ .../data/repository/DefaultScrapRepository.kt | 27 ++++++++++++ .../core/data/repository/MemberRepository.kt | 12 +++++ .../core/data/repository/ScrapRepository.kt | 12 +++++ .../app/core/data/repository/di/DataModule.kt | 31 +++++++++++++ .../datasource/BriefingNetworkDataSource.kt | 4 +- .../datasource/MemberNetworkDataSource.kt | 5 ++- .../app/core/network/model/NetworkBriefing.kt | 44 ++++++++++++++++++- .../app/core/network/model/NetworkMember.kt | 19 +++++++- .../app/core/network/model/NetworkScrap.kt | 32 +++++++++++++- 13 files changed, 267 insertions(+), 7 deletions(-) create mode 100644 core/data/src/main/java/store/newsbriefing/app/core/data/repository/BriefingRepository.kt create mode 100644 core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultBriefingRepository.kt create mode 100644 core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultMemberRepository.kt create mode 100644 core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultScrapRepository.kt create mode 100644 core/data/src/main/java/store/newsbriefing/app/core/data/repository/MemberRepository.kt create mode 100644 core/data/src/main/java/store/newsbriefing/app/core/data/repository/ScrapRepository.kt create mode 100644 core/data/src/main/java/store/newsbriefing/app/core/data/repository/di/DataModule.kt diff --git a/core/data/build.gradle.kts b/core/data/build.gradle.kts index 52f2826..2e83af7 100644 --- a/core/data/build.gradle.kts +++ b/core/data/build.gradle.kts @@ -1,5 +1,6 @@ plugins { alias(libs.plugins.briefing.android.library) + alias(libs.plugins.briefing.android.hilt) } android { @@ -7,5 +8,9 @@ android { } dependencies { + api(projects.core.model) api(projects.core.network) + api(projects.core.common) + + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.8.0") } \ No newline at end of file diff --git a/core/data/src/main/java/store/newsbriefing/app/core/data/repository/BriefingRepository.kt b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/BriefingRepository.kt new file mode 100644 index 0000000..f3ba727 --- /dev/null +++ b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/BriefingRepository.kt @@ -0,0 +1,18 @@ +package store.newsbriefing.app.core.data.repository + +import kotlinx.coroutines.flow.Flow +import store.newsbriefing.app.core.model.BriefingArticle +import store.newsbriefing.app.core.model.BriefingArticleCategory +import store.newsbriefing.app.core.model.BriefingArticleSummary +import store.newsbriefing.app.core.model.TimeOfDay +import java.time.LocalDate + +interface BriefingRepository { + suspend fun getBriefingArticleSummaries( + briefingArticleCategory: BriefingArticleCategory, + dateLocalDate: LocalDate?, + timeOfDay: TimeOfDay? + ): Flow> + + suspend fun getBriefingArticle(articleId: Long): Flow +} \ No newline at end of file diff --git a/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultBriefingRepository.kt b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultBriefingRepository.kt new file mode 100644 index 0000000..ff5b962 --- /dev/null +++ b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultBriefingRepository.kt @@ -0,0 +1,36 @@ +package store.newsbriefing.app.core.data.repository + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import store.newsbriefing.app.core.model.BriefingArticle +import store.newsbriefing.app.core.model.BriefingArticleCategory +import store.newsbriefing.app.core.model.BriefingArticleSummary +import store.newsbriefing.app.core.model.TimeOfDay +import store.newsbriefing.app.core.network.datasource.BriefingNetworkDataSource +import store.newsbriefing.app.core.network.model.asExternalModel +import java.time.LocalDate + +internal class DefaultBriefingRepository( + private val briefingNetworkDataSource: BriefingNetworkDataSource +) : BriefingRepository { + override suspend fun getBriefingArticleSummaries( + briefingArticleCategory: BriefingArticleCategory, + dateLocalDate: LocalDate?, + timeOfDay: TimeOfDay? + ): Flow> = flow { + val summaries = briefingNetworkDataSource.getBriefingArticleSummaries( + briefingArticleCategory, + dateLocalDate, + timeOfDay + ) + emit(summaries.map { + it.asExternalModel() + }) + } + + override suspend fun getBriefingArticle(articleId: Long): Flow { + return flow { + emit(briefingNetworkDataSource.getBriefingArticle(articleId).asExternalModel()) + } + } +} \ No newline at end of file diff --git a/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultMemberRepository.kt b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultMemberRepository.kt new file mode 100644 index 0000000..84e7be6 --- /dev/null +++ b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultMemberRepository.kt @@ -0,0 +1,29 @@ +package store.newsbriefing.app.core.data.repository + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import store.newsbriefing.app.core.model.MemberDeleteResult +import store.newsbriefing.app.core.model.MemberToken +import store.newsbriefing.app.core.network.datasource.MemberNetworkDataSource +import store.newsbriefing.app.core.network.model.asExternalModel + +internal class DefaultMemberRepository(val memberNetworkDataSource: MemberNetworkDataSource) : + MemberRepository { + override suspend fun deleteMember(memberId: Long): Flow = flow { + emit(memberNetworkDataSource.deleteMember(memberId).asExternalModel()) + } + + override suspend fun getTokenWithSocialProvider( + provider: String, + identityToken: String + ): Flow = flow { + emit( + memberNetworkDataSource.getTokenWithSocialProvider(provider, identityToken) + .asExternalModel() + ) + } + + override suspend fun getRefreshedAccessToken(refreshToken: String): Flow = flow { + emit(memberNetworkDataSource.getRefreshedAccessToken(refreshToken).asExternalModel()) + } +} \ No newline at end of file diff --git a/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultScrapRepository.kt b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultScrapRepository.kt new file mode 100644 index 0000000..a8dba1d --- /dev/null +++ b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/DefaultScrapRepository.kt @@ -0,0 +1,27 @@ +package store.newsbriefing.app.core.data.repository + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import store.newsbriefing.app.core.model.Scrap +import store.newsbriefing.app.core.model.ScrapCreateResult +import store.newsbriefing.app.core.model.ScrapDeleteResult +import store.newsbriefing.app.core.network.datasource.ScrapNetworkDataSource +import store.newsbriefing.app.core.network.model.asExternalModel + +internal class DefaultScrapRepository(private val scrapNetworkDataSource: ScrapNetworkDataSource) : ScrapRepository { + override fun getScrap(memberId: Long): Flow> = flow { + val scraps = scrapNetworkDataSource.getScrap(memberId).map { it.asExternalModel() } + emit(scraps) + } + + override fun setScrap(memberId: Long, articleId: Long): Flow = flow { + val result = scrapNetworkDataSource.setScrap(memberId, articleId).asExternalModel() + emit(result) + } + + override fun unScrap(memberId: Long, articleId: Long): Flow = flow { + val result = scrapNetworkDataSource.unScrap(memberId, articleId).asExternalModel() + emit(result) + } + +} \ No newline at end of file diff --git a/core/data/src/main/java/store/newsbriefing/app/core/data/repository/MemberRepository.kt b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/MemberRepository.kt new file mode 100644 index 0000000..66e115d --- /dev/null +++ b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/MemberRepository.kt @@ -0,0 +1,12 @@ +package store.newsbriefing.app.core.data.repository + +import kotlinx.coroutines.flow.Flow +import store.newsbriefing.app.core.model.MemberDeleteResult +import store.newsbriefing.app.core.model.MemberToken + +interface MemberRepository { + + suspend fun deleteMember(memberId: Long): Flow + suspend fun getTokenWithSocialProvider(provider: String, identityToken: String): Flow + suspend fun getRefreshedAccessToken(refreshToken: String): Flow +} \ No newline at end of file diff --git a/core/data/src/main/java/store/newsbriefing/app/core/data/repository/ScrapRepository.kt b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/ScrapRepository.kt new file mode 100644 index 0000000..f9bcaab --- /dev/null +++ b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/ScrapRepository.kt @@ -0,0 +1,12 @@ +package store.newsbriefing.app.core.data.repository + +import kotlinx.coroutines.flow.Flow +import store.newsbriefing.app.core.model.Scrap +import store.newsbriefing.app.core.model.ScrapCreateResult +import store.newsbriefing.app.core.model.ScrapDeleteResult + +interface ScrapRepository { + fun getScrap(memberId: Long): Flow> + fun setScrap(memberId: Long, articleId: Long): Flow + fun unScrap(memberId: Long, articleId: Long): Flow +} \ No newline at end of file diff --git a/core/data/src/main/java/store/newsbriefing/app/core/data/repository/di/DataModule.kt b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/di/DataModule.kt new file mode 100644 index 0000000..9c8eaea --- /dev/null +++ b/core/data/src/main/java/store/newsbriefing/app/core/data/repository/di/DataModule.kt @@ -0,0 +1,31 @@ +package store.newsbriefing.app.core.data.repository.di + +import dagger.Binds +import dagger.Module +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import store.newsbriefing.app.core.data.repository.BriefingRepository +import store.newsbriefing.app.core.data.repository.DefaultBriefingRepository +import store.newsbriefing.app.core.data.repository.DefaultMemberRepository +import store.newsbriefing.app.core.data.repository.DefaultScrapRepository +import store.newsbriefing.app.core.data.repository.MemberRepository +import store.newsbriefing.app.core.data.repository.ScrapRepository + +@Module +@InstallIn(SingletonComponent::class) +abstract class DataModule { + @Binds + internal abstract fun bindBriefingRepository( + repository: DefaultBriefingRepository + ): BriefingRepository + + @Binds + internal abstract fun bindMemberRepository( + repository: DefaultMemberRepository + ): MemberRepository + + @Binds + internal abstract fun bindScrapRepository( + repository: DefaultScrapRepository + ): ScrapRepository +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/BriefingNetworkDataSource.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/BriefingNetworkDataSource.kt index a5d343b..cb70637 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/BriefingNetworkDataSource.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/BriefingNetworkDataSource.kt @@ -2,8 +2,8 @@ package store.newsbriefing.app.core.network.datasource import store.newsbriefing.app.core.model.BriefingArticleCategory import store.newsbriefing.app.core.model.TimeOfDay -import store.newsbriefing.app.core.network.model.briefing.NetworkBriefingArticle -import store.newsbriefing.app.core.network.model.briefing.NetworkBriefingArticleSummary +import store.newsbriefing.app.core.network.model.NetworkBriefingArticle +import store.newsbriefing.app.core.network.model.NetworkBriefingArticleSummary import java.time.LocalDate interface BriefingNetworkDataSource { diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.kt index 27dfe10..926c3cb 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/datasource/MemberNetworkDataSource.kt @@ -1,7 +1,8 @@ package store.newsbriefing.app.core.network.datasource -import store.newsbriefing.app.core.network.model.member.NetworkMemberDelete -import store.newsbriefing.app.core.network.model.member.NetworkMemberToken +import store.newsbriefing.app.core.network.model.NetworkMemberDelete +import store.newsbriefing.app.core.network.model.NetworkMemberToken + interface MemberNetworkDataSource { suspend fun deleteMember(memberId: Long): NetworkMemberDelete diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkBriefing.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkBriefing.kt index 5060321..28831f7 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkBriefing.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkBriefing.kt @@ -1,6 +1,10 @@ package store.newsbriefing.app.core.network.model import com.google.gson.annotations.SerializedName +import store.newsbriefing.app.core.common.toZoneDateTime +import store.newsbriefing.app.core.model.BriefingArticle +import store.newsbriefing.app.core.model.BriefingArticleRelated +import store.newsbriefing.app.core.model.BriefingArticleSummary data class NetworkBriefingArticle( @SerializedName("id") val id: Long, @@ -19,6 +23,25 @@ data class NetworkBriefingArticle( @SerializedName("type") val type: String ) +fun NetworkBriefingArticle.asExternalModel(): BriefingArticle { + return BriefingArticle( + id = id, + ranks = ranks, + title = title, + subtitle = subtitle, + content = content, + date = date.toZoneDateTime(), + articles = articles.map { it.asExternalModel() }, + isScrap = isScrap, + isBriefingOpen = isBriefingOpen, + isWarning = isWarning, + scrapCount = scrapCount, + gptModel = gptModel, + timeOfDay = timeOfDay, + type = type + ) +} + data class NetworkBriefingArticleRelated( @SerializedName("id") val id: Int, @SerializedName("press") val press: String, @@ -26,10 +49,29 @@ data class NetworkBriefingArticleRelated( @SerializedName("url") val url: String ) +fun NetworkBriefingArticleRelated.asExternalModel(): BriefingArticleRelated { + return BriefingArticleRelated( + id = id, + press = press, + title = title, + url = url + ) +} + data class NetworkBriefingArticleSummary( @SerializedName("id") val id: Int, @SerializedName("ranks") val ranks: Int, @SerializedName("title") val title: String, @SerializedName("subtitle") val subtitle: String, @SerializedName("scrapCount") val scrapCount: Int -) \ No newline at end of file +) + +fun NetworkBriefingArticleSummary.asExternalModel(): BriefingArticleSummary { + return BriefingArticleSummary( + id = id, + ranks = ranks, + title = title, + subtitle = subtitle, + scrapCount = scrapCount + ) +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkMember.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkMember.kt index 515141c..f67fbee 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkMember.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkMember.kt @@ -1,11 +1,20 @@ package store.newsbriefing.app.core.network.model import com.google.gson.annotations.SerializedName +import store.newsbriefing.app.core.common.toZoneDateTime +import store.newsbriefing.app.core.model.MemberDeleteResult +import store.newsbriefing.app.core.model.MemberToken data class NetworkMemberDelete( @SerializedName("quitAt") val quitAt : String) +fun NetworkMemberDelete.asExternalModel() : MemberDeleteResult { + return MemberDeleteResult( + quitAt = quitAt.toZoneDateTime() + ) +} + data class NetworkMemberToken( @SerializedName("memberId") val memberId: Long, @@ -13,4 +22,12 @@ data class NetworkMemberToken( val accessToken: String, @SerializedName("refreshToken") val refreshToken: String -) \ No newline at end of file +) + +fun NetworkMemberToken.asExternalModel() : MemberToken { + return MemberToken( + memberId = memberId, + accessToken = accessToken, + refreshToken = refreshToken + ) +} \ No newline at end of file diff --git a/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkScrap.kt b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkScrap.kt index c2e5890..0baadd2 100644 --- a/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkScrap.kt +++ b/core/network/src/main/java/store/newsbriefing/app/core/network/model/NetworkScrap.kt @@ -1,6 +1,10 @@ package store.newsbriefing.app.core.network.model import com.google.gson.annotations.SerializedName +import store.newsbriefing.app.core.common.toZoneDateTime +import store.newsbriefing.app.core.model.Scrap +import store.newsbriefing.app.core.model.ScrapCreateResult +import store.newsbriefing.app.core.model.ScrapDeleteResult data class NetworkScrap( @SerializedName("briefingId") @@ -19,6 +23,16 @@ data class NetworkScrap( val timeOfDay: String, ) +fun NetworkScrap.asExternalModel() = Scrap( + briefingId = briefingId, + ranks = ranks, + title = title, + subtitle = subtitle, + date = date.toZoneDateTime(), + gptModel = gptModel, + timeOfDay = timeOfDay +) + data class NetworkScrapCreate( @SerializedName("scrapId") val scrapId: Int, @@ -30,9 +44,25 @@ data class NetworkScrapCreate( val createdAt: String, ) +fun NetworkScrapCreate.asExternalModel(): ScrapCreateResult { + return ScrapCreateResult( + scrapId = scrapId, + memberId = memberId, + briefingId = briefingId, + createdAt = createdAt.toZoneDateTime() + ) +} + class NetworkScrapDelete( @SerializedName("scrapId") val scrapId: Int, @SerializedName("deletedAt") val deletedAt: String -) \ No newline at end of file +) + +fun NetworkScrapDelete.asExternalModel(): ScrapDeleteResult { + return ScrapDeleteResult( + scrapId = scrapId, + deletedAt = deletedAt.toZoneDateTime() + ) +} \ No newline at end of file