Skip to content

Commit

Permalink
Merge pull request #74 from team-JMT/feat/mypage_registered
Browse files Browse the repository at this point in the history
Feat/mypage registered
  • Loading branch information
soopeach authored Sep 24, 2023
2 parents e58272c + b81442e commit c101a64
Show file tree
Hide file tree
Showing 17 changed files with 313 additions and 43 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,9 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

// Stetho
implementation 'com.facebook.stetho:stetho:1.6.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
implementation 'com.facebook.stetho:stetho-js-rhino:1.6.0'
}
6 changes: 6 additions & 0 deletions app/src/main/java/org/gdsc/jmt/App.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package org.gdsc.jmt

import android.app.Application
import com.facebook.stetho.Stetho
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class App: Application() {

override fun onCreate() {
super.onCreate()

if (BuildConfig.DEBUG) Stetho.initializeWithDefaults(this)
}
}
5 changes: 5 additions & 0 deletions data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,9 @@ dependencies {
implementation "androidx.room:room-ktx:2.5.0"
implementation "androidx.room:room-paging:2.5.0"
kapt "androidx.room:room-compiler:2.5.0"

// Stetho
implementation 'com.facebook.stetho:stetho:1.6.0'
implementation 'com.facebook.stetho:stetho-okhttp3:1.6.0'
implementation 'com.facebook.stetho:stetho-js-rhino:1.6.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RestaurantMediator(
): RemoteMediator<Int,RegisteredRestaurant>() {
private val userDao = db.restaurantDao()
private var currentPageNumber = 0
var totalElementsCount = 0

override suspend fun load(
loadType: LoadType,
Expand Down Expand Up @@ -51,6 +52,7 @@ class RestaurantMediator(

val repos = response.data
currentPageNumber = repos.page.currentPage
totalElementsCount = repos.page.totalElements
val endOfPaginationReached = repos.page.pageLast
if(repos.restaurants.isNotEmpty()) {
db.withTransaction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gdsc.domain.DrinkPossibility
import org.gdsc.domain.FoodCategory
import org.gdsc.domain.SortType
import org.gdsc.domain.model.Location
import org.gdsc.domain.model.PagingResult
import org.gdsc.domain.model.RestaurantLocationInfo
import org.gdsc.domain.model.request.ModifyRestaurantInfoRequest
import org.gdsc.domain.model.request.RestaurantRegistrationRequest
Expand All @@ -30,7 +31,7 @@ interface RestaurantDataSource {

suspend fun getRestaurants(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
): Flow<PagingData<RegisteredRestaurant>>
): Flow<PagingResult<RegisteredRestaurant>>

suspend fun putRestaurantInfo(putRestaurantInfoRequest: ModifyRestaurantInfoRequest): String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import okhttp3.RequestBody.Companion.toRequestBody
import org.gdsc.data.database.RegisteredRestaurant
import org.gdsc.data.database.RestaurantDatabase
Expand All @@ -17,6 +18,7 @@ import org.gdsc.domain.RestaurantRegistrationState
import org.gdsc.domain.SortType
import org.gdsc.domain.model.Filter
import org.gdsc.domain.model.Location
import org.gdsc.domain.model.PagingResult
import org.gdsc.domain.model.RestaurantLocationInfo
import org.gdsc.domain.model.request.ModifyRestaurantInfoRequest
import org.gdsc.domain.model.request.RestaurantRegistrationRequest
Expand Down Expand Up @@ -88,7 +90,7 @@ class RestaurantDataSourceImpl @Inject constructor(
@OptIn(ExperimentalPagingApi::class)
override suspend fun getRestaurants(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
): Flow<PagingData<RegisteredRestaurant>> {
): Flow<PagingResult<RegisteredRestaurant>> {
val categoryFilter = when (foodCategory) {
FoodCategory.INIT, FoodCategory.ETC -> null
else -> foodCategory.text
Expand All @@ -109,18 +111,19 @@ class RestaurantDataSourceImpl @Inject constructor(
)

val restaurantSearchMapRequest = RestaurantSearchMapRequest(locationData, filter)
val mediator = RestaurantMediator(
userId = userId,
restaurantSearchMapRequest = restaurantSearchMapRequest,
db = db,
api = restaurantAPI,
)

return Pager(
config = PagingConfig(
pageSize = 20,
enablePlaceholders = false
),
remoteMediator = RestaurantMediator(
userId = userId,
restaurantSearchMapRequest = restaurantSearchMapRequest,
db = db,
api = restaurantAPI,
)
remoteMediator = mediator,
) {
with(db.restaurantDao()) {
when (sortType) {
Expand All @@ -132,6 +135,10 @@ class RestaurantDataSourceImpl @Inject constructor(
}

}.flow
.map { data ->
val totalElementsCount = mediator.totalElementsCount
PagingResult(data, totalElementsCount)
}
}

override suspend fun putRestaurantInfo(putRestaurantInfoRequest: ModifyRestaurantInfoRequest): String {
Expand Down
20 changes: 16 additions & 4 deletions data/src/main/java/org/gdsc/data/di/NetworkModule.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.gdsc.data.di

import android.content.Context
import com.facebook.stetho.okhttp3.StethoInterceptor
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.gdsc.data.BuildConfig
import org.gdsc.data.network.AuthInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
Expand Down Expand Up @@ -53,11 +55,21 @@ class NetworkModule {
private val baseClientBuilder: OkHttpClient.Builder
get() = run {
val clientBuilder = OkHttpClient.Builder()
val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY

clientBuilder.apply {
if (BuildConfig.DEBUG) {
addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.HEADERS
})

addInterceptor(HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
})

addNetworkInterceptor(StethoInterceptor())
}
}
return clientBuilder.addInterceptor(loggingInterceptor)
return clientBuilder
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.gdsc.domain.DrinkPossibility
import org.gdsc.domain.FoodCategory
import org.gdsc.domain.SortType
import org.gdsc.domain.model.Location
import org.gdsc.domain.model.PagingResult
import org.gdsc.domain.model.RegisteredRestaurant
import org.gdsc.domain.model.RestaurantLocationInfo
import org.gdsc.domain.model.request.ModifyRestaurantInfoRequest
Expand Down Expand Up @@ -46,35 +47,37 @@ class RestaurantRepositoryImpl @Inject constructor(

override suspend fun getRestaurants(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
): Flow<PagingData<RegisteredRestaurant>> {
): Flow<PagingResult<RegisteredRestaurant>> {
return restaurantDataSource.getRestaurants(
userId,
locationData,
sortType,
foodCategory,
drinkPossibility
).map { pagingData ->
val pagingTemp = pagingData.map { restaurant ->
val restaurantTemp = RegisteredRestaurant(
id = restaurant.id,
name = restaurant.name,
placeUrl = restaurant.placeUrl,
phone = restaurant.phone,
address = restaurant.address,
roadAddress = restaurant.roadAddress,
x = restaurant.x,
y = restaurant.y,
restaurantImageUrl = restaurant.restaurantImageUrl,
introduce = restaurant.introduce,
category = restaurant.category,
userId = userId,
userNickName = restaurant.userNickName,
userProfileImageUrl = restaurant.userProfileImageUrl,
canDrinkLiquor = restaurant.canDrinkLiquor,
differenceInDistance = restaurant.differenceInDistance,
)
restaurantTemp
}
).map { result ->

val pagingTemp = PagingResult(
result.data.map { restaurant ->
val restaurantTemp = RegisteredRestaurant(
id = restaurant.id,
name = restaurant.name,
placeUrl = restaurant.placeUrl,
phone = restaurant.phone,
address = restaurant.address,
roadAddress = restaurant.roadAddress,
x = restaurant.x,
y = restaurant.y,
restaurantImageUrl = restaurant.restaurantImageUrl,
introduce = restaurant.introduce,
category = restaurant.category,
userId = userId,
userNickName = restaurant.userNickName,
userProfileImageUrl = restaurant.userProfileImageUrl,
canDrinkLiquor = restaurant.canDrinkLiquor,
differenceInDistance = restaurant.differenceInDistance,
)
restaurantTemp
}, result.totalElementsCount)
pagingTemp
}
}
Expand Down
8 changes: 8 additions & 0 deletions domain/src/main/java/org/gdsc/domain/model/PagingResult.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.gdsc.domain.model

import androidx.paging.PagingData

data class PagingResult<T : Any>(
val data: PagingData<T>,
val totalElementsCount: Int,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gdsc.domain.DrinkPossibility
import org.gdsc.domain.FoodCategory
import org.gdsc.domain.SortType
import org.gdsc.domain.model.Location
import org.gdsc.domain.model.PagingResult
import org.gdsc.domain.model.RegisteredRestaurant
import org.gdsc.domain.model.RestaurantLocationInfo
import org.gdsc.domain.model.request.ModifyRestaurantInfoRequest
Expand All @@ -30,7 +31,7 @@ interface RestaurantRepository {

suspend fun getRestaurants(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
): Flow<PagingData<RegisteredRestaurant>>
): Flow<PagingResult<RegisteredRestaurant>>

suspend fun putRestaurantInfo(putRestaurantInfoRequest: ModifyRestaurantInfoRequest): String

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gdsc.domain.DrinkPossibility
import org.gdsc.domain.FoodCategory
import org.gdsc.domain.SortType
import org.gdsc.domain.model.Location
import org.gdsc.domain.model.PagingResult
import org.gdsc.domain.model.RegisteredRestaurant
import org.gdsc.domain.model.request.RestaurantSearchMapRequest
import org.gdsc.domain.repository.RestaurantRepository
Expand All @@ -16,7 +17,7 @@ class GetRegisteredRestaurantUseCase @Inject constructor(
) {
suspend operator fun invoke(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
): Flow<PagingData<RegisteredRestaurant>> {
): Flow<PagingResult<RegisteredRestaurant>> {

return restaurantRepository.getRestaurants(userId, locationData, sortType, foodCategory, drinkPossibility)
}
Expand Down
Loading

0 comments on commit c101a64

Please sign in to comment.