Skip to content

Commit

Permalink
🧩 :: 취업률 배너 cell 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
ray3238 committed Oct 25, 2024
1 parent 17f72a1 commit b3268a6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
24 changes: 18 additions & 6 deletions Projects/Presentation/Sources/Home/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,16 +168,28 @@ public final class HomeViewController: BaseViewController<HomeViewModel> {
}
.disposed(by: disposeBag)

output.bannerList
.filter { !$0.isEmpty }
.do(onNext: {
self.bannerView.setPageControl(count: $0.count)
let totalPassBannerModel = output.totalPassStudentInfo.value

let combinedBanners = output.bannerList
.map { banners in
return [totalPassBannerModel] + banners
}

combinedBanners
.do(onNext: { banners in
self.bannerView.setPageControl(count: banners.count)
})
.bind(to: bannerView.collectionView.rx.items(
cellIdentifier: BannerCollectionViewCell.identifier,
cellType: BannerCollectionViewCell.self
)) { _, element, cell in
cell.adapt(model: element)
)) { index, element, cell in
if index == 0 {
cell.totalPassAdapt(model: output.totalPassStudentInfo.value)
} else {
if let fetchBanner = element as? FetchBannerEntity {
cell.adapt(model: fetchBanner)
}
}
}
.disposed(by: disposeBag)
}
Expand Down
21 changes: 19 additions & 2 deletions Projects/Presentation/Sources/Home/HomeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ public final class HomeViewModel: BaseViewModel, Stepper {
private let fetchStudentInfoUseCase: FetchStudentInfoUseCase
private let fetchApplicationUseCase: FetchApplicationUseCase
private let fetchBannerListUseCase: FetchBannerListUseCase
private let fetchTotalPassStudentUseCase: FetchTotalPassStudentUseCase

private var touchedPopcatCount = 0

init(
fetchStudentInfoUseCase: FetchStudentInfoUseCase,
fetchApplicationUseCase: FetchApplicationUseCase,
fetchBannerListUseCase: FetchBannerListUseCase
fetchBannerListUseCase: FetchBannerListUseCase,
fetchTotalPassStudentUseCase: FetchTotalPassStudentUseCase
) {
self.fetchStudentInfoUseCase = fetchStudentInfoUseCase
self.fetchApplicationUseCase = fetchApplicationUseCase
self.fetchBannerListUseCase = fetchBannerListUseCase
self.fetchTotalPassStudentUseCase = fetchTotalPassStudentUseCase
}

public struct Input {
Expand All @@ -40,12 +43,18 @@ public final class HomeViewModel: BaseViewModel, Stepper {
let studentInfo: PublishRelay<StudentInfoEntity>
let applicationList: PublishRelay<[ApplicationEntity]>
let bannerList: BehaviorRelay<[FetchBannerEntity]>
let totalPassStudentInfo: BehaviorRelay<TotalPassStudentEntity>
}

public func transform(_ input: Input) -> Output {
let studentInfo = PublishRelay<StudentInfoEntity>()
let applicationList = PublishRelay<[ApplicationEntity]>()
let bannerList = BehaviorRelay<[FetchBannerEntity]>(value: [])
let totalPassStudentInfo = BehaviorRelay<TotalPassStudentEntity>(value: TotalPassStudentEntity.init(
totalStudentCount: 0,
passedCount: 0,
approvedCount: 0
))

input.viewAppear.asObservable()
.flatMap { [self] in
Expand Down Expand Up @@ -94,6 +103,13 @@ public final class HomeViewModel: BaseViewModel, Stepper {
.bind(to: steps)
.disposed(by: disposeBag)

input.viewAppear.asObservable()
.flatMap { [self] in
fetchTotalPassStudentUseCase.execute()
}
.bind(to: totalPassStudentInfo)
.disposed(by: disposeBag)

input.viewAppear.asObservable()
.flatMap { [self] in
fetchBannerListUseCase.execute()
Expand Down Expand Up @@ -146,7 +162,8 @@ public final class HomeViewModel: BaseViewModel, Stepper {
return Output(
studentInfo: studentInfo,
applicationList: applicationList,
bannerList: bannerList
bannerList: bannerList,
totalPassStudentInfo: totalPassStudentInfo
)
}
}

0 comments on commit b3268a6

Please sign in to comment.