Skip to content

Commit

Permalink
Merge pull request #128 from koview/feature/125
Browse files Browse the repository at this point in the history
[SJ-#125] memberId 관련 API 수정사항 반영 및 글 작성 기능 수정
  • Loading branch information
SeonJeongk authored Aug 27, 2024
2 parents 0339055 + 608835a commit 531c06c
Show file tree
Hide file tree
Showing 45 changed files with 536 additions and 424 deletions.
Binary file modified .gitignore
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ data class CoviewCommentItem(
val commentId: Long,
val content: String,
val writer: String,
val profileImage: CoviewImage,
val profileImage: ImageDTO,
val createdDate: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ data class ReviewsResult(
data class CoviewReviewList(
val reviewId: Long,
val content: String,
val writer: String,
val profileImage: CoviewImage?,
val imageList: List<CoviewImage?>,
val profileInfo: ProfileResponseDTO,
val imageList: List<ImageDTO?>,
val purchaseLinkList: List<PurchaseLinkList>,
val totalCommentCount: Long,
val totalLikeCount: Long,
val isLiked: Boolean,
val createdAt: String,
val updatedAt: String
)

data class CoviewImage(
val imageId: Long,
val url: String
)
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package com.example.koview.data.model.response

import java.time.LocalDate

// 내 정보 조회
data class GetMyDetailResponse(
val isSuccess: Boolean,
val code: String,
val message: String,
val result: MyDetailResult
)

data class MyDetailResult(
val imageId: Long,
val url: String,
val nickname: String
val result: ProfileResponseDTO
)

// 내 리뷰 전체 조회
Expand All @@ -34,7 +26,7 @@ data class GetMyReviewsResult(
data class ReviewList(
val reviewId: Long,
val content: String,
val writer: String,
val profileInfo: ProfileResponseDTO,
val imageList: List<ImageDTO>,
val totalCommentCount: Long,
val totalLikesCount: Long,
Expand All @@ -44,6 +36,7 @@ data class ReviewList(

// 마이페이지 리뷰 화면을 위한 데이터 클래스
data class MyReview(
val memberId: Long,
val reviewId: Long,
val content: String,
val writer: String,
Expand All @@ -55,6 +48,14 @@ data class MyReview(
var isSelected: Boolean = false
)

// 리뷰 프로필 정보
data class ProfileResponseDTO(
val imageId: Long,
val imageUrl: String,
val memberId: Long,
val memberNickname: String
)

// 이미지 DTO
data class ImageDTO(
val imageId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ data class ProductReviewResult (
data class ProductReviewDetail (
val reviewId: Long,
val content: String,
val writer: String,
val profileImage: String?,
val profileInfo: ProfileResponseDTO,
val imageList: List<ProductReviewDetailImageList>,
val totalCommentCount: Long,
val totalLikesCount: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ data class ReviewDetailResult(
data class ReviewDetailList(
val reviewId: Long,
val content: String,
val writer: String,
val profileImage: ReviewDetailImage,
val imageList: List<ReviewDetailImage>,
val profileInfo: ProfileResponseDTO,
val imageList: List<ImageDTO?>,
val purchaseLinkList: List<PurchaseLinkList>,
val totalCommentCount: Long,
val totalLikeCount: Long,
Expand All @@ -28,16 +27,11 @@ data class ReviewDetailList(
val updatedAt: String
)

data class ReviewDetailImage(
val imageId: Long,
val url: String
)

data class ReviewImageResponse(
val isSuccess: Boolean,
val code: String,
val message: String,
val result: List<ReviewDetailImage>
val result: List<ImageDTO>
)

data class CreateReviewResponse(
Expand All @@ -49,9 +43,8 @@ data class CreateReviewResponse(
data class ReviewResult(
val reviewId: Long,
val content: String,
val writer: String,
val profileImage: ReviewDetailImage,
val imageList: List<ReviewDetailImage>,
val profileInfo: ProfileResponseDTO,
val imageList: List<ImageDTO>,
val totalCommentCount: Long,
val totalLikesCount: Long,
val isLiked: Boolean,
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/example/koview/data/remote/MainApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ interface MainApi {
suspend fun getReviewDetails(
@Query("page") page: Int,
@Query("size") size: Int,
@Query("clickedReviewId") clickedReviewId: Long
@Query("clickedReviewId") clickedReviewId: Long,
@Query("memberId") memberId: Long
): Response<ReviewDetailResponse>

@GET("products/{productId}/reviews")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ interface MainRepository {
suspend fun getReviewDetails(
page: Int,
size: Int,
clickedReviewId: Long
clickedReviewId: Long,
memberId: Long
): BaseState<ReviewDetailResponse>

suspend fun getProductReview(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,10 @@ class MainRepositoryImpl @Inject constructor(private val api: MainApi) : MainRep
override suspend fun getReviewDetails(
page: Int,
size: Int,
clickedReviewId: Long
clickedReviewId: Long,
memberId: Long
): BaseState<ReviewDetailResponse> = runRemote {
api.getReviewDetails(page, size, clickedReviewId)
api.getReviewDetails(page, size, clickedReviewId, memberId)
}

override suspend fun getProductReview(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.example.koview.presentation.ui.intro.signup.setinfo

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.fragment.app.viewModels
import androidx.navigation.NavController
Expand All @@ -27,8 +26,6 @@ class SignUpSetInfoFragment : BaseFragment<FragmentSignupSetInfoBinding>(R.layou
val selectedShops: List<Int> = args.checkedShops.toList()
viewModel.selectedShops.value = selectedShops

// To-do : 잘 들어오는 지에 대한 것이기 때문에 나중에 삭제
showToastMessage(selectedShops.toString())
initEventObserve()
setObserve()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,10 @@ class SignUpSetInfoViewModel @Inject constructor(
repository.memberSignUp(request).let {
when (it) {
is BaseState.Error -> {
Log.d("SignUpSetInfoFragment", "SignUp ERROR(Request Success)")
Log.d("SignUpSetInfoFragment", it.code.toString() +", "+ it.msg.toString())
Log.d("SignUpSetInfoFragment", it.code +", "+ it.msg)
}

is BaseState.Success -> {
Log.d("SignUpSetInfoFragment", "SignUp SUCCESS")
navigateToNext()
}
}
Expand All @@ -100,7 +98,7 @@ class SignUpSetInfoViewModel @Inject constructor(


// 빈 항목이 있는지, 이메일 형식에 맞는지, 비밀번호 확인이 맞는지 체크
fun validate(){
private fun validate(){
val emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+"

if (email.value.toString().equals("")){
Expand Down Expand Up @@ -133,7 +131,7 @@ class SignUpSetInfoViewModel @Inject constructor(
}
}

fun navigateToNext() {
private fun navigateToNext() {
viewModelScope.launch {
_event.emit(SetInfoEvent.NavigateToComplete)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import com.example.koview.data.model.response.QueryResultList
import com.example.koview.databinding.FragmentAskBinding
import com.example.koview.presentation.base.BaseFragment
import com.example.koview.presentation.ui.main.ask.adapter.AskAdapter
import com.example.koview.presentation.ui.main.ask.model.AskData

class AskFragment : BaseFragment<FragmentAskBinding>(R.layout.fragment_ask), AskInterface {

Expand Down Expand Up @@ -53,15 +52,16 @@ class AskFragment : BaseFragment<FragmentAskBinding>(R.layout.fragment_ask), Ask

private fun initEventObserve() {
repeatOnStarted {
viewModel.event.collect { event ->
when (event) {
viewModel.event.collect {
when (it) {
is AskEvent.NavigateToAskDetail -> {
viewModel.askDetail.value?.let { askDetail ->
findNavController().toAskDetail(askDetail)
}
}

AskEvent.NavigateToPost -> findNavController().toPostAsk()
is AskEvent.ShowToastMessage -> showToastMessage(it.msg)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.example.koview.presentation.ui.main.ask

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -22,6 +21,7 @@ import javax.inject.Inject
sealed class AskEvent {
data class NavigateToAskDetail(val askDetail: QueryResultList) : AskEvent()
data object NavigateToPost : AskEvent()
data class ShowToastMessage(val msg: String) : AskEvent()
}

@HiltViewModel
Expand All @@ -48,8 +48,7 @@ class AskViewModel @Inject constructor(private val repository: MainRepository) :
repository.getQueries().let {
when (it) {
is BaseState.Error -> {
Log.d("AskFragment", "GetQueries ERROR(Request Success)")
Log.d("AskFragment", it.code + ", " + it.msg)
_event.emit(AskEvent.ShowToastMessage(it.msg))
}

is BaseState.Success -> {
Expand Down Expand Up @@ -98,6 +97,7 @@ class AskViewModel @Inject constructor(private val repository: MainRepository) :
// }
// }

// 나도 궁금 변경 반영
fun postWithQuery(item: QueryResultList) {
viewModelScope.launch {
val result = if (item.isWithQuery) {
Expand All @@ -106,32 +106,34 @@ class AskViewModel @Inject constructor(private val repository: MainRepository) :
repository.postWithQuery(item.queryId)
}

when (result) {
is BaseState.Success -> {
val updatedItem = item.copy(
isWithQuery = !item.isWithQuery,
totalWithQueryCount = if (item.isWithQuery) {
item.totalWithQueryCount - 1
} else {
item.totalWithQueryCount + 1
}
)

_getQueries.update { currentList ->
currentList.map {
if (it.queryId == updatedItem.queryId) {
updatedItem
result.let {
when (it) {
is BaseState.Success -> {
val updatedItem = item.copy(
isWithQuery = !item.isWithQuery,
totalWithQueryCount = if (item.isWithQuery) {
item.totalWithQueryCount - 1
} else {
it
item.totalWithQueryCount + 1
}
)

_getQueries.update { currentList ->
currentList.map {
if (it.queryId == updatedItem.queryId) {
updatedItem
} else {
it
}
}
}
}

_askDetail.value = updatedItem
}
_askDetail.value = updatedItem
}

is BaseState.Error -> {
Log.d("AskDetailFragment", "ERROR(Request Success)")
is BaseState.Error -> {
_event.emit(AskEvent.ShowToastMessage(it.msg))
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class AskAnswerFragment : BaseFragment<FragmentAskAnswerBinding>(R.layout.fragme
viewModel.event.collect {
when (it) {
AskAnswerEvent.NavigateToAskDetail -> findNavController().toAskDetail()
is AskAnswerEvent.ShowToastMessage -> showToastMessage(it.msg)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import com.example.koview.data.model.BaseState
import com.example.koview.data.model.requeset.QueryAnswerRequest
import com.example.koview.data.model.response.ReviewList
import com.example.koview.data.repository.MainRepository
import com.example.koview.presentation.ui.main.ask.askdetail.AskDetailEvent
import com.example.koview.presentation.ui.main.global.product.model.Review
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -21,7 +19,9 @@ import javax.inject.Inject

sealed class AskAnswerEvent {
data object NavigateToAskDetail : AskAnswerEvent()
data class ShowToastMessage(val msg: String) : AskAnswerEvent()
}

@HiltViewModel
class AskAnswerViewModel @Inject constructor(private val repository: MainRepository) : ViewModel() {

Expand All @@ -44,8 +44,7 @@ class AskAnswerViewModel @Inject constructor(private val repository: MainReposit
repository.postQueryAnswer(queryId, params).let {
when (it) {
is BaseState.Error -> {
Log.d("AskAnswerFragment", "PostQueryAnswer ERROR(Request Success)")
Log.d("AskAnswerFragment", it.code + ", " + it.msg)
_event.emit(AskAnswerEvent.ShowToastMessage(it.msg))
}

is BaseState.Success -> {
Expand All @@ -58,17 +57,17 @@ class AskAnswerViewModel @Inject constructor(private val repository: MainReposit
}
}

fun getMyReviews() {
private fun getMyReviews() {
viewModelScope.launch {
repository.getMyReviews(
page = 1,
size = 20
).let {
when (it) {
is BaseState.Error -> {
Log.d("AskAnswerFragment", "GetMyReviews ERROR(Request Success)")
Log.d("AskAnswerFragment", it.code + ", " + it.msg)
_event.emit(AskAnswerEvent.ShowToastMessage(it.msg))
}

is BaseState.Success -> {
_reviewList.value = it.body.result.reviewList
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AskAnswerReviewAdapter(listener: AskAnswerInterface) :
}

binding.rvImage.layoutManager =
LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
binding.rvImage.adapter = AskAnswerReviewImageAdapter(review.imageList)
}
}
Expand Down
Loading

0 comments on commit 531c06c

Please sign in to comment.