Skip to content

Commit e688833

Browse files
authored
merge #113 ->develop
[Mod/#109] api연결 다해따. .
2 parents 8f00ccb + 68b7e92 commit e688833

File tree

17 files changed

+263
-146
lines changed

17 files changed

+263
-146
lines changed

app/src/main/java/com/paw/key/core/designsystem/component/ImageModal.kt

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ fun ImageModal(
3737
.wrapContentSize(),
3838
horizontalAlignment = Alignment.End
3939
) {
40-
Icon(
41-
imageVector = Icons.Default.Close,
42-
contentDescription = "닫기",
43-
tint = Color.White,
44-
modifier = Modifier
45-
.align(Alignment.End)
46-
.clickable { onDismiss() }
47-
.padding(bottom = 8.dp)
48-
.size(24.dp)
49-
)
50-
5140
AsyncImage(
5241
model = imageUrl,
5342
contentDescription = null,
@@ -62,11 +51,6 @@ fun ImageModal(
6251
// contentDescription = null,
6352
// modifier = Modifier
6453
// )
65-
/*Image( //테스트용!!
66-
painter = painterResource(id = R.drawable.test),
67-
contentDescription = null,
68-
modifier = Modifier
69-
)*/
7054
}
7155
}
7256
}
Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,67 @@
11
package com.paw.key.data.dto.response
22

3+
import com.paw.key.domain.model.entity.archivedlist.ArchivedListEntity
4+
import com.paw.key.domain.model.entity.archivedlist.ArchivedListPostsEntity
5+
import com.paw.key.domain.model.entity.archivedlist.WriterEntity
36
import com.paw.key.domain.model.entity.savedlist.SavedListEntity
7+
import com.paw.key.domain.model.entity.savedlist.SavedListPostEntity
48
import com.paw.key.domain.model.entity.savedlist.SavedWriterEntity
59
import kotlinx.serialization.SerialName
610
import kotlinx.serialization.Serializable
711

812
@Serializable
9-
data class SavedListResponseDto(
10-
@SerialName("postId")
11-
val postId: Long,
13+
data class SavedListResponseDataDto(
14+
@SerialName("posts")
15+
val posts: List<SavedDto>
16+
) {
17+
fun toEntity() = SavedListPostEntity(
18+
posts = posts.map { it.toEntity() }
19+
)
20+
}
1221

22+
@Serializable
23+
data class SavedDto(
24+
@SerialName("postId")
25+
val postId: Int,
1326
@SerialName("createdAt")
1427
val createdAt: String,
15-
16-
@SerialName("isLiked")
17-
val isLiked: Boolean,
18-
28+
@SerialName("isLike")
29+
val isLike: Boolean,
1930
@SerialName("title")
2031
val title: String,
21-
2232
@SerialName("representativeImageUrl")
23-
val representativeImageUrl: String,
24-
33+
val representativeImageUrl: String? = null,
34+
@SerialName("routeId")
35+
val routeId: Int,
2536
@SerialName("writer")
26-
val writer: List<SavedWriterDto>,
27-
37+
val writer: SavedWriterDto,
2838
@SerialName("descriptionTags")
2939
val descriptionTags: List<String>
30-
31-
){
40+
) {
3241
fun toEntity() = SavedListEntity(
3342
postId = postId,
3443
createdAt = createdAt,
35-
isLiked = isLiked,
44+
isLiked = isLike,
3645
title = title,
37-
representativeImageUrl = representativeImageUrl,
38-
writer = writer.map { it.toEntity() },
46+
representativeImageUrl = representativeImageUrl ?: "",
47+
routeId = routeId,
48+
writer = writer.toEntity(),
3949
descriptionTags = descriptionTags
4050
)
4151
}
4252

4353
@Serializable
4454
data class SavedWriterDto(
4555
@SerialName("userId")
46-
val userId: Long,
47-
56+
val userId: Int,
4857
@SerialName("petName")
4958
val petName: String,
50-
5159
@SerialName("petProfileImageUrl")
5260
val petProfileImageUrl: String
53-
){
61+
) {
5462
fun toEntity() = SavedWriterEntity(
5563
userId = userId,
5664
petName = petName,
5765
petProfileImageUrl = petProfileImageUrl
5866
)
59-
}
67+
}

app/src/main/java/com/paw/key/data/repositoryimpl/SavedListRepositoryImpl.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package com.paw.key.data.repositoryimpl
22

33
import com.paw.key.data.remote.datasource.SavedListDataSource
44
import com.paw.key.domain.model.entity.savedlist.SavedListEntity
5+
import com.paw.key.domain.model.entity.savedlist.SavedListPostEntity
56
import com.paw.key.domain.repository.SavedListRepository
67
import javax.inject.Inject
78

89
class SavedListRepositoryImpl @Inject constructor(
910
private val savedListDataSource: SavedListDataSource,
1011
) : SavedListRepository {
11-
override suspend fun getSavedList(userId: Int): Result<List<SavedListEntity>> = runCatching {
12-
savedListDataSource.getSavedList(userId).data.map { it.toEntity() }
12+
override suspend fun getSavedList(userId: Int): Result<SavedListPostEntity> = runCatching {
13+
savedListDataSource.getSavedList(userId).data.toEntity()
1314
}
1415
}

app/src/main/java/com/paw/key/data/service/LikeService.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import retrofit2.http.Path
88

99
interface LikeService {
1010

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

17-
@DELETE("/api/v1/likes/{courseId}")
17+
@DELETE("/api/v1/likes/{postId}")
1818
suspend fun unlikeCourse(
1919
@Header("X-USER-ID") userId: Int,
20-
@Path("courseId") courseId: Int
20+
@Path("postId") postId: Int
2121
): BaseResponse<Unit>
2222
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.paw.key.data.service
22

33
import com.paw.key.data.dto.response.BaseResponse
4-
import com.paw.key.data.dto.response.SavedListResponseDto
4+
import com.paw.key.data.dto.response.SavedListResponseDataDto
55
import retrofit2.http.GET
66
import retrofit2.http.Header
77

88
interface SavedListService {
99
@GET("users/me/likes")
1010
suspend fun getSavedList(
1111
@Header("X-USER-ID") userId: Int
12-
): BaseResponse<List<SavedListResponseDto>>
12+
): BaseResponse<SavedListResponseDataDto>
1313
}
Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
package com.paw.key.domain.model.entity.savedlist
22

3+
4+
data class SavedListPostEntity(
5+
val posts: List<SavedListEntity>
6+
)
37
data class SavedListEntity(
4-
val postId: Long,
8+
val postId: Int,
59
val createdAt: String,
610
val isLiked: Boolean,
711
val title: String,
812
val representativeImageUrl: String,
9-
val writer: List<SavedWriterEntity>,
13+
val routeId: Int,
14+
val writer: SavedWriterEntity,
1015
val descriptionTags: List<String>
1116
)
1217
data class SavedWriterEntity(
13-
val userId: Long,
18+
val userId: Int,
1419
val petName: String,
1520
val petProfileImageUrl: String
1621
)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.paw.key.domain.repository
22

33
interface LikeRepository {
4-
suspend fun likeCourse(userId: Int, courseId: Int): Result<Unit>
5-
suspend fun unlikeCourse(userId: Int, courseId: Int): Result<Unit>
4+
suspend fun likeCourse(userId: Int, postId: Int): Result<Unit>
5+
suspend fun unlikeCourse(userId: Int, postId: Int): Result<Unit>
66
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.paw.key.domain.repository
22

33
import com.paw.key.domain.model.entity.savedlist.SavedListEntity
4+
import com.paw.key.domain.model.entity.savedlist.SavedListPostEntity
45

56
interface SavedListRepository {
6-
suspend fun getSavedList(userId: Int): Result<List<SavedListEntity>>
7+
suspend fun getSavedList(userId: Int): Result<SavedListPostEntity>
78
}

app/src/main/java/com/paw/key/presentation/ui/course/entire/tab/map/List/viewmodel/TapListViewModel.kt

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
55
import com.paw.key.data.dto.request.list.PostsListRequestDto
66
import com.paw.key.data.dto.request.list.TraitList
7+
import com.paw.key.domain.repository.LikeRepository
78
import com.paw.key.domain.repository.filter.FilterOptionRepository
89
import com.paw.key.domain.repository.list.PostsListRepository
910
import com.paw.key.presentation.ui.course.entire.tab.map.List.state.TapListContract
@@ -18,7 +19,8 @@ import javax.inject.Inject
1819
@HiltViewModel
1920
class TapListViewModel @Inject constructor(
2021
private val filterOptionRepository: FilterOptionRepository,
21-
private val postsListRepository: PostsListRepository
22+
private val postsListRepository: PostsListRepository,
23+
private val likeRepository: LikeRepository
2224
) : ViewModel() {
2325

2426
private val _state = MutableStateFlow(TapListContract.TapListState())
@@ -122,6 +124,13 @@ class TapListViewModel @Inject constructor(
122124
}
123125
}
124126
}
127+
128+
fun toggleLike(userId: Int, postId: Int) {
129+
viewModelScope.launch {
130+
likeRepository.likeCourse(userId = 2, postId = 6)
131+
}
132+
}
133+
125134
fun updateMood(option: String) {
126135
_state.update {
127136
it.copy(
@@ -315,19 +324,19 @@ class TapListViewModel @Inject constructor(
315324
return isAllOptionsSelected()
316325
}
317326

318-
fun toggleLike(postId: Int, isLiked: Boolean) {
319-
viewModelScope.launch {
320-
_state.update { state ->
321-
val updatedPosts = state.postsResult?.posts?.map {
322-
if (it.postId == postId) it.copy(isLike = isLiked) else it
323-
} ?: emptyList()
324-
325-
val updatedPostsResult = state.postsResult?.copy(posts = updatedPosts)
326-
327-
state.copy(
328-
postsResult = updatedPostsResult
329-
)
330-
}
331-
}
332-
}
327+
// fun toggleLike(postId: Int, isLiked: Boolean) {
328+
// viewModelScope.launch {
329+
// _state.update { state ->
330+
// val updatedPosts = state.postsResult?.posts?.map {
331+
// if (it.postId == postId) it.copy(isLike = isLiked) else it
332+
// } ?: emptyList()
333+
//
334+
// val updatedPostsResult = state.postsResult?.copy(posts = updatedPosts)
335+
//
336+
// state.copy(
337+
// postsResult = updatedPostsResult
338+
// )
339+
// }
340+
// }
341+
// }
333342
}

app/src/main/java/com/paw/key/presentation/ui/mypage/ArchivedCourseDetailScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fun ArchivedCourseDetailScreen(
115115
petName = petName,
116116
date = date,
117117
location = location,
118-
isLike = isLike,
118+
onClickLike = {},
119119
content = content,
120120
petProfileImage = petProfileImage,
121121
routeMapImageUrl = routeMapImageUrl,

0 commit comments

Comments
 (0)