Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ fun ImageModal(
.wrapContentSize(),
horizontalAlignment = Alignment.End
) {
Icon(
imageVector = Icons.Default.Close,
contentDescription = "닫기",
tint = Color.White,
modifier = Modifier
.align(Alignment.End)
.clickable { onDismiss() }
.padding(bottom = 8.dp)
.size(24.dp)
)

AsyncImage(
model = imageUrl,
contentDescription = null,
Expand All @@ -62,11 +51,6 @@ fun ImageModal(
// contentDescription = null,
// modifier = Modifier
// )
/*Image( //테스트용!!
painter = painterResource(id = R.drawable.test),
contentDescription = null,
modifier = Modifier
)*/
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,67 @@
package com.paw.key.data.dto.response

import com.paw.key.domain.model.entity.archivedlist.ArchivedListEntity
import com.paw.key.domain.model.entity.archivedlist.ArchivedListPostsEntity
import com.paw.key.domain.model.entity.archivedlist.WriterEntity
import com.paw.key.domain.model.entity.savedlist.SavedListEntity
import com.paw.key.domain.model.entity.savedlist.SavedListPostEntity
import com.paw.key.domain.model.entity.savedlist.SavedWriterEntity
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class SavedListResponseDto(
@SerialName("postId")
val postId: Long,
data class SavedListResponseDataDto(
@SerialName("posts")
val posts: List<SavedDto>
) {
fun toEntity() = SavedListPostEntity(
posts = posts.map { it.toEntity() }
)
}

@Serializable
data class SavedDto(
@SerialName("postId")
val postId: Int,
@SerialName("createdAt")
val createdAt: String,

@SerialName("isLiked")
val isLiked: Boolean,

@SerialName("isLike")
val isLike: Boolean,
@SerialName("title")
val title: String,

@SerialName("representativeImageUrl")
val representativeImageUrl: String,

val representativeImageUrl: String? = null,
@SerialName("routeId")
val routeId: Int,
@SerialName("writer")
val writer: List<SavedWriterDto>,

val writer: SavedWriterDto,
@SerialName("descriptionTags")
val descriptionTags: List<String>

){
) {
fun toEntity() = SavedListEntity(
postId = postId,
createdAt = createdAt,
isLiked = isLiked,
isLiked = isLike,
title = title,
representativeImageUrl = representativeImageUrl,
writer = writer.map { it.toEntity() },
representativeImageUrl = representativeImageUrl ?: "",
routeId = routeId,
writer = writer.toEntity(),
descriptionTags = descriptionTags
)
}

@Serializable
data class SavedWriterDto(
@SerialName("userId")
val userId: Long,

val userId: Int,
@SerialName("petName")
val petName: String,

@SerialName("petProfileImageUrl")
val petProfileImageUrl: String
){
) {
fun toEntity() = SavedWriterEntity(
userId = userId,
petName = petName,
petProfileImageUrl = petProfileImageUrl
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package com.paw.key.data.repositoryimpl

import com.paw.key.data.remote.datasource.SavedListDataSource
import com.paw.key.domain.model.entity.savedlist.SavedListEntity
import com.paw.key.domain.model.entity.savedlist.SavedListPostEntity
import com.paw.key.domain.repository.SavedListRepository
import javax.inject.Inject

class SavedListRepositoryImpl @Inject constructor(
private val savedListDataSource: SavedListDataSource,
) : SavedListRepository {
override suspend fun getSavedList(userId: Int): Result<List<SavedListEntity>> = runCatching {
savedListDataSource.getSavedList(userId).data.map { it.toEntity() }
override suspend fun getSavedList(userId: Int): Result<SavedListPostEntity> = runCatching {
savedListDataSource.getSavedList(userId).data.toEntity()
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/com/paw/key/data/service/LikeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import retrofit2.http.Path

interface LikeService {

@POST("/api/v1/likes/{courseId}")
@POST("/api/v1/likes/{postId}")
suspend fun likeCourse(
@Header("X-USER-ID") userId: Int,
@Path("courseId") courseId: Int
@Path("postId") postId: Int
): BaseResponse<Unit>

@DELETE("/api/v1/likes/{courseId}")
@DELETE("/api/v1/likes/{postId}")
suspend fun unlikeCourse(
@Header("X-USER-ID") userId: Int,
@Path("courseId") courseId: Int
@Path("postId") postId: Int
): BaseResponse<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.paw.key.data.service

import com.paw.key.data.dto.response.BaseResponse
import com.paw.key.data.dto.response.SavedListResponseDto
import com.paw.key.data.dto.response.SavedListResponseDataDto
import retrofit2.http.GET
import retrofit2.http.Header

interface SavedListService {
@GET("users/me/likes")
suspend fun getSavedList(
@Header("X-USER-ID") userId: Int
): BaseResponse<List<SavedListResponseDto>>
): BaseResponse<SavedListResponseDataDto>
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
package com.paw.key.domain.model.entity.savedlist


data class SavedListPostEntity(
val posts: List<SavedListEntity>
)
data class SavedListEntity(
val postId: Long,
val postId: Int,
val createdAt: String,
val isLiked: Boolean,
val title: String,
val representativeImageUrl: String,
val writer: List<SavedWriterEntity>,
val routeId: Int,
val writer: SavedWriterEntity,
val descriptionTags: List<String>
)
data class SavedWriterEntity(
val userId: Long,
val userId: Int,
val petName: String,
val petProfileImageUrl: String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.paw.key.domain.repository

interface LikeRepository {
suspend fun likeCourse(userId: Int, courseId: Int): Result<Unit>
suspend fun unlikeCourse(userId: Int, courseId: Int): Result<Unit>
suspend fun likeCourse(userId: Int, postId: Int): Result<Unit>
suspend fun unlikeCourse(userId: Int, postId: Int): Result<Unit>
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.paw.key.domain.repository

import com.paw.key.domain.model.entity.savedlist.SavedListEntity
import com.paw.key.domain.model.entity.savedlist.SavedListPostEntity

interface SavedListRepository {
suspend fun getSavedList(userId: Int): Result<List<SavedListEntity>>
suspend fun getSavedList(userId: Int): Result<SavedListPostEntity>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.paw.key.data.dto.request.list.PostsListRequestDto
import com.paw.key.data.dto.request.list.TraitList
import com.paw.key.domain.repository.LikeRepository
import com.paw.key.domain.repository.filter.FilterOptionRepository
import com.paw.key.domain.repository.list.PostsListRepository
import com.paw.key.presentation.ui.course.entire.tab.map.List.state.TapListContract
Expand All @@ -18,7 +19,8 @@ import javax.inject.Inject
@HiltViewModel
class TapListViewModel @Inject constructor(
private val filterOptionRepository: FilterOptionRepository,
private val postsListRepository: PostsListRepository
private val postsListRepository: PostsListRepository,
private val likeRepository: LikeRepository
) : ViewModel() {

private val _state = MutableStateFlow(TapListContract.TapListState())
Expand Down Expand Up @@ -122,6 +124,13 @@ class TapListViewModel @Inject constructor(
}
}
}

fun toggleLike(userId: Int, postId: Int) {
viewModelScope.launch {
likeRepository.likeCourse(userId = 2, postId = 6)
}
}

fun updateMood(option: String) {
_state.update {
it.copy(
Expand Down Expand Up @@ -315,19 +324,19 @@ class TapListViewModel @Inject constructor(
return isAllOptionsSelected()
}

fun toggleLike(postId: Int, isLiked: Boolean) {
viewModelScope.launch {
_state.update { state ->
val updatedPosts = state.postsResult?.posts?.map {
if (it.postId == postId) it.copy(isLike = isLiked) else it
} ?: emptyList()

val updatedPostsResult = state.postsResult?.copy(posts = updatedPosts)

state.copy(
postsResult = updatedPostsResult
)
}
}
}
// fun toggleLike(postId: Int, isLiked: Boolean) {
// viewModelScope.launch {
// _state.update { state ->
// val updatedPosts = state.postsResult?.posts?.map {
// if (it.postId == postId) it.copy(isLike = isLiked) else it
// } ?: emptyList()
//
// val updatedPostsResult = state.postsResult?.copy(posts = updatedPosts)
//
// state.copy(
// postsResult = updatedPostsResult
// )
// }
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fun ArchivedCourseDetailScreen(
petName = petName,
date = date,
location = location,
isLike = isLike,
onClickLike = {},
content = content,
petProfileImage = petProfileImage,
routeMapImageUrl = routeMapImageUrl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand All @@ -25,6 +26,11 @@ fun ArchivedCourseRoute(
) {
val state = viewModel.state.collectAsStateWithLifecycle()

LaunchedEffect(Unit) {
// Todo : userId 네비게이션 연결
viewModel.getArchivedList(userId = 2)
}

ArchivedCourseListScreen(
state = state.value,
navigateUp = navigateUp,
Expand Down Expand Up @@ -83,7 +89,9 @@ fun ArchivedCourseListScreenPreview() {
state = ArchivedListState(),
navigateUp = {},
navigateNext = {},
onClickLike = {}
onClickLike = {
_, _ ->
}

)
}
Expand Down
Loading