Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor#186] 탐색 기본 뷰 / 리팩토링 #190

Closed
wants to merge 8 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ import com.terning.core.designsystem.theme.Grey400
import com.terning.core.designsystem.theme.TerningMain
import com.terning.core.designsystem.theme.TerningTheme


/**
* 검색창 텍스트 필드 컴포저블입니다.
*
* @param text 텍스트 필드에 표시될 텍스트입니다.
* @param onValueChange 텍스트 필드의 값이 변경될 때 호출되는 콜백 함수입니다.
* @param modifier 텍스트 필드에 적용될 Modifier입니다.
* @param hint 텍스트 필드에 아무것도 입력하지 않았을 때 표시될 힌트 텍스트입니다.
* @param leftIcon 텍스트 필드의 왼쪽에 표시될 아이콘의 리소스 ID입니다.
* @param enabled 텍스트 필드가 활성화되어 있는지 여부를 나타냅니다.
* @param readOnly 텍스트 필드가 읽기 전용인지 여부를 나타냅니다.
* @param onSearchAction 사용자가 키보드에서 검색을 실행할 때 호출되는 콜백 함수입니다.
*/
@Composable
fun SearchTextField(
text: String = "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package com.terning.data.datasource
import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.SearchRequestDto
import com.terning.data.dto.response.SearchResultResponseDto
import com.terning.data.dto.response.SearchScrapsResponseDto
import com.terning.data.dto.response.SearchViewsResponseDto
import com.terning.data.dto.response.SearchAnnouncementResponseDto

interface SearchDataSource {
suspend fun getSearch(request: SearchRequestDto): BaseResponse<SearchResultResponseDto>
suspend fun getSearchViews(): BaseResponse<SearchViewsResponseDto>
suspend fun getSearchScraps(): BaseResponse<SearchScrapsResponseDto>
suspend fun getSearchViews(): BaseResponse<SearchAnnouncementResponseDto>
suspend fun getSearchScraps(): BaseResponse<SearchAnnouncementResponseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import com.terning.data.datasource.SearchDataSource
import com.terning.data.dto.BaseResponse
import com.terning.data.dto.request.SearchRequestDto
import com.terning.data.dto.response.SearchResultResponseDto
import com.terning.data.dto.response.SearchScrapsResponseDto
import com.terning.data.dto.response.SearchViewsResponseDto
import com.terning.data.dto.response.SearchAnnouncementResponseDto
import com.terning.data.service.SearchService
import javax.inject.Inject

Expand All @@ -22,9 +21,9 @@ class SearchDataSourceImpl @Inject constructor(
request.size
)

override suspend fun getSearchViews(): BaseResponse<SearchViewsResponseDto> =
override suspend fun getSearchViews(): BaseResponse<SearchAnnouncementResponseDto> =
searchService.getSearchViewsList()

override suspend fun getSearchScraps(): BaseResponse<SearchScrapsResponseDto> =
override suspend fun getSearchScraps(): BaseResponse<SearchAnnouncementResponseDto> =
searchService.getSearchScrapsList()
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.InternshipAnnouncementModel
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable


@Serializable
data class SearchScrapsResponseDto(
data class SearchAnnouncementResponseDto(
@SerialName("announcements")
val announcements: List<ScrapsAnnouncementDto>,
) {
Expand All @@ -19,14 +18,4 @@ data class SearchScrapsResponseDto(
@SerialName("title")
val title: String,
)

fun toSearchScrapsEntity(): List<InternshipAnnouncementModel> {
return announcements.map {
InternshipAnnouncementModel(
announcementId = it.internshipAnnouncementId,
companyImage = it.companyImage,
title = it.title,
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.terning.data.dto.response

import com.terning.domain.entity.response.SearchResultModel
import com.terning.domain.entity.search.SearchResult
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 지금 사용되는 내용이 아니라면 삭제해주면 좋을 것 같아요!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

섬세하시닷!~

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

Expand Down Expand Up @@ -34,20 +34,4 @@ data class SearchResultResponseDto(
@SerialName("deadline")
val deadline: String,
)

fun toSearchResultEntity(): List<SearchResultModel> {
return announcements.map {
SearchResultModel(
internshipAnnouncementId = it.internshipAnnouncementId,
title = it.title,
dDay = it.dDay,
workingPeriod = it.workingPeriod,
companyImage = it.companyImage,
scrapId = it.scrapId,
deadline = it.deadline,
startYearMonth = it.startYearMonth,
color = it.color
)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.terning.data.mapper.search

import com.terning.data.dto.response.SearchAnnouncementResponseDto
import com.terning.domain.entity.search.SearchPopularAnnouncement

fun SearchAnnouncementResponseDto.toSearchPopularAnnouncementList(): List<SearchPopularAnnouncement> {
return announcements.map {
SearchPopularAnnouncement(
announcementId = it.internshipAnnouncementId,
companyImage = it.companyImage,
title = it.title,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.terning.data.mapper.search

import com.terning.data.dto.response.SearchResultResponseDto
import com.terning.domain.entity.search.SearchResult


fun SearchResultResponseDto.toSearchResultList(): List<SearchResult> {
return announcements.map {
SearchResult(
internshipAnnouncementId = it.internshipAnnouncementId,
title = it.title,
dDay = it.dDay,
workingPeriod = it.workingPeriod,
companyImage = it.companyImage,
scrapId = it.scrapId,
deadline = it.deadline,
startYearMonth = it.startYearMonth,
color = it.color
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package com.terning.data.repositoryimpl

import com.terning.data.datasource.SearchDataSource
import com.terning.data.dto.request.SearchRequestDto
import com.terning.domain.entity.response.InternshipAnnouncementModel
import com.terning.domain.entity.response.SearchResultModel
import com.terning.data.mapper.search.toSearchPopularAnnouncementList
import com.terning.data.mapper.search.toSearchResultList
import com.terning.domain.entity.search.SearchPopularAnnouncement
import com.terning.domain.entity.search.SearchResult
import com.terning.domain.repository.SearchRepository
import javax.inject.Inject

Expand All @@ -15,7 +17,7 @@ class SearchRepositoryImpl @Inject constructor(
sortBy: String,
page: Int,
size: Int,
): Result<List<SearchResultModel>> {
): Result<List<SearchResult>> {
return runCatching {
searchDataSource.getSearch(
SearchRequestDto(
Expand All @@ -24,17 +26,17 @@ class SearchRepositoryImpl @Inject constructor(
page = page,
size = size
)
).result.toSearchResultEntity()
).result.toSearchResultList()
}
}

override suspend fun getSearchViewsList(): Result<List<InternshipAnnouncementModel>> =
override suspend fun getSearchViewsList(): Result<List<SearchPopularAnnouncement>> =
runCatching {
searchDataSource.getSearchViews().result.toSearchViewsEntity()
searchDataSource.getSearchViews().result.toSearchPopularAnnouncementList()
}

override suspend fun getSearchScrapsList(): Result<List<InternshipAnnouncementModel>> =
override suspend fun getSearchScrapsList(): Result<List<SearchPopularAnnouncement>> =
runCatching {
searchDataSource.getSearchScraps().result.toSearchScrapsEntity()
searchDataSource.getSearchScraps().result.toSearchPopularAnnouncementList()
}
}
7 changes: 3 additions & 4 deletions data/src/main/java/com/terning/data/service/SearchService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.terning.data.service

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.response.SearchResultResponseDto
import com.terning.data.dto.response.SearchScrapsResponseDto
import com.terning.data.dto.response.SearchViewsResponseDto
import com.terning.data.dto.response.SearchAnnouncementResponseDto
import retrofit2.http.GET
import retrofit2.http.Query

Expand All @@ -17,8 +16,8 @@ interface SearchService {
): BaseResponse<SearchResultResponseDto>

@GET("api/v1/search/views")
suspend fun getSearchViewsList(): BaseResponse<SearchViewsResponseDto>
suspend fun getSearchViewsList(): BaseResponse<SearchAnnouncementResponseDto>

@GET("api/v1/search/scraps")
suspend fun getSearchScrapsList(): BaseResponse<SearchScrapsResponseDto>
suspend fun getSearchScrapsList(): BaseResponse<SearchAnnouncementResponseDto>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.terning.domain.entity.response
package com.terning.domain.entity.search

data class InternshipAnnouncementModel(
data class SearchPopularAnnouncement(
val title: String,
val companyImage: String,
val announcementId: Long,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.terning.domain.entity.response
package com.terning.domain.entity.search

data class SearchResultModel(
data class SearchResult(
val internshipAnnouncementId: Long,
val title: String,
val dDay: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.terning.domain.repository

import com.terning.domain.entity.response.SearchResultModel
import com.terning.domain.entity.response.InternshipAnnouncementModel
import com.terning.domain.entity.search.SearchResult
import com.terning.domain.entity.search.SearchPopularAnnouncement

interface SearchRepository {
suspend fun getSearchList(
query: String,
sortBy: String,
page: Int,
size: Int,
): Result<List<SearchResultModel>>
suspend fun getSearchViewsList(): Result<List<InternshipAnnouncementModel>>
suspend fun getSearchScrapsList(): Result<List<InternshipAnnouncementModel>>
): Result<List<SearchResult>>
suspend fun getSearchViewsList(): Result<List<SearchPopularAnnouncement>>
suspend fun getSearchScrapsList(): Result<List<SearchPopularAnnouncement>>
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NavHostController는 SearchRoute까지 호이스팅하거나 유빈이 코드처럼 아예 Navigation 파일로 호이스팅하는게 좋을 것 같아요!!

Copy link
Contributor Author

@arinming arinming Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네엡 감사합니당~!!! 바로 수정해볼게욤

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.terning.core.designsystem.theme.Grey100
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.core.extension.noRippleClickable
import com.terning.core.state.UiState
import com.terning.domain.entity.response.InternshipAnnouncementModel
import com.terning.domain.entity.search.SearchPopularAnnouncement
import com.terning.feature.R
import com.terning.feature.search.search.component.ImageSlider
import com.terning.feature.search.search.component.InternListType
Expand Down Expand Up @@ -62,12 +62,12 @@ fun SearchRoute(
}

val searchViewsList = when (viewState.searchViewsList) {
is UiState.Success -> (viewState.searchViewsList as UiState.Success<List<InternshipAnnouncementModel>>).data
is UiState.Success -> (viewState.searchViewsList as UiState.Success<List<SearchPopularAnnouncement>>).data
else -> emptyList()
}

val searchScrapsList = when (scrapState.searchScrapsList) {
is UiState.Success -> (scrapState.searchScrapsList as UiState.Success<List<InternshipAnnouncementModel>>).data
is UiState.Success -> (scrapState.searchScrapsList as UiState.Success<List<SearchPopularAnnouncement>>).data
else -> emptyList()
}

Expand All @@ -82,8 +82,8 @@ fun SearchRoute(
fun SearchScreen(
modifier: Modifier = Modifier,
navController: NavHostController,
searchViewsList: List<InternshipAnnouncementModel>,
searchScrapsList: List<InternshipAnnouncementModel>,
searchViewsList: List<SearchPopularAnnouncement>,
searchScrapsList: List<SearchPopularAnnouncement>,
) {
val images = listOf(
R.drawable.img_ad_1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import com.terning.core.designsystem.theme.Grey400
import com.terning.core.designsystem.theme.TerningTheme
import com.terning.domain.entity.response.InternshipAnnouncementModel
import com.terning.domain.entity.search.SearchPopularAnnouncement
import com.terning.feature.R

@Composable
fun SearchInternList(
type: InternListType,
searchScrapsList: List<InternshipAnnouncementModel>?,
searchViewsList: List<InternshipAnnouncementModel>?,
searchScrapsList: List<SearchPopularAnnouncement>?,
searchViewsList: List<SearchPopularAnnouncement>?,
navController: NavHostController,
) {
Column(modifier = Modifier.padding(horizontal = 24.dp)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.terning.feature.search.search.model

import com.terning.domain.entity.response.InternshipAnnouncementModel
import com.terning.domain.entity.search.SearchPopularAnnouncement
import com.terning.core.state.UiState

data class SearchScrapsListState(
var searchScrapsList: UiState<List<InternshipAnnouncementModel>> = UiState.Loading,
var searchScrapsList: UiState<List<SearchPopularAnnouncement>> = UiState.Loading,
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.terning.feature.search.search.model

import com.terning.domain.entity.response.InternshipAnnouncementModel
import com.terning.domain.entity.search.SearchPopularAnnouncement
import com.terning.core.state.UiState

data class SearchViewsListState(
var searchViewsList: UiState<List<InternshipAnnouncementModel>> = UiState.Loading,
var searchViewsList: UiState<List<SearchPopularAnnouncement>> = UiState.Loading,
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.ui.graphics.Color
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.terning.domain.entity.CalendarScrapRequest
import com.terning.domain.entity.response.SearchResultModel
import com.terning.domain.entity.search.SearchResult
import com.terning.domain.repository.ScrapRepository
import com.terning.domain.repository.SearchRepository
import com.terning.feature.R
Expand Down Expand Up @@ -37,8 +37,8 @@ class SearchProcessViewModel @Inject constructor(
MutableStateFlow(SearchResultState())
val searchListState: StateFlow<SearchResultState> = _searchListState.asStateFlow()

private val _internSearchResultData = MutableStateFlow<List<SearchResultModel>>(emptyList())
val internSearchResultData: StateFlow<List<SearchResultModel>> =
private val _internSearchResultData = MutableStateFlow<List<SearchResult>>(emptyList())
val internSearchResultData: StateFlow<List<SearchResult>> =
_internSearchResultData.asStateFlow()

private val _dialogState: MutableStateFlow<SearchDialogState> =
Expand Down
Loading
Loading