Skip to content

Commit

Permalink
#91 관심 약 처리 DataSource 로직추가
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Jun 7, 2023
1 parent cf0bda5 commit e35e458
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 34 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.android.mediproject.core.model.favorites
package com.android.mediproject.core.model.medicine.InterestedMedicine


import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class AddFavoriteMedicineResponse(
data class AddInterestedMedicineResponse(
@SerialName("favoriteMedicineID") val favoriteMedicineID: Int, // 86
@SerialName("message") val message: String
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.android.mediproject.core.model.favorites
package com.android.mediproject.core.model.medicine.InterestedMedicine


import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class DeleteFavoriteMedicineResponse(
data class DeleteInterestedMedicineResponse(
@SerialName("message") val message: String
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.android.mediproject.core.model.favorites

package com.android.mediproject.core.model.medicine.InterestedMedicine

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class IsFavoriteMedicineResponse(
data class IsInterestedMedicineResponse(
@SerialName("isFavorite") val isFavorite: Boolean, // false
@SerialName("message") val message: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.android.mediproject.core.model.requestparameters

import kotlinx.serialization.Serializable

@Serializable
data class AddInterestedMedicineParameter(
val medicineId: Long
)
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
package com.android.mediproject.core.network.datasource.interestedmedicine


import com.android.mediproject.core.model.medicine.InterestedMedicine.AddInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.DeleteInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.IsInterestedMedicineResponse
import com.android.mediproject.core.model.requestparameters.AddInterestedMedicineParameter
import kotlinx.coroutines.flow.Flow

interface InterestedMedicineDataSource {
suspend fun getInterestedMedicineList() : Flow<Result<InterestedMedicineListResponse>>
suspend fun getInterestedMedicineList(): Flow<Result<InterestedMedicineListResponse>>

/**
* 관심 약 추가
*/
fun addInterestedMedicine(addInterestedMedicineParameter: AddInterestedMedicineParameter): Flow<Result<AddInterestedMedicineResponse>>

/**
* 관심 약 삭제
*/
fun deleteInterestedMedicine(medicineId: Long): Flow<Result<DeleteInterestedMedicineResponse>>

/**
* 관심 약 여부 확인
*/
fun isInterestedMedicine(medicineId: Long): Flow<Result<IsInterestedMedicineResponse>>
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
package com.android.mediproject.core.network.datasource.interestedmedicine

import com.android.mediproject.core.model.medicine.InterestedMedicine.AddInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.DeleteInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.IsInterestedMedicineResponse
import com.android.mediproject.core.model.requestparameters.AddInterestedMedicineParameter
import com.android.mediproject.core.network.module.AwsNetworkApi
import com.android.mediproject.core.network.onResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import javax.inject.Inject

class InterestedMedicineDataSourceImpl @Inject constructor(private val awsNetworkApi: AwsNetworkApi) :
InterestedMedicineDataSource {
override suspend fun getInterestedMedicineList(): Flow<Result<InterestedMedicineListResponse>> =
class InterestedMedicineDataSourceImpl @Inject constructor(private val awsNetworkApi: AwsNetworkApi) : InterestedMedicineDataSource {
override suspend fun getInterestedMedicineList(): Flow<Result<InterestedMedicineListResponse>> = channelFlow {
awsNetworkApi.getInterestedMedicineList().onResponse().fold(onSuccess = { Result.success(it) }, onFailure = { Result.failure(it) })
.also {
trySend(it)
}
}

override fun addInterestedMedicine(addInterestedMedicineParameter: AddInterestedMedicineParameter): Flow<Result<AddInterestedMedicineResponse>> =
channelFlow {
awsNetworkApi.getInterestedMedicineList().onResponse()
awsNetworkApi.addInterestedMedicine(addInterestedMedicineParameter).onResponse()
.fold(onSuccess = { Result.success(it) }, onFailure = { Result.failure(it) }).also {
trySend(it)
}
}

override fun deleteInterestedMedicine(medicineId: Long): Flow<Result<DeleteInterestedMedicineResponse>> = channelFlow {
awsNetworkApi.deleteInterestedMedicine(medicineId).onResponse()
.fold(onSuccess = { Result.success(it) }, onFailure = { Result.failure(it) }).also {
trySend(it)
}
}

override fun isInterestedMedicine(medicineId: Long): Flow<Result<IsInterestedMedicineResponse>> = channelFlow {
awsNetworkApi.isInterestedMedicine(medicineId).onResponse()
.fold(onSuccess = { Result.success(it) }, onFailure = { Result.failure(it) }).also {
trySend(it)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ import com.android.mediproject.core.datastore.TokenDataSourceImpl
import com.android.mediproject.core.model.comments.CommentChangedResponse
import com.android.mediproject.core.model.comments.CommentListResponse
import com.android.mediproject.core.model.comments.LikeResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.AddInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.DeleteInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.InterestedMedicineListResponse
import com.android.mediproject.core.model.medicine.InterestedMedicine.IsInterestedMedicineResponse
import com.android.mediproject.core.model.medicine.MedicineIdResponse
import com.android.mediproject.core.model.remote.sign.SignInResponse
import com.android.mediproject.core.model.remote.sign.SignUpResponse
import com.android.mediproject.core.model.remote.token.ReissueTokenResponse
import com.android.mediproject.core.model.requestparameters.AddInterestedMedicineParameter
import com.android.mediproject.core.model.requestparameters.ChangeNicknameParameter
import com.android.mediproject.core.model.requestparameters.ChangePasswordRequestParameter
import com.android.mediproject.core.model.requestparameters.DeleteCommentParameter
Expand Down Expand Up @@ -52,6 +56,7 @@ import retrofit2.http.HTTP
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query
import javax.inject.Named
import javax.inject.Singleton

Expand Down Expand Up @@ -224,4 +229,28 @@ interface AwsNetworkApi {
*/
@GET(value = "user")
suspend fun getUserInfo(): Response<UserResponse>

/**
* 관심 약 조회
*/
@GET(value = "medicine/favorite")
suspend fun isInterestedMedicine(
@Query("ITEM_SEQ") itemSeq: Long
): Response<IsInterestedMedicineResponse>

/**
* 관심 약 추가
*/
@POST(value = "medicine/favorite")
suspend fun addInterestedMedicine(
@Body addInterestedMedicineParameter: AddInterestedMedicineParameter
): Response<AddInterestedMedicineResponse>

/**
* 관심 약 삭제
*/
@DELETE(value = "medicine/favorite")
suspend fun deleteInterestedMedicine(
@Query("medicineId") medicineId: Long
): Response<DeleteInterestedMedicineResponse>
}

0 comments on commit e35e458

Please sign in to comment.