Skip to content

Commit

Permalink
#219 TokenRepository.kt 삭제하고 연관된 코드 삭제 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
pknujsp committed Mar 10, 2024
1 parent b3870e1 commit 783b1cb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ interface CommentsRepository {
/**
* 내가 작성한 댓글을 가져오는 메서드입니다.
*/
fun getMyCommentsList(): Flow<Result<MyCommentsListResponse>>
fun getMyCommentsList(): Result<MyCommentsListResponse>

/**
* 댓글을 수정합니다.
*/
fun editComment(parameter: EditCommentParameter): Flow<Result<CommentChangedResponse>>
fun editComment(parameter: EditCommentParameter): Result<CommentChangedResponse>

/**
* 댓글을 등록합니다.
*/
fun applyNewComment(parameter: NewCommentParameter): Flow<Result<CommentChangedResponse>>
fun applyNewComment(parameter: NewCommentParameter): Result<CommentChangedResponse>

/**
* 댓글 삭제 클릭
*/
fun deleteComment(parameter: DeleteCommentParameter): Flow<Result<CommentChangedResponse>>
fun deleteComment(parameter: DeleteCommentParameter): Result<CommentChangedResponse>

/**
* 댓글 좋아요 클릭
*/
fun likeComment(parameter: LikeCommentParameter): Flow<Result<LikeResponse>>
fun likeComment(parameter: LikeCommentParameter): Result<LikeResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,46 @@ import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.android.mediproject.core.common.SERVER_PAGE_SIZE
import com.android.mediproject.core.data.token.TokenRepository
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.comments.MyCommentsListResponse
import com.android.mediproject.core.model.token.TokenState
import com.android.mediproject.core.model.requestparameters.DeleteCommentParameter
import com.android.mediproject.core.model.requestparameters.EditCommentParameter
import com.android.mediproject.core.model.requestparameters.LikeCommentParameter
import com.android.mediproject.core.model.requestparameters.NewCommentParameter
import com.android.mediproject.core.network.datasource.comments.CommentsDataSource
import com.android.mediproject.core.network.datasource.comments.CommentsListDataSourceImpl
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.last
import javax.inject.Inject

class CommentsRepositoryImpl @Inject constructor(
private val commentsDataSource: CommentsDataSource, private val tokenRepository: TokenRepository,
private val commentsDataSource: CommentsDataSource,
) : CommentsRepository {
override fun getCommentsByMedicineId(medicineId: Long): Flow<PagingData<CommentListResponse.Comment>> =
Pager(
config = PagingConfig(pageSize = SERVER_PAGE_SIZE, prefetchDistance = 0),
pagingSourceFactory = {
CommentsListDataSourceImpl(commentsDataSource, medicineId)
},
).flow

override fun getMyCommentsList(): Flow<Result<MyCommentsListResponse>> = channelFlow {
checkToken().collectLatest { tokenState ->
tokenState.onSuccess {
commentsDataSource.getMyCommentsList().collectLatest {
trySend(it)
}
}.onFailure {
trySend(Result.failure(it))
}
}
override fun getCommentsByMedicineId(medicineId: Long): Flow<PagingData<CommentListResponse.Comment>> = Pager(
config = PagingConfig(pageSize = SERVER_PAGE_SIZE, prefetchDistance = 0),
pagingSourceFactory = {
CommentsListDataSourceImpl(commentsDataSource, medicineId)
},
).flow

override fun getMyCommentsList(): Result<MyCommentsListResponse> {
TODO("Not yet implemented")
}

override fun editComment(parameter: EditCommentParameter): Flow<Result<CommentChangedResponse>> = channelFlow {
checkToken().collectLatest { tokenState ->
tokenState.onSuccess {
commentsDataSource.editComment(parameter).collectLatest {
trySend(it)
}
}.onFailure {
trySend(Result.failure(it))
}
}
override fun applyNewComment(parameter: NewCommentParameter): Result<CommentChangedResponse> {
TODO("Not yet implemented")
}


override fun applyNewComment(parameter: NewCommentParameter): Flow<Result<CommentChangedResponse>> = channelFlow {
checkToken().collectLatest { tokenState ->
tokenState.onSuccess {
commentsDataSource.applyNewComment(parameter).collectLatest {
trySend(it)
}
}.onFailure {
trySend(Result.failure(it))
}
}
override fun deleteComment(parameter: DeleteCommentParameter): Result<CommentChangedResponse> {
TODO("Not yet implemented")
}

override fun deleteComment(parameter: DeleteCommentParameter): Flow<Result<CommentChangedResponse>> = channelFlow {
checkToken().collectLatest { tokenState ->
tokenState.onSuccess {
commentsDataSource.deleteComment(parameter).collectLatest {
trySend(it)
}
}.onFailure {
trySend(Result.failure(it))
}
}
override fun editComment(parameter: EditCommentParameter): Result<CommentChangedResponse> {
TODO("Not yet implemented")
}

override fun likeComment(parameter: LikeCommentParameter): Flow<Result<LikeResponse>> = channelFlow {
checkToken().collectLatest { tokenState ->
tokenState.onSuccess {
commentsDataSource.likeComment(parameter).collectLatest {
trySend(it)
}
}.onFailure {
trySend(Result.failure(it))
}
}
override fun likeComment(parameter: LikeCommentParameter): Result<LikeResponse> {
TODO("Not yet implemented")
}

private suspend fun checkToken() = tokenRepository.getCurrentTokens().last().let { tokenState ->
when (tokenState) {
is TokenState.Tokens.Valid -> {
flowOf(Result.success(Unit))
}

is TokenState.Error -> {
flowOf(Result.failure(tokenState.exception))
}

else -> {
flowOf(Result.failure(Exception("로그인 해주세요")))
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package com.android.mediproject.core.data.sign

import com.android.mediproject.core.model.requestparameters.LoginParameter
import com.android.mediproject.core.model.requestparameters.SignUpParameter
import kotlinx.coroutines.flow.Flow

interface SignRepository {
fun login(loginParameter: LoginParameter): Result<Boolean>

fun login(loginParameter: LoginParameter): Flow<Result<Unit>>

fun signUp(signUpParameter: SignUpParameter): Flow<Result<Unit>>
fun signUp(signUpParameter: SignUpParameter): Result<Boolean>

fun signOut()

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,20 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import javax.inject.Inject

class SignRepositoryImpl @Inject constructor(
class SignRepositoryImpl(
private val signDataSource: SignDataSource,
private val appDataStore: AppDataStore,
private val userInfoRepository: UserInfoRepository,
) : SignRepository {


/**
* 서버에 로그인 요청을 하고, 토큰 정보를 받는다.
*
* @param loginParameter 로그인 요청 파라미터
* @return 응답받은 토큰
*/
override fun login(loginParameter: LoginParameter): Flow<Result<Unit>> = channelFlow {
override fun login(loginParameter: LoginParameter): Result<Boolean> {
signDataSource.logIn(loginParameter).collect { signInResult ->

if (signInResult.isFailure) {
trySend(Result.failure(signInResult.exceptionOrNull() ?: Exception("로그인 실패")))
} else {
appDataStore.apply {
saveSkipIntro(true)
signInResult.onSuccess {
// 내 계정 정보 메모리에 저장
userInfoRepository.updateMyAccountInfo(AccountState.SignedIn(it._userId!!.toLong(), it._nickName!!, it._email!!))
saveMyAccountInfo(it._email!!, it._nickName!!, it._userId!!.toLong())
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 783b1cb

Please sign in to comment.