Skip to content

Commit bda579e

Browse files
authored
Merge pull request #155 from imflint/feat/#151-onboarding-contnet-api
[Feat] Onboarding Content API 연동
2 parents d3141c9 + 58b7170 commit bda579e

21 files changed

Lines changed: 457 additions & 118 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.flint.core.common.extension
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.remember
5+
import androidx.hilt.navigation.compose.hiltViewModel
6+
import androidx.lifecycle.ViewModel
7+
import androidx.navigation.NavBackStackEntry
8+
import androidx.navigation.NavHostController
9+
10+
/**
11+
* 공용 뷰모델을 불러오기 위한 함수
12+
* */
13+
@Composable
14+
inline fun <reified T : ViewModel> NavBackStackEntry.sharedViewModel(
15+
navController: NavHostController,
16+
): T {
17+
val navGraphRoute = destination.parent?.route ?: return hiltViewModel()
18+
val parentEntry = remember(this) {
19+
navController.getBackStackEntry(navGraphRoute)
20+
}
21+
return hiltViewModel(parentEntry)
22+
}

app/src/main/java/com/flint/core/navigation/Route.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ interface Route {
1414
val tempToken: String
1515
) : Route
1616

17+
@Serializable
18+
data class OnboardingGraph(
19+
val tempToken: String
20+
) : Route
21+
1722
@Serializable
1823
data object OnboardingContent : Route
1924

app/src/main/java/com/flint/data/api/SearchApi.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.flint.data.api
22

33
import com.flint.data.dto.base.BaseResponse
44
import com.flint.data.dto.search.SearchBookmarkedContentsResponseDto
5+
import com.flint.data.dto.search.SearchContentsResponseDto
56
import retrofit2.http.GET
67
import retrofit2.http.Query
78

@@ -12,4 +13,9 @@ interface SearchApi {
1213
@Query("cursor") cursor: Int,
1314
@Query("size") size: Int
1415
) : BaseResponse<SearchBookmarkedContentsResponseDto>
16+
17+
@GET("/api/v1/search/contents")
18+
suspend fun getSearchContentList(
19+
@Query("keyword") keyword: String?
20+
): BaseResponse<SearchContentsResponseDto>
1521
}

app/src/main/java/com/flint/data/api/UserApi.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package com.flint.data.api
22

33
import com.flint.data.dto.base.BaseResponse
4+
import com.flint.data.dto.user.response.NicknameCheckResponseDto
45
import com.flint.data.dto.user.response.BookmarkedCollectionListResponseDto
56
import com.flint.data.dto.user.response.CreatedCollectionListResponseDto
67
import com.flint.data.dto.user.response.UserKeywordsResponseDto
78
import com.flint.data.dto.user.response.UserProfileResponseDto
89
import retrofit2.http.GET
910
import retrofit2.http.Path
11+
import retrofit2.http.Query
1012

1113
interface UserApi {
1214
// 사용자 프로필 조회
@@ -16,6 +18,10 @@ interface UserApi {
1618
): BaseResponse<UserProfileResponseDto>
1719

1820
// 닉네임 중복 체크
21+
@GET("/api/v1/users/nickname/check")
22+
suspend fun checkNickname(
23+
@Query("nickname") nickname: String
24+
): BaseResponse<NicknameCheckResponseDto>
1925

2026
// 사용자 북마크 컬렉션 조회
2127
@GET("/api/v1/users/{userId}/bookmarked-collections")
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.flint.data.dto.response
2+
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
5+
6+
@Serializable
7+
data class ContentSearchResponseDto(
8+
@SerialName("data") val contents: List<ContentItemDto>,
9+
@SerialName("meta") val meta: PageMetaDto,
10+
)
11+
@Serializable
12+
data class ContentItemDto(
13+
@SerialName("contentId") val contentId: Long,
14+
@SerialName("title") val title: String,
15+
@SerialName("author") val author: String,
16+
@SerialName("posterUrl") val posterUrl: String,
17+
@SerialName("year") val year: Int,
18+
)
19+
20+
@Serializable
21+
data class PageMetaDto(
22+
@SerialName("type") val type: String,
23+
@SerialName("returned") val returned: Int,
24+
@SerialName("currentPage") val currentPage: Int,
25+
@SerialName("totalPages") val totalPages: Int,
26+
@SerialName("totalElements") val totalElements: Int,
27+
@SerialName("nextCursor") val nextCursor: String?,
28+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.flint.data.dto.search
2+
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
5+
6+
@Serializable
7+
data class SearchContentsResponseDto(
8+
@SerialName("contents")
9+
val contents: List<Content>
10+
) {
11+
@Serializable
12+
data class Content(
13+
@SerialName("id")
14+
val id: String,
15+
@SerialName("title")
16+
val title: String,
17+
@SerialName("author")
18+
val author: String,
19+
@SerialName("posterUrl")
20+
val posterUrl: String,
21+
@SerialName("year")
22+
val year: Int
23+
)
24+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.flint.data.dto.user.response
2+
3+
import kotlinx.serialization.SerialName
4+
import kotlinx.serialization.Serializable
5+
6+
@Serializable
7+
data class NicknameCheckResponseDto(
8+
@SerialName("available")
9+
val available: Boolean
10+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.flint.domain.mapper.search
2+
3+
import com.flint.data.dto.search.SearchContentsResponseDto
4+
import com.flint.domain.model.search.SearchContentItemModel
5+
import com.flint.domain.model.search.SearchContentListModel
6+
import kotlinx.collections.immutable.toImmutableList
7+
8+
fun SearchContentsResponseDto.toModel(): SearchContentListModel {
9+
return SearchContentListModel(
10+
contents = this.contents.map { it.toModel() }.toImmutableList()
11+
)
12+
}
13+
14+
private fun SearchContentsResponseDto.Content.toModel(): SearchContentItemModel{
15+
return SearchContentItemModel(
16+
id = id,
17+
title = title,
18+
author = author,
19+
posterUrl = posterUrl,
20+
year = year
21+
)
22+
}
23+
24+
25+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.flint.domain.mapper.user
2+
3+
import com.flint.data.dto.user.response.NicknameCheckResponseDto
4+
import com.flint.domain.model.user.NicknameCheckModel
5+
6+
fun NicknameCheckResponseDto.toModel(): NicknameCheckModel {
7+
return NicknameCheckModel(
8+
isAvailable = this.available
9+
)
10+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.flint.domain.model.search
2+
3+
import kotlinx.collections.immutable.ImmutableList
4+
import kotlinx.collections.immutable.persistentListOf
5+
6+
data class SearchContentItemModel(
7+
val id: String,
8+
val title: String,
9+
val author: String,
10+
val posterUrl: String,
11+
val year: Int,
12+
)
13+
14+
data class SearchContentListModel(
15+
val contents: ImmutableList<SearchContentItemModel>
16+
) {
17+
companion object {
18+
val FakeList =
19+
persistentListOf(
20+
SearchContentItemModel(
21+
id = "1",
22+
title = "은하수를 여행하는 히치하이커를 위한 안내서",
23+
author = "가스 제닝스",
24+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
25+
year = 2005,
26+
),
27+
SearchContentItemModel(
28+
id = "2",
29+
title = "인터스텔라",
30+
author = "크리스토퍼 놀란",
31+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
32+
year = 2014,
33+
),
34+
SearchContentItemModel(
35+
id = "3",
36+
title = "인셉션",
37+
author = "크리스토퍼 놀란",
38+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
39+
year = 2010,
40+
),
41+
SearchContentItemModel(
42+
id = "4",
43+
title = "기생충",
44+
author = "봉준호",
45+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
46+
year = 2019,
47+
),
48+
SearchContentItemModel(
49+
id = "5",
50+
title = "어벤져스: 엔드게임",
51+
author = "안소니 루소",
52+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
53+
year = 2019,
54+
),
55+
SearchContentItemModel(
56+
id = "6",
57+
title = "다크 나이트",
58+
author = "크리스토퍼 놀란",
59+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
60+
year = 2008,
61+
),
62+
SearchContentItemModel(
63+
id = "7",
64+
title = "오펜하이머",
65+
author = "크리스토퍼 놀란",
66+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
67+
year = 2023,
68+
),
69+
SearchContentItemModel(
70+
id = "8",
71+
title = "괴물",
72+
author = "봉준호",
73+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
74+
year = 2006,
75+
),
76+
SearchContentItemModel(
77+
id = "9",
78+
title = "설국열차",
79+
author = "봉준호",
80+
posterUrl = "https://image.tmdb.org/t/p/w500/ib6v6qUXzez1x2qIOLN7C0yJNPQ.jpg",
81+
year = 2013,
82+
),
83+
)
84+
}
85+
}

0 commit comments

Comments
 (0)