Skip to content

Commit

Permalink
[MERGE] #85 -> develop
Browse files Browse the repository at this point in the history
[FEAT/#85] ํƒ์ƒ‰ ๋ทฐ / ์Šคํฌ๋žฉ ๋งŽ์€ ๊ณต๊ณ  ํ†ต์‹ 
  • Loading branch information
arinming authored Jul 17, 2024
2 parents 923dc21 + 710d049 commit 76334ae
Show file tree
Hide file tree
Showing 21 changed files with 180 additions and 81 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/terning/point/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class DataSourceModule {

@Binds
@Singleton
abstract fun bindSearchViewsDataSource(searchViewsDataSourceImpl: SearchDataSourceImpl):
abstract fun bindSearchViewsDataSource(searchDataSourceImpl: SearchDataSourceImpl):
SearchDataSource

@Binds
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/terning/point/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.terning.point.di

import com.terning.data.repositoryimpl.AuthRepositoryImpl
import com.terning.data.repositoryimpl.SearchRepositoryImpl
import com.terning.data.repositoryimpl.CalendarRepositoryImpl
import com.terning.data.repositoryimpl.SearchViewsRepositoryImpl
import com.terning.data.repositoryimpl.TokenReissueRepositoryImpl
import com.terning.data.repositoryimpl.TokenRepositoryImpl
import com.terning.domain.repository.AuthRepository
Expand Down Expand Up @@ -34,7 +34,7 @@ abstract class RepositoryModule {

@Binds
@Singleton
abstract fun bindSearchViewsRepository(searchViewsRepositoryImpl: SearchViewsRepositoryImpl): SearchRepository
abstract fun bindSearchRepository(searchRepositoryImpl: SearchRepositoryImpl): SearchRepository

@Binds
@Singleton
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/terning/point/di/RetrofitModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,4 @@ object RetrofitModule {
.client(client)
.addConverterFactory(factory)
.build()

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.terning.data.datasource

import com.terning.data.dto.BaseResponse
import com.terning.data.dto.response.SearchScrapsResponseDto
import com.terning.data.dto.response.SearchViewsResponseDto

interface SearchDataSource {
suspend fun getSearchViews(): BaseResponse<SearchViewsResponseDto>
suspend fun getSearchScraps(): BaseResponse<SearchScrapsResponseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.terning.data.datasourceimpl

import com.terning.data.datasource.SearchDataSource
import com.terning.data.dto.BaseResponse
import com.terning.data.dto.response.SearchScrapsResponseDto
import com.terning.data.dto.response.SearchViewsResponseDto
import com.terning.data.service.SearchService
import javax.inject.Inject
Expand All @@ -11,4 +12,7 @@ class SearchDataSourceImpl @Inject constructor(
) : SearchDataSource {
override suspend fun getSearchViews(): BaseResponse<SearchViewsResponseDto> =
searchService.getSearchViewsList()

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

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


@Serializable
data class SearchScrapsResponseDto(
@SerialName("announcements")
val announcements: List<ScrapsAnnouncementDto>,
) {
@Serializable
data class ScrapsAnnouncementDto(
@SerialName("internshipAnnouncementId")
val internshipAnnouncementId: Long,
@SerialName("companyImage")
val companyImage: String,
@SerialName("title")
val title: String,
)

fun toSearchScrapsEntity(): List<InternshipAnnouncement> {
return announcements.map {
InternshipAnnouncement(
announcementId = it.internshipAnnouncementId,
companyImage = it.companyImage,
title = it.title,
)
}
}
}


Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package com.terning.data.dto.response

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

@Serializable
data class SearchViewsResponseDto(
@SerialName("internshipAnnouncementId")
val internshipAnnouncementId: Long,
@SerialName("companyImage")
val companyImage: String,
@SerialName("title")
val title: String,
@SerialName("announcements")
val announcements: List<ViewsAnnouncementDto>,
) {

@Serializable
data class ViewsAnnouncementDto(
@SerialName("internshipAnnouncementId")
val internshipAnnouncementId: Long,
@SerialName("companyImage")
val companyImage: String,
@SerialName("title")
val title: String,
)

fun toSearchViewsEntity(): List<InternshipAnnouncement> {
return listOf(
return announcements.map {
InternshipAnnouncement(
announcementId = internshipAnnouncementId,
companyImage = companyImage,
title = title,
announcementId = it.internshipAnnouncementId,
companyImage = it.companyImage,
title = it.title,
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.terning.data.repositoryimpl

import InternshipAnnouncement
import com.terning.data.datasource.SearchDataSource
import com.terning.domain.repository.SearchRepository
import javax.inject.Inject

class SearchRepositoryImpl @Inject constructor(
private val searchDataSource: SearchDataSource,
) : SearchRepository {
override suspend fun getSearchViewsList(): Result<List<InternshipAnnouncement>> = runCatching {
searchDataSource.getSearchViews().result.toSearchViewsEntity()
}

override suspend fun getSearchScrapsList(): Result<List<InternshipAnnouncement>> = runCatching {
searchDataSource.getSearchScraps().result.toSearchScrapsEntity()
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ class TokenRepositoryImpl @Inject constructor(
override fun clearInfo() {
terningDataStore.clearInfo()
}

}
4 changes: 4 additions & 0 deletions data/src/main/java/com/terning/data/service/SearchService.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.terning.data.service

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

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

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

data class InternshipAnnouncement(
val title: String,
val companyImage: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.terning.domain.repository

import com.terning.domain.entity.response.InternshipAnnouncement
import InternshipAnnouncement

interface SearchRepository {
suspend fun getSearchViewsList(): Result<List<InternshipAnnouncement>>
suspend fun getSearchScrapsList(): Result<List<InternshipAnnouncement>>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.terning.feature.search.search

import InternshipAnnouncement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -27,7 +28,6 @@ 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.InternshipAnnouncement
import com.terning.feature.R
import com.terning.feature.search.search.component.ImageSlider
import com.terning.feature.search.search.component.InternListType
Expand All @@ -41,31 +41,34 @@ fun SearchRoute(
) {
val lifecycleOwner = LocalLifecycleOwner.current

val state by viewModel.state.collectAsStateWithLifecycle(lifecycleOwner = lifecycleOwner)
val viewState by viewModel.viewState.collectAsStateWithLifecycle(lifecycleOwner = lifecycleOwner)
val scrapState by viewModel.scrapState.collectAsStateWithLifecycle(lifecycleOwner = lifecycleOwner)

LaunchedEffect(key1 = true) {
viewModel.getSearchViews()
viewModel.getSearchScraps()
}

LaunchedEffect(viewModel.sideEffect, lifecycleOwner) {
viewModel.sideEffect.flowWithLifecycle(lifecycle = lifecycleOwner.lifecycle)
.collect { sideEffect ->
when (sideEffect) {
is SearchViewsSideEffect.Toast -> {
is SearchSideEffect.Toast -> {
sideEffect.message
}
}
}
}

when (state.searchViewsList) {
when (viewState.searchViewsList) {
is UiState.Loading -> {}
is UiState.Empty -> {}
is UiState.Failure -> {}
is UiState.Success -> {
SearchScreen(
navController = navController,
searchViewsList = (state.searchViewsList as UiState.Success<List<InternshipAnnouncement>>).data
searchViewsList = (viewState.searchViewsList as UiState.Success<List<InternshipAnnouncement>>).data,
searchScrapsList = (scrapState.searchScrapsList as UiState.Success<List<InternshipAnnouncement>>).data
)
}

Expand All @@ -77,6 +80,7 @@ fun SearchScreen(
modifier: Modifier = Modifier,
navController: NavHostController,
searchViewsList: List<InternshipAnnouncement>,
searchScrapsList: List<InternshipAnnouncement>,
) {
val images = listOf(
R.drawable.ic_nav_search,
Expand Down Expand Up @@ -132,6 +136,7 @@ fun SearchScreen(
SearchInternList(
type = InternListType.VIEW,
searchViewsList = searchViewsList,
searchScrapsList = searchScrapsList,
navController = navController
)
HorizontalDivider(
Expand All @@ -142,6 +147,7 @@ fun SearchScreen(
SearchInternList(
type = InternListType.SCRAP,
searchViewsList = searchViewsList,
searchScrapsList = searchScrapsList,
navController = navController
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.terning.feature.search.search

import androidx.annotation.StringRes

sealed class SearchSideEffect {
data class Toast(@StringRes val message: Int) : SearchSideEffect()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.terning.feature.search.search

import InternshipAnnouncement
import com.terning.core.state.UiState

data class SearchState(
var searchViewsList: UiState<List<InternshipAnnouncement>> = UiState.Loading,
var searchScrapsList: UiState<List<InternshipAnnouncement>> = UiState.Loading,
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,35 @@ import javax.inject.Inject
class SearchViewModel @Inject constructor(
private val searchRepository: SearchRepository,
) : ViewModel() {
private val _state: MutableStateFlow<SearchViewsState> = MutableStateFlow(SearchViewsState())
val state: StateFlow<SearchViewsState> = _state.asStateFlow()
private val _viewState: MutableStateFlow<SearchState> = MutableStateFlow(SearchState())
val viewState: StateFlow<SearchState> = _viewState.asStateFlow()

private val _sideEffect: MutableSharedFlow<SearchViewsSideEffect> = MutableSharedFlow()
val sideEffect = _sideEffect.asSharedFlow()
private val _scrapState: MutableStateFlow<SearchState> = MutableStateFlow(SearchState())
val scrapState: StateFlow<SearchState> = _scrapState.asStateFlow()

init {
getSearchViews()
}
private val _sideEffect: MutableSharedFlow<SearchSideEffect> = MutableSharedFlow()
val sideEffect = _sideEffect.asSharedFlow()

fun getSearchViews() {
viewModelScope.launch {
searchRepository.getSearchViewsList().onSuccess { searchViewsList ->
_state.value = _state.value.copy(
_viewState.value = _viewState.value.copy(
searchViewsList = UiState.Success(searchViewsList)
)
}.onFailure {
_sideEffect.emit(SearchViewsSideEffect.Toast(R.string.server_failure))
_sideEffect.emit(SearchSideEffect.Toast(R.string.server_failure))
}
}
}

fun getSearchScraps() {
viewModelScope.launch {
searchRepository.getSearchScrapsList().onSuccess { searchScrapsList ->
_scrapState.value = _scrapState.value.copy(
searchScrapsList = UiState.Success(searchScrapsList)
)
}.onFailure {
_sideEffect.emit(SearchSideEffect.Toast(R.string.server_failure))
}
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.terning.feature.search.search

import InternshipAnnouncement
import com.terning.core.state.UiState
import com.terning.domain.entity.response.InternshipAnnouncement

data class SearchViewsState(
var searchViewsList: UiState<List<InternshipAnnouncement>> = UiState.Loading,
Expand Down
Loading

0 comments on commit 76334ae

Please sign in to comment.