Skip to content

Commit

Permalink
[feat] : #15 전체 친구 목록 조회
Browse files Browse the repository at this point in the history
  • Loading branch information
SsongSik committed May 17, 2023
1 parent f4fca82 commit 987a4d7
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ interface AddFriendsService {
@Path("userId") userId: String
) : Response<BasePomeResponse<BaseAllData<GetFriendRecord>>>

//친구 삭제
@DELETE("api/v1/users/friend/{friendId}")
suspend fun deleteFriend(
@Path("friendId") friendId: String
) : Response<BasePomeResponse<DeleteFriend>>

//모든 친구 기록 조회
@GET("api/v1/records/friends")
suspend fun getAllFriendRecord() :
Response<BasePomeResponse<BaseAllData<GetFriendRecord>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri
override fun initView() {
setUpRecyclerView()
friendRecordSetUpRecyclerView()
getAllFriendRecord()

//친구 조회
viewModel.getFriend(object : CoroutineErrorHandler{
Expand Down Expand Up @@ -65,13 +66,36 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri
}
}
is ApiResponse.Failure -> {
hideLoading()
}
is ApiResponse.Loading -> {
showLoading()
}
}
}

viewModel.getAllFriendRecordResponse.observe(viewLifecycleOwner){
when(it) {
is ApiResponse.Success -> {
hideLoading()
it.data.data?.content?.let { list ->
(binding.friendDetailRv.adapter as FriendRecordGetAdapter).submitList(
list
)
}
}
is ApiResponse.Failure -> {
hideLoading()
}
is ApiResponse.Loading -> {
showLoading()
}
}
}

binding.friendAllIv.setOnClickListener {
getAllFriendRecord()
}
}

//친구 목록 조회 RV
Expand Down Expand Up @@ -113,4 +137,13 @@ class FriendFragment : BaseFragment<FragmentFriendBinding>(R.layout.fragment_fri
Toast.makeText(requireContext(), "${it.nickname}", Toast.LENGTH_SHORT).show()
}
}

private fun getAllFriendRecord() {
viewModel.getAllRecordFriend(object : CoroutineErrorHandler{
override fun onError(message: String) {
Toast.makeText(requireContext(), message, Toast.LENGTH_SHORT).show()
hideLoading()
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ interface AddFriendsDataSource {
userId : String
) : Flow<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>>

//친구 삭제
fun deleteFriend(
friendId: String
) : Flow<ApiResponse<BasePomeResponse<DeleteFriend>>>

//모든 친구 기록 조회
fun getAllFriendRecord() : Flow<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ class AddFriendsRemoteDataSource @Inject constructor(
override fun deleteFriend(friendId: String): Flow<ApiResponse<BasePomeResponse<DeleteFriend>>> = apiRequestFlow{
service.deleteFriend(friendId)
}

override fun getAllFriendRecord(): Flow<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>> = apiRequestFlow {
service.getAllFriendRecord()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ class AddFriendsRepository @Inject constructor(
fun getFriendRecord(userId : String) = dataSource.getFriendRecord(userId)

fun deleteFriend(friendId: String) = dataSource.deleteFriend(friendId)

fun getAllFriendRecord() = dataSource.getAllFriendRecord()
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ class AddFriendsViewModel @Inject constructor(
private val _deleteFriendResponse = MutableLiveData<ApiResponse<BasePomeResponse<DeleteFriend>>>()
val deleteFriendResponse : LiveData<ApiResponse<BasePomeResponse<DeleteFriend>>> = _deleteFriendResponse

//모든 친구 기록 조회
private val _getAllFriendRecordResponse = MutableLiveData<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>>()
val getAllFriendRecordResponse : LiveData<ApiResponse<BasePomeResponse<BaseAllData<GetFriendRecord>>>> = _getAllFriendRecordResponse


fun findFriendsData(nickName: String, coroutineErrorHandler: CoroutineErrorHandler) = baseRequest(
_findFriendsDataResponse,
Expand Down Expand Up @@ -80,13 +84,21 @@ class AddFriendsViewModel @Inject constructor(
repository.getFriendRecord(userId)
}

//친구 삭제
fun deleteFriend(friendId : String, coroutineErrorHandler: CoroutineErrorHandler) = baseRequest(
_deleteFriendResponse,
coroutineErrorHandler
){
repository.deleteFriend(friendId)
}

fun getAllRecordFriend(coroutineErrorHandler: CoroutineErrorHandler) = baseRequest(
_getAllFriendRecordResponse,
coroutineErrorHandler
){
repository.getAllFriendRecord()
}

//친구 조회
val friendGet: LiveData<List<GetFriends?>> = Transformations.map(_getFriendResponse) {
when(it) {
Expand Down

0 comments on commit 987a4d7

Please sign in to comment.