Skip to content

Commit

Permalink
Merge pull request #85 from Team-Walkie/compose/community_ui_fix
Browse files Browse the repository at this point in the history
커뮤니티 [팔로잉/전체글] 선택 버튼 추가 및 게시글 화면 구현
  • Loading branch information
yonghanJu authored Sep 12, 2024
2 parents 3e61023 + 3c4e8fe commit 07cba04
Show file tree
Hide file tree
Showing 25 changed files with 457 additions and 116 deletions.
4 changes: 4 additions & 0 deletions app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import com.whyranoid.domain.usecase.GetTopRankChallengePreviewsUseCase
import com.whyranoid.domain.usecase.GetUserBadgesUseCase
import com.whyranoid.domain.usecase.GetUserDetailUseCase
import com.whyranoid.domain.usecase.GetUserPostPreviewsUseCase
import com.whyranoid.domain.usecase.GetUserPostsUseCase
import com.whyranoid.domain.usecase.GetUserUseCase
import com.whyranoid.domain.usecase.LikePostUseCase
import com.whyranoid.domain.usecase.RequestLoginUseCase
Expand Down Expand Up @@ -98,6 +99,7 @@ import com.whyranoid.presentation.viewmodel.SignInViewModel
import com.whyranoid.presentation.viewmodel.SplashViewModel
import com.whyranoid.presentation.viewmodel.TotalBadgeViewModel
import com.whyranoid.presentation.viewmodel.UserPageViewModel
import com.whyranoid.presentation.viewmodel.UserPostsViewModel
import com.whyranoid.presentation.viewmodel.challenge.ChallengeDetailViewModel
import com.whyranoid.presentation.viewmodel.challenge.ChallengeExitViewModel
import com.whyranoid.presentation.viewmodel.challenge.ChallengeMainViewModel
Expand Down Expand Up @@ -132,6 +134,7 @@ val viewModelModule =
viewModel { FollowingViewModel(get(), get(), get(), get(), get(), get()) }
viewModel { SettingViewModel(get(), get()) }
viewModel { TotalBadgeViewModel(get(), get()) }
viewModel { UserPostsViewModel(get(), get()) }
}

val repositoryModule =
Expand Down Expand Up @@ -198,6 +201,7 @@ val useCaseModule =
single { SendCommentUseCase(get(), get()) }
single { GetUserUseCase(get()) }
single { ChangeChallengeStatusUseCase(get(), get())}
single { GetUserPostsUseCase(get(), get()) }
}

val databaseModule =
Expand Down
4 changes: 4 additions & 0 deletions data/src/main/java/com/whyranoid/data/API.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ object API {

const val UPLOAD_POST = "api/community/upload-post"

// 사용자가 작성한 게시글을 가져온다
const val LIST_UP_MY_POST = "api/walkies/listup-my-post"

// 사용자의 팔로잉들의 게시글을 가져온다
const val LIST_UP_POST = "api/community/listup-post"

const val LIST_UP_EVERY_POST = "api/community/listup-every-post"

const val LIST_UP_COMMENT = "api/community/listup-comment"

const val SEARCH = "api/community/search-nickname"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class PostDataSourceImpl(private val postService: PostService) : PostDataSource
return Result.success(response.body()?.map { it.toPostPreview() }!!)
}

override suspend fun getMyPosts(uid: Long, myUid: Long): Result<List<Post>> {
val response = postService.myPosts(uid)
response.body() ?: return Result.failure(Throwable(response.message().toString()))
return Result.success(response.body()?.map { it.toPost(myUid) }!!)
}

override suspend fun getMyPostPreviews(
uid: Long,
year: Int,
Expand Down Expand Up @@ -101,6 +107,13 @@ class PostDataSourceImpl(private val postService: PostService) : PostDataSource
}
}

override suspend fun getEveryPost(uid: Long): Result<List<Post>> {
return kotlin.runCatching {
val posts = requireNotNull(postService.getPosts(uid).body())
posts.map { it.toPost(uid) }
}
}

override suspend fun getComments(postId: Long): Result<List<Comment>> {
return kotlin.runCatching {
val comments = requireNotNull(postService.getComments(postId).body())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,23 @@ interface PostService {
@Part image: MultipartBody.Part,
): Response<UploadPostResponse>

// 사용자가 작성한 글을 가져온다
@GET(API.LIST_UP_MY_POST)
suspend fun myPosts(
@Query("walkieId") uid: Long,
): Response<List<PostResponse>>

// 사용자의 팔로잉의 글을 가져온다
@GET(API.LIST_UP_POST)
suspend fun getPosts(
@Query("walkieId") uid: Long,
): Response<List<PostResponse>>

@GET(API.LIST_UP_EVERY_POST)
suspend fun getEveryPosts(
@Query("walkieId") uid: Long,
): Response<List<PostResponse>>

@GET(API.LIST_UP_COMMENT)
suspend fun getComments(
@Query("postId") postId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ data class PostResponse(
val destructedHistoryContent = historyContent.split('_')
return PostPreview(
author = poster.toUser(),
id = this.poster.uid,
id = this.postId,
isLiked = this.liked,
likers = this.likers.map { it.toUser() },
imageUrl = this.photo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ class PostRepositoryImpl(
return postDataSource.getMyPostPreviews(uid, year, month, day)
}

override suspend fun getMyPosts(uid: Long, myUid: Long): Result<List<Post>> {
return postDataSource.getMyPosts(uid, myUid)
}

override suspend fun getPost(postId: Long): Result<Post> {
return postDataSource.getPost(postId)
}
Expand All @@ -53,6 +57,10 @@ class PostRepositoryImpl(
return postDataSource.getMyFollowingsPost(uid)
}

override suspend fun getEveryPost(uid: Long): Result<List<Post>> {
return postDataSource.getMyFollowingsPost(uid)
}

override suspend fun getComments(postId: Long): Result<List<Comment>> {
return postDataSource.getComments(postId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@ import com.whyranoid.domain.model.post.Post
import com.whyranoid.domain.model.post.PostPreview

interface PostDataSource {

/**
* 사용자의 팔로잉들의 글을 가져온다
*
* @param uid
* @return
*/
suspend fun getPostPreviews(uid: Long): Result<List<PostPreview>>

/**
* 해당 사용자가 작성한 글들을 가져온다
*
* @param uid
* @return
*/
suspend fun getMyPostPreviews(uid: Long): Result<List<PostPreview>>

/**
* 해당 사용자가 작성한 글들을 가져온다
*
* @param uid
* @return
*/
suspend fun getMyPosts(uid: Long, myUid: Long): Result<List<Post>>

suspend fun getPostPreviews(
uid: Long,
year: Int,
Expand All @@ -35,6 +56,8 @@ interface PostDataSource {

suspend fun getMyFollowingsPost(uid: Long): Result<List<Post>>

suspend fun getEveryPost(uid: Long): Result<List<Post>>

suspend fun getComments(postId: Long): Result<List<Comment>>

suspend fun sendComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.whyranoid.domain.model.post.PostPreview

data class UserDetail(
val user: User,
val postCount: Int,
val postCount: Int?,
val followerCount: Int,
val followingCount: Int,
val isFollowing: Boolean? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,61 @@ import com.whyranoid.domain.model.post.Post
import com.whyranoid.domain.model.post.PostPreview

interface PostRepository {

/**
* 유저의 팔로잉들이 작성한 글을 가져옴
*
* @param uid
* @return
*/
suspend fun getUserPostPreviews(uid: Long): Result<List<PostPreview>>


/**
* 해당 유저가 작성한 글을 가져옴
*
* @param uid
* @return
*/
suspend fun getMyPostPreviews(uid: Long): Result<List<PostPreview>>

/**
* 유저의 팔로잉들이 작성한 글을 가져옴
*
* @param uid
* @return
*/
suspend fun getUserPostPreviews(
uid: Long,
year: Int,
month: Int,
day: Int,
): Result<List<PostPreview>>

/**
* 해당 유저가 작성한 글을 가져옴
*
* @param uid
* @return
*/
suspend fun getMyPostPreviews(
uid: Long,
year: Int,
month: Int,
day: Int,
): Result<List<PostPreview>>

/**
* 해당 유저가 작성한 글을 가져옴
*
* @param uid
* @return
*/
suspend fun getMyPosts(
uid: Long,
myUid: Long
): Result<List<Post>>

suspend fun getPost(postId: Long): Result<Post>

suspend fun uploadPost(
Expand All @@ -35,6 +72,8 @@ interface PostRepository {

suspend fun getMyFollowingsPost(uid: Long): Result<List<Post>>

suspend fun getEveryPost(uid: Long): Result<List<Post>>

suspend fun getComments(postId: Long): Result<List<Comment>>

suspend fun sendComment(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GetFollowingsPostsUseCase(
private val accountRepository: AccountRepository,
private val postRepository: PostRepository,
) {
suspend operator fun invoke(): Result<List<Post>> {
suspend operator fun invoke(isEveryPost: Boolean): Result<List<Post>> {
val myUid = requireNotNull(accountRepository.walkieId.first())
return postRepository.getMyFollowingsPost(myUid)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.whyranoid.domain.usecase

import com.whyranoid.domain.model.post.Post
import com.whyranoid.domain.repository.AccountRepository
import com.whyranoid.domain.repository.PostRepository

class GetUserPostsUseCase(
private val accountRepository: AccountRepository,
private val postRepository: PostRepository,
) {
suspend operator fun invoke(uid: Long): Result<List<Post>> {
return postRepository.getMyPosts(uid, accountRepository.getUID())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.material3.Divider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import com.whyranoid.domain.model.post.Post
import com.whyranoid.domain.model.post.toPostPreview
import com.whyranoid.domain.model.user.User
Expand All @@ -22,6 +20,7 @@ fun PostItem(
onLikeClicked: (Long) -> Unit = {},
onProfileClicked: (User) -> Unit = {},
onCommentClicked: (Post) -> Unit = {},
onPostPreviewClicked: (uid: Long, postId: Long) -> Unit = { _, _ -> }
) {
Column(
Modifier.fillMaxHeight(),
Expand All @@ -42,7 +41,8 @@ fun PostItem(
postPreview = post.toPostPreview(),
modifier = Modifier
.fillMaxWidth()
.aspectRatio(1f)
.aspectRatio(1f),
onPostPreviewClicked = onPostPreviewClicked
)

PostContentItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.whyranoid.presentation.screens.challenge.ChallengeExitScreen
import com.whyranoid.presentation.screens.challenge.ChallengeMainScreen
import com.whyranoid.presentation.screens.community.CommentScreen
import com.whyranoid.presentation.screens.community.SearchFriendScreen
import com.whyranoid.presentation.screens.community.UserPostScreen
import com.whyranoid.presentation.screens.mypage.MyPageScreen
import com.whyranoid.presentation.screens.mypage.TotalBadgeScreen
import com.whyranoid.presentation.screens.mypage.UserPageScreen
Expand Down Expand Up @@ -144,10 +145,6 @@ fun AppScreenContent(
MyPageScreen(navController)
}

composable(Screen.MyPage.route) {
MyPageScreen(navController)
}

composable(Screen.TotalBadgeScreen.route) {
TotalBadgeScreen(navController)
}
Expand All @@ -169,6 +166,7 @@ fun AppScreenContent(
val isChallenging = arguments.getBoolean("isChallenging")
ChallengeDetailScreen(navController, challengeId, isChallenging)
}

composable(
Screen.ChallengeExitScreen.route,
Screen.ChallengeExitScreen.arguments,
Expand Down Expand Up @@ -213,6 +211,12 @@ fun AppScreenContent(
post?.let {
CommentScreen(
post = it,
onProfileClicked = { uid, nickname ->
navController.navigate("userpage/${uid}/${nickname}/false")
},
onMyProfileClicked = {
navController.navigate(Screen.MyPage.route)
},
onBackClicked = { navController.popBackStack() },
)
}
Expand All @@ -221,6 +225,29 @@ fun AppScreenContent(
composable(Screen.SettingScreen.route) {
SettingsScreen(navHostController = navController)
}

composable(
Screen.UserPostsScreen.route,
Screen.UserPostsScreen.arguments,
) { backStackEntry ->
val arguments = requireNotNull(backStackEntry.arguments)
val uid = arguments.getLong(Screen.UID_ARGUMENT)
val postId = arguments.getLong(Screen.POST_ID)
UserPostScreen(
uid,
postId,
onProfileClicked = { user ->
navController.navigate("userPage/${user.uid}/${user.nickname}/false")
},
onCommentClicked = { post ->
navController.currentBackStackEntry?.savedStateHandle?.set(
"post",
post
)
navController.navigate(Screen.CommentScreen.route)
}
)
}
}
}
}
Loading

0 comments on commit 07cba04

Please sign in to comment.