Skip to content

Commit

Permalink
Merge branch 'develop' into feat/upgrade_search
Browse files Browse the repository at this point in the history
  • Loading branch information
soopeach authored Mar 18, 2024
2 parents 3a17126 + 314bbce commit b818d45
Show file tree
Hide file tree
Showing 53 changed files with 986 additions and 387 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.gdsc.data.database

import androidx.room.Database
import androidx.room.Entity
import androidx.room.PrimaryKey
import androidx.room.RoomDatabase

@Entity(tableName = "restaurant")
data class RegisteredRestaurant(
Expand All @@ -18,7 +20,9 @@ data class RegisteredRestaurant(
val category: String, // 식당 카테고리
val userId: Int, // 식당 등록한 유저 id
val userNickName: String, // 식당 등록한 유저 닉네임
val userProfileImageUrl: String, // 식당 등록한 유저 프로필 이미지
val userProfileImageUrl: String?, // 식당 등록한 유저 프로필 이미지
val canDrinkLiquor: Boolean, // 식당 주류 판매 여부
val differenceInDistance: String, // 식당과의 거리
val groupId: Int,
val groupName: String,
)
14 changes: 12 additions & 2 deletions data/src/main/java/org/gdsc/data/database/RestaurantDatabase.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase

@Database(entities = [RegisteredRestaurant::class], version = 4)
@Database(entities = [RegisteredRestaurant::class], version = 5)
abstract class RestaurantDatabase: RoomDatabase() {

abstract fun restaurantDao(): RestaurantDao
Expand All @@ -20,10 +22,18 @@ abstract class RestaurantDatabase: RoomDatabase() {
context.applicationContext,
RestaurantDatabase::class.java,
DATABASE_NAME
).build()
)
.addMigrations(MIGRATION_4_5)
.build()
INSTANCE = instance
instance
}
}
private val MIGRATION_4_5 = object : Migration(4, 5) {
override fun migrate(database: SupportSQLiteDatabase) {
database.execSQL("ALTER TABLE restaurant ADD COLUMN groupId INTEGER NOT NULL DEFAULT 0")
database.execSQL("ALTER TABLE restaurant ADD COLUMN groupName TEXT NOT NULL DEFAULT ''")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ interface RestaurantDataSource {

suspend fun postRestaurantLocationInfo(restaurantLocationInfo: RestaurantLocationInfo): String

suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String
suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest, groupId: Int): String

suspend fun getRestaurants(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
Expand All @@ -51,6 +51,8 @@ interface RestaurantDataSource {

suspend fun getRegisteredRestaurantsBySearch(keyword: String?, userLocation: Location?): Flow<PagingData<RegisteredRestaurantResponse>>

suspend fun getRegisteredRestaurantByMapWithLimitCount(sortType: SortType, currentGroup: Group?): List<RegisteredRestaurantResponse>

suspend fun getRegisteredRestaurantsBySearchWithLimitCount(keyword: String?, userLocation: Location?, limit: Int): List<RegisteredRestaurantResponse>

suspend fun getRestaurantReviews(restaurantId: Int): ReviewPaging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ class RestaurantDataSourceImpl @Inject constructor(
return restaurantAPI.postRestaurantLocationInfo(restaurantLocationInfo).data
}

override suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String {
override suspend fun postRestaurantInfo(
restaurantRegistrationRequest: RestaurantRegistrationRequest,
groupId: Int,
): String {
runCatching {
restaurantAPI.postRestaurantInfo(
mapOf(
Expand All @@ -100,7 +103,7 @@ class RestaurantDataSourceImpl @Inject constructor(
"goWellWithLiquor" to restaurantRegistrationRequest.goWellWithLiquor.toRequestBody(),
"recommendMenu" to restaurantRegistrationRequest.recommendMenu.toRequestBody(),
"restaurantLocationId" to restaurantRegistrationRequest.restaurantLocationAggregateId.toRequestBody(),
"groupId" to "10".toRequestBody()
"groupId" to groupId.toString().toRequestBody()
),
pictures = restaurantRegistrationRequest.pictures
)
Expand Down Expand Up @@ -258,6 +261,20 @@ class RestaurantDataSourceImpl @Inject constructor(
}.flow.cachedIn(coroutineScope)
}

override suspend fun getRegisteredRestaurantByMapWithLimitCount(
sortType: SortType,
currentGroup: Group?
): List<RegisteredRestaurantResponse> {
return restaurantAPI.getRestaurantLocationInfoByMap(
page = 1,
size = 3,
sort = sortType.key,
RestaurantSearchRequest(
groupId = currentGroup?.groupId
)
).data.restaurants
}

override suspend fun getRegisteredRestaurantsBySearchWithLimitCount(
keyword: String?,
userLocation: Location?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ data class RegisteredRestaurantResponse(
@SerializedName("userNickName")
val userNickName: String = "", // 식당 등록한 유저 닉네임
@SerializedName("userProfileImageUrl")
val userProfileImageUrl: String = "", // 식당 등록한 유저 프로필 이미지
val userProfileImageUrl: String? = "", // 식당 등록한 유저 프로필 이미지
@SerializedName("canDrinkLiquor")
val canDrinkLiquor: Boolean = false, // 식당 주류 판매 여부
@SerializedName("differenceInDistance")
val differenceInDistance: String = "", // 식당과의 거리
@SerializedName("groupId")
val groupId: Int = 0,
@SerializedName("groupName")
val groupName: String = "",
) {
fun convertResponseToRegisteredRestaurant(
userId: Int,
Expand All @@ -70,6 +74,8 @@ data class RegisteredRestaurantResponse(
userProfileImageUrl = userProfileImageUrl,
canDrinkLiquor = canDrinkLiquor,
differenceInDistance = differenceInDistance,
groupId = groupId,
groupName = groupName,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ class RestaurantRepositoryImpl @Inject constructor(
return restaurantDataSource.postRestaurantLocationInfo(restaurantLocationInfo)
}

override suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String {
return restaurantDataSource.postRestaurantInfo(restaurantRegistrationRequest)
override suspend fun postRestaurantInfo(
restaurantRegistrationRequest: RestaurantRegistrationRequest,
groupId: Int,
): String {
return restaurantDataSource.postRestaurantInfo(restaurantRegistrationRequest, groupId)
}

override suspend fun getRestaurants(
Expand Down Expand Up @@ -85,6 +88,8 @@ class RestaurantRepositoryImpl @Inject constructor(
userProfileImageUrl = restaurant.userProfileImageUrl,
canDrinkLiquor = restaurant.canDrinkLiquor,
differenceInDistance = restaurant.differenceInDistance,
groupId = restaurant.groupId,
groupName = restaurant.groupName,
)
restaurantTemp
}, result.totalElementsCount
Expand Down Expand Up @@ -134,6 +139,8 @@ class RestaurantRepositoryImpl @Inject constructor(
userProfileImageUrl = restaurant.userProfileImageUrl,
canDrinkLiquor = restaurant.canDrinkLiquor,
differenceInDistance = restaurant.differenceInDistance,
groupId = restaurant.groupId,
groupName = restaurant.groupName,
)
}
}
Expand Down Expand Up @@ -163,11 +170,42 @@ class RestaurantRepositoryImpl @Inject constructor(
userProfileImageUrl = restaurant.userProfileImageUrl,
canDrinkLiquor = restaurant.canDrinkLiquor,
differenceInDistance = restaurant.differenceInDistance,
groupId = restaurant.groupId,
groupName = restaurant.groupName,
)
}
}
}

override suspend fun getRegisteredRestaurantByMapWithLimitCount(
sortType: SortType,
currentGroup: Group?
): List<RegisteredRestaurant> {
return restaurantDataSource.getRegisteredRestaurantByMapWithLimitCount(sortType, currentGroup)
.map { restaurant ->
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 = restaurant.id,
userNickName = restaurant.userNickName,
userProfileImageUrl = restaurant.userProfileImageUrl,
canDrinkLiquor = restaurant.canDrinkLiquor,
differenceInDistance = restaurant.differenceInDistance,
groupId = restaurant.groupId,
groupName = restaurant.groupName,
)
}
}

override suspend fun getRestaurantReviews(restaurantId: Int): List<Review> {
return restaurantDataSource.getRestaurantReviews(restaurantId).reviewList

Expand Down Expand Up @@ -201,6 +239,8 @@ class RestaurantRepositoryImpl @Inject constructor(
userProfileImageUrl = restaurant.userProfileImageUrl,
canDrinkLiquor = restaurant.canDrinkLiquor,
differenceInDistance = restaurant.differenceInDistance,
groupId = restaurant.groupId,
groupName = restaurant.groupName,
)
}
}
Expand Down
3 changes: 2 additions & 1 deletion domain/src/main/java/org/gdsc/domain/model/GroupPreview.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package org.gdsc.domain.model

data class GroupPreview(
val groupId: Int,
val groupIntroduce: String,
val groupName: String,
val groupProfileImageUrl: String,
val groupIntroduce: String,
val memberCnt: Int,
val restaurantCnt: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ data class RegisteredRestaurant(
val category: String, // 식당 카테고리
val userId: Int, // 식당 등록한 유저 id
val userNickName: String, // 식당 등록한 유저 닉네임
val userProfileImageUrl: String, // 식당 등록한 유저 프로필 이미지
val userProfileImageUrl: String?, // 식당 등록한 유저 프로필 이미지
val canDrinkLiquor: Boolean, // 식당 주류 판매 여부
val differenceInDistance: String, // 식당과의 거리
val groupId: Int,
val groupName: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ data class RestaurantLocationInfo(
val x: String,
@SerializedName("y")
val y: String,
@SerializedName("differenceInDistance")
val differenceInDistance: String
): java.io.Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface RestaurantRepository {

suspend fun postRestaurantLocationInfo(restaurantLocationInfo: RestaurantLocationInfo): String

suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest): String
suspend fun postRestaurantInfo(restaurantRegistrationRequest: RestaurantRegistrationRequest, groupId: Int): String

suspend fun getRestaurants(
userId: Int, locationData: Location, sortType: SortType, foodCategory: FoodCategory, drinkPossibility: DrinkPossibility
Expand All @@ -50,6 +50,10 @@ interface RestaurantRepository {

suspend fun getRegisteredRestaurantsBySearch(keyword: String?, userLocation: Location?): Flow<PagingData<RegisteredRestaurant>>

suspend fun getRegisteredRestaurantByMapWithLimitCount(
sortType: SortType,currentGroup: Group?
): List<RegisteredRestaurant>

suspend fun getRestaurantReviews(restaurantId: Int): List<Review>

suspend fun getRegisteredRestaurantsBySearchWithLimitCount(keyword: String?, userLocation: Location?, limit: Int): List<RegisteredRestaurant>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.gdsc.domain.usecase

import org.gdsc.domain.SortType
import org.gdsc.domain.model.RegisteredRestaurant
import org.gdsc.domain.model.request.RestaurantSearchRequest
import org.gdsc.domain.model.response.Group
import org.gdsc.domain.repository.RestaurantRepository
import javax.inject.Inject

class GetRestaurantMapWithLimitCountUseCase @Inject constructor(
private val restaurantRepository: RestaurantRepository
) {
suspend operator fun invoke(
sortType: SortType,
group: Group?,
): List<RegisteredRestaurant> {
return restaurantRepository.getRegisteredRestaurantByMapWithLimitCount(sortType, group)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class PostRestaurantInfoUseCase @Inject constructor(
canDrinkLiquor: Boolean,
goWellWithLiquor: String,
recommendMenu: String,
restaurantLocationAggregateIdg: String
restaurantLocationAggregateIdg: String,
groupId: Int,
): String {
return restaurantRepository.postRestaurantInfo(
RestaurantRegistrationRequest(
Expand All @@ -30,6 +31,7 @@ class PostRestaurantInfoUseCase @Inject constructor(
recommendMenu,
restaurantLocationAggregateIdg
),
groupId,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ class MainActivity : BaseActivity() {
binding.toolBar.isVisible = isVisible
}

fun navigateToEditRestaurantInfo(restaurantId: Int) {

val action = HomeFragmentDirections.actionHomeFragmentToRegisterRestaurantFragment(
targetRestaurantId = restaurantId
)
navController.navigate(action)
}
// fun navigateToEditRestaurantInfo(restaurantId: Int) {
//
// val action = HomeFragmentDirections.actionHomeFragmentToRegisterRestaurantFragment(
// targetRestaurantId = restaurantId
// )
// navController.navigate(action)
// }

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
Expand Down
Loading

0 comments on commit b818d45

Please sign in to comment.