Skip to content

Commit

Permalink
Merge branch 'develop' into feature/onboarding-#1
Browse files Browse the repository at this point in the history
  • Loading branch information
huiwoo-jo authored Mar 28, 2024
2 parents 6bd8372 + a90b7c1 commit 96bff96
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dongyang.android.youdongknowme.data.repository

import com.dongyang.android.youdongknowme.data.local.SharedPreference
import com.dongyang.android.youdongknowme.data.remote.entity.Notice
import com.dongyang.android.youdongknowme.data.remote.service.NoticeService
import com.dongyang.android.youdongknowme.standard.network.ErrorResponseHandler
Expand All @@ -9,6 +10,11 @@ import com.dongyang.android.youdongknowme.standard.network.RetrofitObject
class NoticeRepository(
private val errorResponseHandler: ErrorResponseHandler
) {

fun getUserDepartment(): String {
return SharedPreference.getDepartment()
}

suspend fun fetchUniversityNotices(page: Int): NetworkResult<List<Notice>> {
return try {
val universityNotices = RetrofitObject.getNetwork().create(NoticeService::class.java)
Expand All @@ -23,8 +29,8 @@ class NoticeRepository(

suspend fun fetchDepartmentNotices(
department: String,
page: Int)
: NetworkResult<List<Notice>> {
page: Int
): NetworkResult<List<Notice>> {
return try {
val departmentNotices = RetrofitObject.getNetwork().create(NoticeService::class.java)
.getDepartmentNotice(department, page, DEFAULT_SIZE)
Expand All @@ -37,11 +43,12 @@ class NoticeRepository(

suspend fun fetchSearchNotices(
searchWord: String,
department: String,
page: Int
): NetworkResult<List<Notice>> {
return try {
val searchNotices = RetrofitObject.getNetwork().create(NoticeService::class.java)
.getSearchNotice(searchWord, "컴퓨터소프트웨어공학과", page, DEFAULT_SIZE)
.getSearchNotice(searchWord, department, page, DEFAULT_SIZE)
NetworkResult.Success(searchNotices)
} catch (exception: Exception) {
val error = errorResponseHandler.getError(exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class NoticeViewModel(
private val _selectedTab: MutableLiveData<Event<NoticeTabType>> = MutableLiveData()
val selectedTab: LiveData<Event<NoticeTabType>> = _selectedTab

private val _myDepartment: MutableLiveData<String> = MutableLiveData()
private val myDepartment: LiveData<String> = _myDepartment

private val _universityNotices: MutableLiveData<List<Notice>?> = MutableLiveData()
val universityNotices: LiveData<List<Notice>?> = _universityNotices

Expand All @@ -38,6 +41,12 @@ class NoticeViewModel(
init {
updateSelectedTabType(NoticeTabType.SCHOOL)
fetchUniversityNotices()
getUserDepartment()
}

private fun getUserDepartment() {
val myDepartment = noticeRepository.getUserDepartment()
_myDepartment.postValue(myDepartment)
}

fun updateSelectedTabType(tabType: NoticeTabType) {
Expand Down Expand Up @@ -77,9 +86,11 @@ class NoticeViewModel(
_isLoading.postValue(true)

viewModelScope.launch {
when (val result = noticeRepository.fetchDepartmentNotices(
"컴퓨터소프트웨어공학과", departmentNoticeCurrentPage
)) {
when (val result =
noticeRepository.fetchDepartmentNotices(
myDepartment.value.toString(),
departmentNoticeCurrentPage
)) {
is NetworkResult.Success -> {
val updatedNotices = _departmentNotices.value.orEmpty() + result.data
_departmentNotices.postValue(updatedNotices)
Expand Down Expand Up @@ -119,9 +130,11 @@ class NoticeViewModel(
}

NoticeTabType.FACULTY -> viewModelScope.launch {
when (val result = noticeRepository.fetchDepartmentNotices(
"컴퓨터소프트웨어공학과", DEFAULT_REFRESH_PAGE
)) {
when (val result =
noticeRepository.fetchDepartmentNotices(
myDepartment.value.toString(),
DEFAULT_REFRESH_PAGE
)) {
is NetworkResult.Success -> {
_departmentNotices.value = result.data
_isError.postValue(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,28 @@ class SearchViewModel(
val isError: LiveData<Boolean> = _isError

private val _searchContent: MutableLiveData<String> = MutableLiveData()
val searchContent: LiveData<String> = _searchContent
private val searchContent: LiveData<String> = _searchContent

private val _searchClearVisibility: MutableLiveData<Boolean> = MutableLiveData()
val searchClearVisibility: LiveData<Boolean> get() = _searchClearVisibility

private val _myDepartment: MutableLiveData<String> = MutableLiveData()
val myDepartment: LiveData<String> = _myDepartment

private val _searchNotices: MutableLiveData<List<Notice>> = MutableLiveData()
val searchNotices: LiveData<List<Notice>> = _searchNotices

private var searchNoticeCurrentPage = 1

init {
getUserDepartment()
}

private fun getUserDepartment() {
val myDepartment = noticeRepository.getUserDepartment()
_myDepartment.postValue(myDepartment)
}

fun updateSearchContent(newContent: String) {
_searchContent.value = newContent
_searchNotices.postValue(emptyList())
Expand All @@ -54,7 +66,8 @@ class SearchViewModel(
viewModelScope.launch {
when (val result =
noticeRepository.fetchSearchNotices(
_searchContent.value.toString(),
searchContent.value.toString(),
myDepartment.value.toString(),
searchNoticeCurrentPage
)) {
is NetworkResult.Success -> {
Expand Down

0 comments on commit 96bff96

Please sign in to comment.