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

[feature/api_get_university] 대학 목록 조회 API 연결 #84

Merged
merged 10 commits into from
Nov 9, 2023
Merged
6 changes: 6 additions & 0 deletions .github/workflows/EveryMeal_PR_Builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ jobs:
- name: Change gradlew permissions
run: chmod +x ./gradlew

- name: Add Local Properties
env:
BASE_URL: ${{ secrets.BASE_URL }}
run: |
echo baseUrl=BASE_URL >> ./local.properties

- name: Build debug APK
run: ./gradlew assembleDebug --stacktrace

Expand Down
9 changes: 9 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.kotlin.konan.properties.Properties
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
id("com.android.application")
Expand All @@ -23,6 +24,10 @@ android {
}
}

val localPropertiesFile = rootProject.file("local.properties")
val localProperties = Properties()
localProperties.load(localPropertiesFile.inputStream())

buildTypes {
release {
isMinifyEnabled = false
Expand All @@ -31,6 +36,9 @@ android {
"proguard-rules.pro"
)
}
debug {
buildConfigField("String", "BASE_URL", "\"${localProperties.getProperty("BASE_URL")}\"")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
Expand All @@ -41,6 +49,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.7"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.everymeal.everymeal_android.di

import com.everymeal.data.service.ExampleApi
import com.everymeal.data.service.onboarding.OnboardingApi
import com.everymeal.everymeal_android.BuildConfig
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import dagger.Module
import dagger.Provides
Expand All @@ -19,7 +20,7 @@ object NetworkModule {
private val contentType = "application/json".toMediaType()
private val json = Json { ignoreUnknownKeys = true }

private const val BASE_URL = "https://api.github.com/"
private const val BASE_URL = BuildConfig.BASE_URL

@Provides
@Singleton
Expand All @@ -42,7 +43,7 @@ object NetworkModule {

@Provides
@Singleton
fun provideApi(retrofit: Retrofit): ExampleApi {
return retrofit.create(ExampleApi::class.java)
fun provideOnboardingApi(retrofit: Retrofit): OnboardingApi {
return retrofit.create(OnboardingApi::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.everymeal.everymeal_android.di

import com.everymeal.data.datasource.FoodDataSource
import com.everymeal.data.datasource.FoodDataSourceImpl
import com.everymeal.data.repository.FoodRepositoryImpl
import com.everymeal.domain.repository.FoodRepository
import com.everymeal.data.datasource.onboarding.OnboardingDataSource
import com.everymeal.data.datasource.onboarding.OnboardingDataSourceImpl
import com.everymeal.data.repository.onboarding.OnboardingRepositoryImpl
import com.everymeal.domain.repository.onboarding.OnboardingRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -16,13 +16,13 @@ abstract class RepositoryModule {

@Singleton
@Binds
abstract fun bindFoodRepository(
foodRepositoryImpl: FoodRepositoryImpl,
) : FoodRepository
abstract fun bindOnboardingRepository(
onboardingRepositoryImpl: OnboardingRepositoryImpl
): OnboardingRepository

@Singleton
@Binds
abstract fun bindFoodV2DataSource(
foodDataSourceImpl: FoodDataSourceImpl
): FoodDataSource
abstract fun bindOnboardingDataSource(
onboardingDataSourceImpl: OnboardingDataSourceImpl
): OnboardingDataSource
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.everymeal.data.datasource.onboarding

import com.everymeal.data.model.onboarding.UniversityData

interface OnboardingDataSource {
suspend fun getUniversity(): Result<List<UniversityData>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.everymeal.data.datasource.onboarding

import com.everymeal.data.model.onboarding.UniversityData
import com.everymeal.data.model.unwrapData
import com.everymeal.data.service.onboarding.OnboardingApi
import javax.inject.Inject

class OnboardingDataSourceImpl @Inject constructor(
private val onboardingApi: OnboardingApi
) : OnboardingDataSource {

override suspend fun getUniversity(): Result<List<UniversityData>> {
return runCatching { onboardingApi.getUniversity() }.unwrapData()
}
}
14 changes: 14 additions & 0 deletions data/src/main/java/com/everymeal/data/model/BaseResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.everymeal.data.model

import kotlinx.serialization.Serializable

@Serializable
data class BaseResponse<T>(
val localDateTime: String,
val message: String,
val data: T,
)

fun <T> Result<BaseResponse<T>>.unwrapData(): Result<T> {
return this.map { it.data }
}
44 changes: 0 additions & 44 deletions data/src/main/java/com/everymeal/data/model/GetWeekFood.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.everymeal.data.model.onboarding

import com.everymeal.domain.model.onboarding.GetUniversityEntity
import kotlinx.serialization.Serializable

@Serializable
data class UniversityData(
val idx: Int,
val universityName: String,
val campusName: String,
val universityShortName: String
)

fun List<UniversityData>.toUniversityEntity(): GetUniversityEntity {
val universityDataList = this.map { result ->
GetUniversityEntity.UniversityData(
idx = result.idx,
universityName = result.universityName,
campusName = result.campusName,
universityShortName = result.universityShortName
)
}

return GetUniversityEntity(
data = universityDataList
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.everymeal.data.repository.onboarding

import com.everymeal.data.datasource.onboarding.OnboardingDataSource
import com.everymeal.data.model.onboarding.toUniversityEntity
import com.everymeal.domain.model.onboarding.GetUniversityEntity
import com.everymeal.domain.repository.onboarding.OnboardingRepository
import javax.inject.Inject

class OnboardingRepositoryImpl @Inject constructor(
private val onboardingDataSource: OnboardingDataSource
): OnboardingRepository {

override suspend fun getUniversity(): Result<GetUniversityEntity> {
return onboardingDataSource.getUniversity().map { it.toUniversityEntity() }
}
}
14 changes: 0 additions & 14 deletions data/src/main/java/com/everymeal/data/service/ExampleApi.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.everymeal.data.service.onboarding

import com.everymeal.data.model.BaseResponse
import com.everymeal.data.model.onboarding.UniversityData
import retrofit2.http.GET

interface OnboardingApi {

@GET("/api/v1/universities")
suspend fun getUniversity(): BaseResponse<List<UniversityData>>
}

This file was deleted.

7 changes: 0 additions & 7 deletions domain/src/main/java/com/everymeal/domain/model/Result.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.everymeal.domain.model.onboarding

data class GetUniversityEntity(
val data: List<UniversityData>
) {
data class UniversityData(
val idx: Int,
val universityName: String,
val campusName: String,
val universityShortName: String
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.everymeal.domain.repository.onboarding

import com.everymeal.domain.model.onboarding.GetUniversityEntity

interface OnboardingRepository {
suspend fun getUniversity(): Result<GetUniversityEntity>
}
Loading