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
7 changes: 5 additions & 2 deletions app/src/main/java/com/flint/data/api/SearchApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ interface SearchApi {
@Query("size") size: Int
) : BaseResponse<SearchBookmarkedContentsResponseDto>

@GET("/api/v1/search/contents")
@GET("/api/v1/contents/search")
suspend fun getSearchContentList(
@Query("keyword") keyword: String?
@Query("keyword") keyword: String? = null,
@Query("genre") genre: String? = null,
@Query("cursor") cursor: Int = 1,
@Query("size") size: Int = 20,
): BaseResponse<SearchContentsResponseDto>
}
20 changes: 20 additions & 0 deletions app/src/main/java/com/flint/data/api/TermsApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.flint.data.api

import com.flint.data.dto.base.BaseResponse
import com.flint.data.dto.terms.response.TermResponseDto
import com.flint.data.dto.terms.response.TermsListResponseDto
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query

interface TermsApi {
@GET("/api/v1/terms")
suspend fun getTermsList(
@Query("type") type: String? = null,
): BaseResponse<TermsListResponseDto>

@GET("/api/v1/terms/{termsId}")
suspend fun getTermsDetail(
@Path("termsId") termsId: Long,
): BaseResponse<TermResponseDto>
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/flint/data/di/ServiceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.flint.data.api.ContentApi
import com.flint.data.api.HomeApi
import com.flint.data.api.SearchApi
import com.flint.data.api.StorageApi
import com.flint.data.api.TermsApi
import com.flint.data.api.UserApi
import dagger.Module
import dagger.Provides
Expand Down Expand Up @@ -49,4 +50,8 @@ object ServiceModule {
@Provides
@Singleton
fun provideStorageApi(retrofit: Retrofit): StorageApi = retrofit.create(StorageApi::class.java)

@Provides
@Singleton
fun provideTermsApi(retrofit: Retrofit): TermsApi = retrofit.create(TermsApi::class.java)
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,24 @@ class NetworkErrorInterceptor @Inject constructor(

response
} catch (e: UnknownHostException) {
scope.launch {
networkErrorManager.emitError(NetworkError.NoInternet)
if (!chain.call().isCanceled()) {
scope.launch {
networkErrorManager.emitError(NetworkError.NoInternet)
}
}
throw e
} catch (e: SocketTimeoutException) {
scope.launch {
networkErrorManager.emitError(NetworkError.Timeout)
if (!chain.call().isCanceled()) {
scope.launch {
networkErrorManager.emitError(NetworkError.Timeout)
}
}
throw e
} catch (e: IOException) {
scope.launch {
networkErrorManager.emitError(NetworkError.UnknownError(e.message))
if (!chain.call().isCanceled()) {
scope.launch {
networkErrorManager.emitError(NetworkError.UnknownError(e.message))
}
}
throw e
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ data class SignupRequestDto(
@SerialName("nickname")
val nickname: String,
@SerialName("favoriteContentIds")
val favoriteContentIds: List<Long>,
@SerialName("subscribedOttIds")
val subscribedOttIds: List<Long>,
val favoriteContentIds: List<String>,
@SerialName("agreedTermsIds")
val agreedTermsIds: List<String>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import kotlinx.serialization.Serializable

@Serializable
data class SearchContentsResponseDto(
@SerialName("contents")
val contents: List<Content>
@SerialName("data")
val data: List<Content>,
@SerialName("meta")
val meta: Meta? = null,
) {
@Serializable
data class Content(
Expand All @@ -19,6 +21,16 @@ data class SearchContentsResponseDto(
@SerialName("posterUrl")
val posterUrl: String,
@SerialName("year")
val year: Int
val year: Int,
)
}

@Serializable
data class Meta(
@SerialName("type")
val type: String? = null,
@SerialName("returned")
val returned: Int? = null,
@SerialName("nextCursor")
val nextCursor: String? = null,
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.flint.data.dto.terms.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class TermResponseDto(
@SerialName("id")
val id: String,
@SerialName("type")
val type: String,
@SerialName("version")
val version: Int,
@SerialName("title")
val title: String,
@SerialName("content")
val content: String,
@SerialName("required")
val required: Boolean,
@SerialName("activeAt")
val activeAt: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.flint.data.dto.terms.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class TermsListResponseDto(
@SerialName("terms")
val terms: List<TermResponseDto>,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fun SignupRequestModel.toDto(): SignupRequestDto =
tempToken = tempToken,
nickname = nickname,
favoriteContentIds = favoriteContentIds,
subscribedOttIds = subscribedOttIds,
agreedTermsIds = agreedTermsIds,
)

fun SignupResponseDto.toModel(): SignupResponseModel =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import kotlinx.collections.immutable.toImmutableList

fun SearchContentsResponseDto.toModel(): SearchContentListModel {
return SearchContentListModel(
contents = this.contents.map { it.toModel() }.toImmutableList()
contents = this.data.map { it.toModel() }.toImmutableList()
)
}

Expand Down
17 changes: 17 additions & 0 deletions app/src/main/java/com/flint/domain/mapper/terms/TermsMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.flint.domain.mapper.terms

import com.flint.data.dto.terms.response.TermResponseDto
import com.flint.domain.model.terms.TermModel

fun TermResponseDto.toModel(): TermModel =
TermModel(
id = id,
type = type,
version = version,
title = title,
content = content,
required = required,
activeAt = activeAt,
)
Comment thread
coderabbitai[bot] marked this conversation as resolved.

fun List<TermResponseDto>.toModel(): List<TermModel> = map { it.toModel() }
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.flint.domain.model.auth
data class SignupRequestModel(
val tempToken: String,
val nickname: String,
val favoriteContentIds: List<Long>,
val subscribedOttIds: List<Long>,
val favoriteContentIds: List<String>,
val agreedTermsIds: List<String>,
)

data class SignupResponseModel(
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/flint/domain/model/terms/TermModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.flint.domain.model.terms

data class TermModel(
val id: String,
val type: String,
val version: Int,
val title: String,
val content: String,
val required: Boolean,
val activeAt: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ class SearchRepository @Inject constructor(
suspend fun getBookmarkedContentList(keyword: String, cursor: Int, size: Int): Result<List<ContentModel>> =
suspendRunCatching { apiService.getBookmarkedContentList(keyword, cursor, size).data.toModel() }

suspend fun getSearchContentList(keyword: String?): Result<SearchContentListModel> =
suspendRunCatching { apiService.getSearchContentList(keyword).data.toModel() }
suspend fun getSearchContentList(
keyword: String? = null,
genre: String? = null,
cursor: Int = 1,
size: Int = 20,
): Result<SearchContentListModel> =
suspendRunCatching {
apiService.getSearchContentList(
keyword = keyword,
genre = genre,
cursor = cursor,
size = size,
).data.toModel()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.flint.domain.repository

import com.flint.core.common.util.suspendRunCatching
import com.flint.data.api.TermsApi
import com.flint.domain.mapper.terms.toModel
import com.flint.domain.model.terms.TermModel
import javax.inject.Inject

class TermsRepository @Inject constructor(
private val api: TermsApi,
) {
suspend fun getTermsList(type: String? = null): Result<List<TermModel>> =
suspendRunCatching {
api.getTermsList(type).data.terms.toModel()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ fun OnboardingContentScreen(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically,
) {
items(OnboardingContentUiState.GENRES) { genre ->
val isSelected = genre in contentUiState.selectedGenres
items(OnboardingContentUiState.GENRES.keys.toList()) { genre ->
val isSelected = contentUiState.selectedGenre == genre
FlintGenreChip(
text = genre,
isSelected = isSelected,
Expand Down Expand Up @@ -375,16 +375,14 @@ private fun OnboardingContentScreenEmptyPreview() {
@Preview(showBackground = true, name = "장르 칩 인터랙티브")
@Composable
private fun OnboardingContentScreenGenreInteractivePreview() {
var selectedGenres by remember { mutableStateOf(setOf<String>()) }
var selectedGenre by remember { mutableStateOf<String?>(null) }

FlintTheme {
OnboardingContentScreen(
nickname = "안비",
contentUiState = OnboardingContentUiState(
searchResults = UiState.Success(SearchContentListModel.FakeList),
selectedGenres = selectedGenres.toList().let {
kotlinx.collections.immutable.persistentListOf(*it.toTypedArray())
},
selectedGenre = selectedGenre,
),
onBackClick = {},
onNextClick = {},
Expand All @@ -394,11 +392,7 @@ private fun OnboardingContentScreenGenreInteractivePreview() {
onContentClick = {},
onRemoveContent = {},
onGenreClick = { genre ->
selectedGenres = if (genre in selectedGenres) {
selectedGenres - genre
} else {
selectedGenres + genre
}
selectedGenre = if (selectedGenre == genre) null else genre
},
)
}
Expand Down
Loading
Loading