Skip to content

Commit

Permalink
Merge pull request #101 from Begin-Vegan/feature/BVVER24-145-mypage-mโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆy-recipe-api

Mypage ๋‚˜์˜ ๋ ˆ์‹œํ”ผ API ์—ฐ๊ฒฐ
  • Loading branch information
syjeuion authored Jul 13, 2024
2 parents 5da8605 + 414755b commit 5aa08d9
Show file tree
Hide file tree
Showing 33 changed files with 418 additions and 30 deletions.
Binary file modified .gradle/8.4/executionHistory/executionHistory.bin
Binary file not shown.
Binary file modified .gradle/8.4/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/8.4/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
Binary file modified buildSrc/.gradle/8.4/executionHistory/executionHistory.lock
Binary file not shown.
13 changes: 11 additions & 2 deletions data/src/main/java/com/example/data/di/MypageMyScrapModule.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.data.di

import com.example.data.mapper.mypage.MypageMyMagazineMapper
import com.example.data.mapper.mypage.MypageMyRecipeMapper
import com.example.data.repository.local.auth.AuthTokenDataSource
import com.example.data.repository.remote.mypage.MypageMyScrapRemoteDataSource
import com.example.data.repository.remote.mypage.MypageMyScrapRemoteDataSourceImpl
Expand Down Expand Up @@ -36,11 +37,13 @@ class MypageMyScrapModule {
@Singleton
fun provideMyScrapRepository(
myScrapRemoteDataSource: MypageMyScrapRemoteDataSource,
mypageMyMagazineMapper: MypageMyMagazineMapper
mypageMyMagazineMapper: MypageMyMagazineMapper,
mypageMyRecipeMapper: MypageMyRecipeMapper
): MypageMyScrapRepository {
return MypageMyScrapRepositoryImpl(
myScrapRemoteDataSource,
mypageMyMagazineMapper
mypageMyMagazineMapper,
mypageMyRecipeMapper
)
}

Expand All @@ -49,4 +52,10 @@ class MypageMyScrapModule {
fun provideMypageMyMagazineMapper(): MypageMyMagazineMapper {
return MypageMyMagazineMapper()
}

@Provides
@Singleton
fun provideMypageMyRecipeMapper(): MypageMyRecipeMapper {
return MypageMyRecipeMapper()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.data.mapper.mypage

import com.example.data.model.mypage.MyRecipeItemDto
import com.example.domain.mapper.Mapper
import com.example.domain.model.mypage.MypageMyRecipeItem

class MypageMyRecipeMapper:Mapper<List<MyRecipeItemDto>, List<MypageMyRecipeItem>> {
override fun mapFromEntity(type: List<MyRecipeItemDto>): List<MypageMyRecipeItem> {
return type.map { MypageMyRecipeItem(
foodId = it.foodId,
name = it.name,
veganType = it.veganType
) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.data.model.mypage

import com.squareup.moshi.Json

data class MyRecipeResponse (
@Json(name = "check")
val check: Boolean,
@Json(name = "information")
val information: List<MyRecipeItemDto>
)
data class MyRecipeItemDto(
@Json(name = "foodId") val foodId:Int,
@Json(name = "name") val name:String,
@Json(name = "veganType") val veganType:String
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.example.data.repository.remote.mypage

import com.example.data.model.mypage.MyMagazineResponse
import com.example.data.model.mypage.MyRecipeResponse
import com.skydoves.sandwich.ApiResponse

interface MypageMyScrapRemoteDataSource {
suspend fun getMyMagazineList(page: Int): ApiResponse<MyMagazineResponse>
suspend fun getMyRecipeList(page: Int): ApiResponse<MyRecipeResponse>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.data.repository.remote.mypage

import com.example.data.model.mypage.MyMagazineResponse
import com.example.data.model.mypage.MyRecipeResponse
import com.example.data.repository.local.auth.AuthTokenDataSource
import com.example.data.retrofit.MypageMyScrapService
import com.skydoves.sandwich.ApiResponse
Expand All @@ -26,4 +27,16 @@ class MypageMyScrapRemoteDataSourceImpl @Inject constructor(
ApiResponse.Failure.Error(this.errorBody)
}
}

override suspend fun getMyRecipeList(page: Int): ApiResponse<MyRecipeResponse> {
val accessToken = authTokenDataSource.accessToken.first()
val authHeader = "Bearer $accessToken"
return mypageMyScrapService.getMyRecipeList(authHeader, page).suspendOnSuccess {
Timber.d("getMyRecipeList successful")
ApiResponse.Success(this.data)
}.suspendOnError {
Timber.e("getMyRecipeList error: ${this.errorBody}")
ApiResponse.Failure.Error(this.errorBody)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.data.repository.remote.mypage

import com.example.data.mapper.mypage.MypageMyMagazineMapper
import com.example.data.mapper.mypage.MypageMyRecipeMapper
import com.example.domain.model.mypage.MypageMyMagazineItem
import com.example.domain.model.mypage.MypageMyRecipeItem
import com.example.domain.repository.mypage.MypageMyScrapRepository
import com.skydoves.sandwich.ApiResponse
import com.skydoves.sandwich.retrofit.errorBody
Expand All @@ -12,7 +14,8 @@ import javax.inject.Inject

class MypageMyScrapRepositoryImpl @Inject constructor(
private val mypageMyScrapRemoteDataSource: MypageMyScrapRemoteDataSource,
private val mypageMyMagazineMapper: MypageMyMagazineMapper
private val mypageMyMagazineMapper: MypageMyMagazineMapper,
private val mypageMyRecipeMapper: MypageMyRecipeMapper
): MypageMyScrapRepository {
override suspend fun getMyMagazineList(page: Int): Flow<Result<List<MypageMyMagazineItem>>> {
return flow{
Expand Down Expand Up @@ -40,4 +43,31 @@ class MypageMyScrapRepositoryImpl @Inject constructor(
}
}
}

override suspend fun getMyRecipeList(page: Int): Flow<Result<List<MypageMyRecipeItem>>> {
return flow{
try {
val response = mypageMyScrapRemoteDataSource.getMyRecipeList(page)
when (response) {
is ApiResponse.Success -> {
val magazineList = mypageMyRecipeMapper.mapFromEntity(response.data.information)
emit(Result.success(magazineList))
}

is ApiResponse.Failure.Error -> {
Timber.e("getMyRecipeList error: ${response.errorBody}")
emit(Result.failure(Exception("getMyRecipeList failed")))
}

is ApiResponse.Failure.Exception -> {
Timber.e("getMyRecipeList exception: ${response.message}")
emit(Result.failure(response.throwable))
}
}
} catch (e: Exception) {
Timber.e(e, "getMyRecipeList exception")
emit(Result.failure(e))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.data.retrofit

import com.example.data.model.mypage.MyMagazineResponse
import com.example.data.model.mypage.MyRecipeResponse
import com.example.data.model.tips.MagazineResponse
import com.skydoves.sandwich.ApiResponse
import retrofit2.http.GET
Expand All @@ -13,4 +14,10 @@ interface MypageMyScrapService {
@Header("Authorization") token: String,
@Query("page") page: Int
): ApiResponse<MyMagazineResponse>

@GET("/api/v1/bookmarks/recipe")
suspend fun getMyRecipeList(
@Header("Authorization") token: String,
@Query("page") page: Int
): ApiResponse<MyRecipeResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ data class MypageMyMagazineItem(
val editor: String,
val writeTime: String
)

data class MypageMyRecipeItem(
val foodId:Int,
val name:String,
val veganType:String
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.example.domain.repository.mypage

import com.example.domain.model.mypage.MypageMyMagazineItem
import com.example.domain.model.mypage.MypageMyRecipeItem
import com.example.domain.model.tips.TipsMagazineItem
import kotlinx.coroutines.flow.Flow

interface MypageMyScrapRepository {
suspend fun getMyMagazineList(page: Int): Flow<Result<List<MypageMyMagazineItem>>>
suspend fun getMyRecipeList(page: Int): Flow<Result<List<MypageMyRecipeItem>>>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.domain.useCase.mypage

import com.example.domain.model.mypage.MypageMyMagazineItem
import com.example.domain.model.mypage.MypageMyRecipeItem
import com.example.domain.repository.mypage.MypageMyScrapRepository
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject
Expand All @@ -10,4 +11,7 @@ class MypageMyScrapUseCase @Inject constructor(
){
suspend fun getMyMagazineList(page: Int): Flow<Result<List<MypageMyMagazineItem>>> =
mypageMyScrapRepository.getMyMagazineList(page)

suspend fun getMyRecipeList(page:Int): Flow<Result<List<MypageMyRecipeItem>>> =
mypageMyScrapRepository.getMyRecipeList(page)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.navigation.NavController
interface HomeNavigationHandler {
fun navigateToHome()
fun navigateToMap()
fun navigateToTips(fromTest: Boolean)
fun navigateToTips(fromTest: Boolean,fromMyRecipe:Boolean)
fun navigateToMypage()

fun navigationToMypageNotBackStack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class HomeNavigationImpl(private val navController: NavController) : HomeNavigat
controlBackStack(R.id.veganMapFragment)
}

override fun navigateToTips(fromTest: Boolean) {
if(fromTest){
val action = HomeFragmentDirections.actionMainHomeFragmentToTipsFragment(fromTest)
override fun navigateToTips(fromTest: Boolean, fromMyRecipe:Boolean) {
if(fromTest||fromMyRecipe){
val action = HomeFragmentDirections.actionMainHomeFragmentToTipsFragment(fromTest=fromTest, fromMyRecipe = fromMyRecipe)
navController.navigate(action)
}else{
controlBackStack(R.id.tipsFragment)
Expand All @@ -38,8 +38,6 @@ class HomeNavigationImpl(private val navController: NavController) : HomeNavigat
override fun navigationToTipsNotBackStack() {
navController.navigate(R.id.tipsFragment, null,
NavOptions.Builder().setPopUpTo(navController.currentDestination?.id!!, true).build())
// val action = HomeFragmentDirections.actionMainHomeFragmentToTipsFragment(false)
// navController.navigate(action)
}

private fun controlBackStack(destinationId:Int){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface MainNavigationHandler {
fun navigateToTipsMagazineDetail()
fun navigateMyMagazineToMagazineDetail()
fun navigateMyMagazineToMainHome(fromMagazine:Boolean = false)
fun navigateMyRecipeToMainHome(fromMyRecipe:Boolean = false)

fun navigateToMainHome(fromTest:Boolean = false)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.example.presentation.R
import com.example.presentation.view.home.veganTest.view.VeganTestResultFragmentDirections
import com.example.presentation.view.mypage.view.MypageMyMagazineFragment
import com.example.presentation.view.mypage.view.MypageMyMagazineFragmentDirections
import com.example.presentation.view.mypage.view.MypageMyRecipeFragmentDirections
import timber.log.Timber
import javax.inject.Inject

Expand Down Expand Up @@ -58,6 +59,11 @@ class MainNavigationImpl @Inject constructor(private val navController: NavContr
navController.navigate(action)
}

override fun navigateMyRecipeToMainHome(fromMyRecipe: Boolean) {
val action = MypageMyRecipeFragmentDirections.actionMypageMyRecipeFragmentToMainFragment(fromMyRecipe = fromMyRecipe)
navController.navigate(action)
}

override fun navigateToMainHome(fromTest: Boolean) {
val action = VeganTestResultFragmentDirections.actionVeganTestResultFragmentToMainFragment(fromTest = fromTest)
navController.navigate(action)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MainFragment : BaseFragment<FragmentMainBinding>(R.layout.fragment_main) {
when (menuItem.itemId) {
R.id.item_home -> homeNavigationHandler.navigateToHome()
R.id.item_map -> homeNavigationHandler.navigateToMap()
R.id.item_tips -> homeNavigationHandler.navigateToTips(false)
R.id.item_tips -> homeNavigationHandler.navigateToTips(false,false)
R.id.item_profile -> homeNavigationHandler.navigateToMypage()
}
true
Expand All @@ -57,21 +57,26 @@ class MainFragment : BaseFragment<FragmentMainBinding>(R.layout.fragment_main) {

private fun checkFromOthers(){
val args: MainFragmentArgs by navArgs()
Timber.d("args.fromTest:${args.fromTest}, args.fromMyMagazine:${args.fromMyMagazine}, args.fromMyRecipe:${args.fromMyRecipe}")
if(args.fromTest) {
homeNavigationHandler.navigateToTips(true)
homeNavigationHandler.navigateToTips(true,false)
val nArg = this.arguments ?:Bundle()
nArg.putBoolean("fromTest", false)
this.arguments = nArg

}else if(args.fromMyMagazine){
homeNavigationHandler.navigateToTips(false)
homeNavigationHandler.navigateToTips(false,false)
val nArg = this.arguments ?:Bundle()
nArg.putBoolean("fromMyMagazine", false)
this.arguments = nArg
} else{
}else if(args.fromMyRecipe){
homeNavigationHandler.navigateToTips(false,true)
val nArg = this.arguments ?:Bundle()
nArg.putBoolean("fromMyRecipe", false)
this.arguments = nArg

}else{
if(navController.currentDestination?.id==R.id.mainMypageFragment)
homeNavigationHandler.navigationToMypageNotBackStack()

if(navController.currentDestination?.id==R.id.tipsFragment)
homeNavigationHandler.navigationToTipsNotBackStack()
}
Expand Down
Loading

0 comments on commit 5aa08d9

Please sign in to comment.