Skip to content

Commit

Permalink
Merge branch 'feat/group_select' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-swit committed Mar 14, 2024
2 parents d0dafd3 + e75469c commit ef650cf
Show file tree
Hide file tree
Showing 30 changed files with 729 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.gdsc.data.model.RegisteredRestaurantResponse
import org.gdsc.data.network.RestaurantAPI
import org.gdsc.domain.SortType
import org.gdsc.domain.model.request.RestaurantSearchRequest
import org.gdsc.domain.model.response.Group

class RestaurantByMapPagingSource(
private val api: RestaurantAPI,
Expand Down
10 changes: 10 additions & 0 deletions data/src/main/java/org/gdsc/data/datasource/GroupDataSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.gdsc.data.datasource

import org.gdsc.domain.model.response.Group


interface GroupDataSource {
suspend fun getMyGroups(): List<Group>

suspend fun selectGroup(groupId: Int): String
}
32 changes: 32 additions & 0 deletions data/src/main/java/org/gdsc/data/datasource/GroupDataSourceImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.gdsc.data.datasource

import android.util.Log
import org.gdsc.data.network.GroupAPI
import org.gdsc.domain.model.response.Group
import javax.inject.Inject

class GroupDataSourceImpl @Inject constructor(
private val groupAPI: GroupAPI,
): GroupDataSource {
override suspend fun getMyGroups(): List<Group> {
runCatching {
groupAPI.getMyGroups()
}.onSuccess {
return it.data
}.onFailure {
return emptyList()
}
return emptyList()
}

override suspend fun selectGroup(groupId: Int): String {
runCatching {
groupAPI.selectGroup(groupId)
}.onSuccess {
return it.data
}.onFailure {
return ""
}
return ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.gdsc.domain.model.RestaurantLocationInfo
import org.gdsc.domain.model.UserLocation
import org.gdsc.domain.model.request.ModifyRestaurantInfoRequest
import org.gdsc.domain.model.request.RestaurantRegistrationRequest
import org.gdsc.domain.model.response.Group
import org.gdsc.domain.model.response.RestaurantInfoResponse

interface RestaurantDataSource {
Expand All @@ -39,7 +40,13 @@ interface RestaurantDataSource {
suspend fun putRestaurantInfo(putRestaurantInfoRequest: ModifyRestaurantInfoRequest): String

suspend fun getRestaurantsByMap(
userLocation: Location?, startLocation: Location?, endLocation: Location?, sortType: SortType, foodCategory: FoodCategory?, drinkPossibility: DrinkPossibility?
userLocation: Location?,
startLocation: Location?,
endLocation: Location?,
sortType: SortType,
foodCategory: FoodCategory?,
drinkPossibility: DrinkPossibility?,
currentGroup: Group?,
): Flow<PagingData<RegisteredRestaurantResponse>>

suspend fun getRegisteredRestaurantsBySearch(keyword: String?, userLocation: Location?): Flow<PagingData<RegisteredRestaurantResponse>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.gdsc.domain.model.UserLocation
import org.gdsc.domain.model.request.ModifyRestaurantInfoRequest
import org.gdsc.domain.model.request.RestaurantRegistrationRequest
import org.gdsc.domain.model.request.RestaurantSearchRequest
import org.gdsc.domain.model.response.Group
import org.gdsc.domain.model.response.RestaurantInfoResponse
import retrofit2.HttpException
import javax.inject.Inject
Expand Down Expand Up @@ -203,12 +204,14 @@ class RestaurantDataSourceImpl @Inject constructor(
endLocation: Location?,
sortType: SortType,
foodCategory: FoodCategory?,
drinkPossibility: DrinkPossibility?
drinkPossibility: DrinkPossibility?,
currentGroup: Group?,
): Flow<PagingData<RegisteredRestaurantResponse>> {
val restaurantSearchRequest = RestaurantSearchRequest(
userLocation = userLocation,
startLocation = startLocation,
endLocation = endLocation,
groupId = currentGroup?.groupId,
filter = Filter(
categoryFilter = when (foodCategory) {
FoodCategory.INIT, FoodCategory.ETC -> String.Empty
Expand Down
7 changes: 7 additions & 0 deletions data/src/main/java/org/gdsc/data/di/ApiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.gdsc.data.network.GroupAPI
import org.gdsc.data.network.LoginAPI
import org.gdsc.data.network.RestaurantAPI
import org.gdsc.data.network.TokenAPI
Expand Down Expand Up @@ -39,4 +40,10 @@ class ApiModule {
return retrofit.create(TokenAPI::class.java)
}

@Provides
@Singleton
fun provideGroupApi(@AuthClient retrofit: Retrofit): GroupAPI {
return retrofit.create(GroupAPI::class.java)
}

}
25 changes: 25 additions & 0 deletions data/src/main/java/org/gdsc/data/di/GroupModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.gdsc.data.di

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.gdsc.data.datasource.GroupDataSource
import org.gdsc.data.datasource.GroupDataSourceImpl
import org.gdsc.data.repository.GroupRepositoryImpl
import org.gdsc.domain.repository.GroupRepository
import javax.inject.Singleton


@Module
@InstallIn(SingletonComponent::class)
abstract class GroupModule {

@Singleton
@Binds
abstract fun bindGroupDataSource(groupDataSourceImpl: GroupDataSourceImpl): GroupDataSource

@Singleton
@Binds
abstract fun bindGroupRepository(groupRepositoryImpl: GroupRepositoryImpl): GroupRepository
}
14 changes: 14 additions & 0 deletions data/src/main/java/org/gdsc/data/model/Group.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.gdsc.data.model

import com.google.gson.annotations.SerializedName

data class Group(
@SerializedName("groupId") val groupId: Int,
@SerializedName("groupIntroduce") val groupIntroduce: String,
@SerializedName("groupProfileImageUrl") val groupProfileImageUrl: String,
@SerializedName("groupBackgroundImageUrl") val groupBackgroundImageUrl: String,
@SerializedName("memberCnt") val memberCnt: Int,
@SerializedName("restaurantCnt") val restaurantCnt: Int,
@SerializedName("privateGroup") val privateGroup: Boolean,
@SerializedName("isSelected") val isSelected: Boolean,
)
19 changes: 19 additions & 0 deletions data/src/main/java/org/gdsc/data/network/GroupAPI.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.gdsc.data.network

import org.gdsc.data.model.Response
import org.gdsc.domain.model.response.Group
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Path

interface GroupAPI {

@GET("api/v1/group/my")
suspend fun getMyGroups(): Response<List<Group>>

@POST("api/v1/group/{groupId}/select")
suspend fun selectGroup(
@Path("groupId") groupId: Int
): Response<String>

}
18 changes: 18 additions & 0 deletions data/src/main/java/org/gdsc/data/repository/GroupRepositoryImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.gdsc.data.repository

import org.gdsc.data.datasource.GroupDataSource
import org.gdsc.domain.model.response.Group
import org.gdsc.domain.repository.GroupRepository
import javax.inject.Inject

class GroupRepositoryImpl @Inject constructor(
private val groupDataSource: GroupDataSource
): GroupRepository {
override suspend fun getMyGroups(): List<Group> {
return groupDataSource.getMyGroups()
}

override suspend fun selectGroup(groupId: Int): String {
return groupDataSource.selectGroup(groupId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.gdsc.domain.model.Review
import org.gdsc.domain.model.UserLocation
import org.gdsc.domain.model.request.ModifyRestaurantInfoRequest
import org.gdsc.domain.model.request.RestaurantRegistrationRequest
import org.gdsc.domain.model.response.Group
import org.gdsc.domain.model.response.RestaurantInfoResponse
import org.gdsc.domain.repository.RestaurantRepository
import javax.inject.Inject
Expand Down Expand Up @@ -103,15 +104,17 @@ class RestaurantRepositoryImpl @Inject constructor(
endLocation: Location?,
sortType: SortType,
foodCategory: FoodCategory?,
drinkPossibility: DrinkPossibility?
drinkPossibility: DrinkPossibility?,
currentGroup: Group?,
): Flow<PagingData<RegisteredRestaurant>> {
return restaurantDataSource.getRestaurantsByMap(
userLocation,
startLocation,
endLocation,
sortType,
foodCategory,
drinkPossibility
drinkPossibility,
currentGroup,
).map { result ->
result.map { restaurant ->
RegisteredRestaurant(
Expand Down
6 changes: 6 additions & 0 deletions domain/src/main/java/org/gdsc/domain/model/ScreenLocation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.gdsc.domain.model

data class ScreenLocation(
val startLocation: Location,
val endLocation: Location,
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ data class RestaurantSearchRequest(
val startLocation: Location? = null,
@SerializedName("endLocation")
val endLocation: Location? = null,
@SerializedName("groupId")
val groupId: Int? = null,
@SerializedName("keyword")
val keyword: String? = null,
)
13 changes: 13 additions & 0 deletions domain/src/main/java/org/gdsc/domain/model/response/Group.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.gdsc.domain.model.response

data class Group(
val groupId: Int,
val groupName: String,
val groupIntroduce: String,
val groupProfileImageUrl: String,
val groupBackgroundImageUrl: String,
val memberCnt: Int,
val restaurantCnt: Int,
val privateGroup: Boolean,
val isSelected: Boolean,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.gdsc.domain.repository

import org.gdsc.domain.model.response.Group

interface GroupRepository {
suspend fun getMyGroups(): List<Group>

suspend fun selectGroup(groupId: Int): String
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.gdsc.domain.model.Review
import org.gdsc.domain.model.UserLocation
import org.gdsc.domain.model.request.ModifyRestaurantInfoRequest
import org.gdsc.domain.model.request.RestaurantRegistrationRequest
import org.gdsc.domain.model.response.Group
import org.gdsc.domain.model.response.RestaurantInfoResponse

interface RestaurantRepository {
Expand All @@ -38,7 +39,13 @@ interface RestaurantRepository {
suspend fun putRestaurantInfo(putRestaurantInfoRequest: ModifyRestaurantInfoRequest): String

suspend fun getRestaurantsByMap(
userLocation: Location?, startLocation: Location?, endLocation: Location?, sortType: SortType, foodCategory: FoodCategory?, drinkPossibility: DrinkPossibility?
userLocation: Location?,
startLocation: Location?,
endLocation: Location?,
sortType: SortType,
foodCategory: FoodCategory?,
drinkPossibility: DrinkPossibility?,
currentGroup: Group?,
): Flow<PagingData<RegisteredRestaurant>>

suspend fun getRegisteredRestaurantsBySearch(keyword: String?, userLocation: Location?): Flow<PagingData<RegisteredRestaurant>>
Expand Down
10 changes: 10 additions & 0 deletions domain/src/main/java/org/gdsc/domain/usecase/GetMyGroupUseCase.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.gdsc.domain.usecase

import org.gdsc.domain.repository.GroupRepository
import javax.inject.Inject

class GetMyGroupUseCase @Inject constructor(
private val groupRepository: GroupRepository
){
suspend operator fun invoke() = groupRepository.getMyGroups()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,31 @@ import org.gdsc.domain.FoodCategory
import org.gdsc.domain.SortType
import org.gdsc.domain.model.Location
import org.gdsc.domain.model.RegisteredRestaurant
import org.gdsc.domain.model.response.Group
import org.gdsc.domain.repository.RestaurantRepository
import javax.inject.Inject

class GetRestaurantsByMapUseCase @Inject constructor(
private val restaurantRepository: RestaurantRepository
) {
suspend operator fun invoke(
sortType: SortType, foodCategory: FoodCategory?, drinkPossibility: DrinkPossibility?, userLocation: Location?, startLocation: Location? = null, endLocation: Location? = null
sortType: SortType,
foodCategory: FoodCategory?,
drinkPossibility: DrinkPossibility?,
userLocation: Location?,
startLocation: Location? = null,
endLocation: Location? = null,
currentGroup: Group? = null,
): Flow<PagingData<RegisteredRestaurant>> {

return restaurantRepository.getRestaurantsByMap( userLocation, startLocation, endLocation, sortType, foodCategory, drinkPossibility)
return restaurantRepository.getRestaurantsByMap(
userLocation,
startLocation,
endLocation,
sortType,
foodCategory,
drinkPossibility,
currentGroup,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.gdsc.domain.usecase

import org.gdsc.domain.repository.GroupRepository
import javax.inject.Inject

class PostSelectGroupUseCase @Inject constructor(
private val groupRepository: GroupRepository
) {
suspend operator fun invoke(groupId: Int): String {
return groupRepository.selectGroup(groupId)
}
}
Loading

0 comments on commit ef650cf

Please sign in to comment.