-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat/#79] ํ์ ๊ธฐ๋ณธ ๋ทฐ / ์กฐํ์ ๋ง์ ๊ณต๊ณ ํต์
- Loading branch information
Showing
19 changed files
with
277 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
data/src/main/java/com/terning/data/datasource/SearchDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.terning.data.datasource | ||
|
||
import com.terning.data.dto.BaseResponse | ||
import com.terning.data.dto.response.SearchViewsResponseDto | ||
|
||
interface SearchDataSource { | ||
suspend fun getSearchViews(): BaseResponse<SearchViewsResponseDto> | ||
} |
14 changes: 14 additions & 0 deletions
14
data/src/main/java/com/terning/data/datasourceimpl/SearchDataSourceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.terning.data.datasourceimpl | ||
|
||
import com.terning.data.datasource.SearchDataSource | ||
import com.terning.data.dto.BaseResponse | ||
import com.terning.data.dto.response.SearchViewsResponseDto | ||
import com.terning.data.service.SearchService | ||
import javax.inject.Inject | ||
|
||
class SearchDataSourceImpl @Inject constructor( | ||
private val searchService: SearchService, | ||
) : SearchDataSource { | ||
override suspend fun getSearchViews(): BaseResponse<SearchViewsResponseDto> = | ||
searchService.getSearchViewsList() | ||
} |
27 changes: 27 additions & 0 deletions
27
data/src/main/java/com/terning/data/dto/response/SearchViewsResponseDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.terning.data.dto.response | ||
|
||
import com.terning.domain.entity.response.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, | ||
) { | ||
|
||
|
||
fun toSearchViewsEntity(): List<InternshipAnnouncement> { | ||
return listOf( | ||
InternshipAnnouncement( | ||
announcementId = internshipAnnouncementId, | ||
companyImage = companyImage, | ||
title = title, | ||
) | ||
) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/com/terning/data/repositoryimpl/SearchViewsRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.terning.data.repositoryimpl | ||
|
||
import com.terning.data.datasource.SearchDataSource | ||
import com.terning.domain.entity.response.InternshipAnnouncement | ||
import com.terning.domain.repository.SearchRepository | ||
import javax.inject.Inject | ||
|
||
class SearchViewsRepositoryImpl @Inject constructor( | ||
private val searchDataSource: SearchDataSource, | ||
) : SearchRepository { | ||
override suspend fun getSearchViewsList(): Result<List<InternshipAnnouncement>> = | ||
runCatching { | ||
searchDataSource.getSearchViews().result.toSearchViewsEntity() | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
data/src/main/java/com/terning/data/service/SearchService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.terning.data.service | ||
|
||
import com.terning.data.dto.BaseResponse | ||
import com.terning.data.dto.response.SearchViewsResponseDto | ||
import retrofit2.http.GET | ||
|
||
interface SearchService { | ||
@GET("api/v1/search/views") | ||
suspend fun getSearchViewsList(): BaseResponse<SearchViewsResponseDto> | ||
} |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/terning/domain/entity/response/InternshipAnnouncement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.terning.domain.entity.response | ||
|
||
data class InternshipAnnouncement( | ||
val title: String, | ||
val companyImage: String, | ||
val announcementId: Long, | ||
) |
7 changes: 7 additions & 0 deletions
7
domain/src/main/java/com/terning/domain/repository/SearchRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.terning.domain.repository | ||
|
||
import com.terning.domain.entity.response.InternshipAnnouncement | ||
|
||
interface SearchRepository { | ||
suspend fun getSearchViewsList(): Result<List<InternshipAnnouncement>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
feature/src/main/java/com/terning/feature/search/search/SearchViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.terning.feature.search.search | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.terning.core.state.UiState | ||
import com.terning.domain.repository.SearchRepository | ||
import com.terning.feature.R | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableSharedFlow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asSharedFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SearchViewModel @Inject constructor( | ||
private val searchRepository: SearchRepository, | ||
) : ViewModel() { | ||
private val _state: MutableStateFlow<SearchViewsState> = MutableStateFlow(SearchViewsState()) | ||
val state: StateFlow<SearchViewsState> = _state.asStateFlow() | ||
|
||
private val _sideEffect: MutableSharedFlow<SearchViewsSideEffect> = MutableSharedFlow() | ||
val sideEffect = _sideEffect.asSharedFlow() | ||
|
||
init { | ||
getSearchViews() | ||
} | ||
|
||
fun getSearchViews() { | ||
viewModelScope.launch { | ||
searchRepository.getSearchViewsList().onSuccess { searchViewsList -> | ||
_state.value = _state.value.copy( | ||
searchViewsList = UiState.Success(searchViewsList) | ||
) | ||
}.onFailure { | ||
_sideEffect.emit(SearchViewsSideEffect.Toast(R.string.server_failure)) | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
feature/src/main/java/com/terning/feature/search/search/SearchViewsSideEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 SearchViewsSideEffect { | ||
data class Toast(@StringRes val message: Int) : SearchViewsSideEffect() | ||
} |
8 changes: 8 additions & 0 deletions
8
feature/src/main/java/com/terning/feature/search/search/SearchViewsState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.terning.feature.search.search | ||
|
||
import com.terning.core.state.UiState | ||
import com.terning.domain.entity.response.InternshipAnnouncement | ||
|
||
data class SearchViewsState( | ||
var searchViewsList: UiState<List<InternshipAnnouncement>> = UiState.Loading, | ||
) |
Oops, something went wrong.