Skip to content
This repository has been archived by the owner on Nov 18, 2024. It is now read-only.

Commit

Permalink
#206 내 알림 리스트관련 UseCase 추가 개발 및 바인딩
Browse files Browse the repository at this point in the history
  • Loading branch information
dlrjswns committed Sep 25, 2024
1 parent 7e238b5 commit 3657a64
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 8 deletions.
16 changes: 16 additions & 0 deletions ShowPot/ShowPot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
70DC8F682CA1AD6B006DDAF7 /* MyAlarmListViewHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F672CA1AD6B006DDAF7 /* MyAlarmListViewHolder.swift */; };
70DC8F6A2CA1AD73006DDAF7 /* MyAlarmListCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F692CA1AD73006DDAF7 /* MyAlarmListCoordinator.swift */; };
70DC8F6D2CA1B351006DDAF7 /* AlarmCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F6C2CA1B351006DDAF7 /* AlarmCollectionViewCell.swift */; };
70DC8F712CA27E37006DDAF7 /* MyAlarmListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F702CA27E37006DDAF7 /* MyAlarmListUseCase.swift */; };
70DC8F732CA27E42006DDAF7 /* DefaultMyAlarmListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70DC8F722CA27E42006DDAF7 /* DefaultMyAlarmListUseCase.swift */; };
70F3C0DB2C663A8900786738 /* MyShowAlarmViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F3C0DA2C663A8900786738 /* MyShowAlarmViewController.swift */; };
70F3C0DD2C663A9C00786738 /* MyShowAlarmViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F3C0DC2C663A9C00786738 /* MyShowAlarmViewModel.swift */; };
70F3C0DF2C663AA900786738 /* MyShowAlarmCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70F3C0DE2C663AA900786738 /* MyShowAlarmCoordinator.swift */; };
Expand Down Expand Up @@ -432,6 +434,8 @@
70DC8F672CA1AD6B006DDAF7 /* MyAlarmListViewHolder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyAlarmListViewHolder.swift; sourceTree = "<group>"; };
70DC8F692CA1AD73006DDAF7 /* MyAlarmListCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyAlarmListCoordinator.swift; sourceTree = "<group>"; };
70DC8F6C2CA1B351006DDAF7 /* AlarmCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AlarmCollectionViewCell.swift; sourceTree = "<group>"; };
70DC8F702CA27E37006DDAF7 /* MyAlarmListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyAlarmListUseCase.swift; sourceTree = "<group>"; };
70DC8F722CA27E42006DDAF7 /* DefaultMyAlarmListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultMyAlarmListUseCase.swift; sourceTree = "<group>"; };
70F3C0DA2C663A8900786738 /* MyShowAlarmViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyShowAlarmViewController.swift; sourceTree = "<group>"; };
70F3C0DC2C663A9C00786738 /* MyShowAlarmViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyShowAlarmViewModel.swift; sourceTree = "<group>"; };
70F3C0DE2C663AA900786738 /* MyShowAlarmCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyShowAlarmCoordinator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1020,6 +1024,15 @@
path = CustomView;
sourceTree = "<group>";
};
70DC8F6F2CA27D69006DDAF7 /* MyAlarmList */ = {
isa = PBXGroup;
children = (
70DC8F702CA27E37006DDAF7 /* MyAlarmListUseCase.swift */,
70DC8F722CA27E42006DDAF7 /* DefaultMyAlarmListUseCase.swift */,
);
path = MyAlarmList;
sourceTree = "<group>";
};
70F3C0D92C663A7700786738 /* MyShowAlarm */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1471,6 +1484,7 @@
7D3E96262C061C61003A6FA9 /* UseCase */ = {
isa = PBXGroup;
children = (
70DC8F6F2CA27D69006DDAF7 /* MyAlarmList */,
70A95BD52C818AD00007836E /* MyArtist */,
70A95B972C7F27BE0007836E /* Search */,
70A95B812C7E29E80007836E /* Featured */,
Expand Down Expand Up @@ -2027,9 +2041,11 @@
70A95BA52C7F7DDE0007836E /* UnsubscribeArtistResponse.swift in Sources */,
7DEACE532C1ED96400F37DA3 /* ENFont.swift in Sources */,
701467802C53645900750A54 /* FeaturedWatchTheFullPerformanceFooterView.swift in Sources */,
70DC8F732CA27E42006DDAF7 /* DefaultMyAlarmListUseCase.swift in Sources */,
7DA1CA1F2C6BA72D00C2752F /* ShowDetailInfoView.swift in Sources */,
700484FB2C76823500B9A964 /* ShowDetailSeatInfoView.swift in Sources */,
70B81D5E2C580E8F00665EDD /* LeftAlignedCollectionViewFlowLayout.swift in Sources */,
70DC8F712CA27E37006DDAF7 /* MyAlarmListUseCase.swift in Sources */,
7DB9F93B2C662D600097C4F9 /* GradientView.swift in Sources */,
7D2981022C01E1D000A619FB /* SceneDelegate.swift in Sources */,
7D0ED9D72C80C77D00145D86 /* ShowDetailResponse.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// DefaultMyAlarmListUseCase.swift
// ShowPot
//
// Created by 이건준 on 9/24/24.
//

import Foundation

import RxSwift
import RxCocoa

final class DefaultMyAlarmListUseCase: MyAlarmListUseCase {

private let apiService: SPShowAPI
private let disposeBag = DisposeBag()

var myAlarmModel: RxRelay.BehaviorRelay<[MyAlarmInfo]> = BehaviorRelay<[MyAlarmInfo]>(value: [])

init(apiService: SPShowAPI = SPShowAPI()) {
self.apiService = apiService
requestMyAlarmModel()
}

func requestMyAlarmModel() {
myAlarmModel.accept([
.init(thumbnailImageURL: URL(string: "https://ticketimage.interpark.com/Play/image/large/24/24006288_p.gif"), mainAlarm: "티켓팅이 1시간 남았어요!", subAlarm: "1시간 후, 0000 티켓팅이 오픈됩니다.🥰", timeLeft: "1분전"),
.init(thumbnailImageURL: URL(string: "https://ticketimage.interpark.com/Play/image/large/24/24006714_p.gif"), mainAlarm: "티켓팅이 6시간 남았어요!", subAlarm: "6시간 후, 0000 예매가 오픈됩니다.🥰", timeLeft: "5시간 전"),
.init(thumbnailImageURL: URL(string: "https://ticketimage.interpark.com/Play/image/large/24/24011642_p.gif"), mainAlarm: "구독장르의 공연이 오픈 되었어요!", subAlarm: "EDM 장르의 공연이 업데이트 되었어요.", timeLeft: "10분전"),
.init(thumbnailImageURL: URL(string: "https://ticketimage.interpark.com/Play/image/large/24/24007623_p.gif"), mainAlarm: "구독한 아티스트 공연이 오픈 되었어요!", subAlarm: "힙합 장르의 공연이 업데이트 되었어요.", timeLeft: "2시간 전"),
.init(thumbnailImageURL: URL(string: "https://media.bunjang.co.kr/product/262127257_1_1714651082_w360.jpg"), mainAlarm: "티켓팅이 24시간 남았어요!", subAlarm: "High Flying Birds 의 공연이 업데이트 되었어요.", timeLeft: "8분전"),
])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// MyAlarmListUseCase.swift
// ShowPot
//
// Created by 이건준 on 9/24/24.
//

import RxSwift
import RxCocoa

protocol MyAlarmListUseCase {
var myAlarmModel: BehaviorRelay<[MyAlarmInfo]> { get }
func requestMyAlarmModel()
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ final class MyAlarmListCoordinator: Coordinator {
}

func start() {
let viewModel = MyAlarmListViewModel(coordinator: self)
let viewModel = MyAlarmListViewModel(coordinator: self, usecase: DefaultMyAlarmListUseCase())
let viewController = MyAlarmListViewController(viewModel: viewModel)
self.navigationController.pushViewController(viewController, animated: true)
}

func popViewController() {
self.parentCoordinator?.removeChildCoordinator(child: self)
self.navigationController.popViewController(animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ final class MyAlarmListViewController: ViewController {
override func viewDidLoad() {
super.viewDidLoad()
viewHolderConfigure()

viewHolder.alarmListView.delegate = self
}

override func setupStyles() {
Expand All @@ -37,7 +35,30 @@ final class MyAlarmListViewController: ViewController {
}

override func bind() {
let input = MyAlarmListViewModel.Input(
didTappedBackButton: contentNavigationBar.didTapLeftButton.asObservable(),
didTappedAlarmCell: viewHolder.alarmListView.rx.itemSelected.asObservable()
)

let output = viewModel.transform(input: input)
output.myAlarmModel
.asDriver()
.drive(viewHolder.alarmListView.rx.items(
cellIdentifier: AlarmCollectionViewCell.reuseIdentifier,
cellType: AlarmCollectionViewCell.self)
) { index, item, cell in
cell.configureUI(
thumbnailImageURL: item.thumbnailImageURL,
mainAlarm: item.mainAlarm,
subAlarm: item.subAlarm,
timeLeft: item.timeLeft
)
}
.disposed(by: disposeBag)

viewHolder.alarmListView.rx
.setDelegate(self)
.disposed(by: disposeBag)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,66 @@

import Foundation

import RxSwift
import RxCocoa

final class MyAlarmListViewModel: ViewModelType {

var coordinator: Coordinator
private let disposeBag = DisposeBag()
private let usecase: MyAlarmListUseCase

var coordinator: MyAlarmListCoordinator

init(coordinator: Coordinator) {
init(coordinator: MyAlarmListCoordinator, usecase: MyAlarmListUseCase) {
self.coordinator = coordinator
self.usecase = usecase
}

struct Input {

let didTappedBackButton: Observable<Void>
let didTappedAlarmCell: Observable<IndexPath>
}

struct Output {

let myAlarmModel = BehaviorRelay<[MyAlarmInfo]>(value: [])
let isAlarmEmpty = PublishRelay<Bool>()
}

func transform(input: Input) -> Output {

let output = Output()

input.didTappedBackButton
.subscribe(with: self) { owner, _ in
owner.coordinator.popViewController()
}
.disposed(by: disposeBag)

input.didTappedAlarmCell
.subscribe(with: self) { owner, indexPath in
let selectedAlarmModel = owner.usecase.myAlarmModel.value[indexPath.row]
LogHelper.debug("선택된 알림 정보: \(selectedAlarmModel)")
}
.disposed(by: disposeBag)

let sharedAlarmModel = usecase.myAlarmModel.share(replay: 1)

return Output()
sharedAlarmModel
.map { $0.isEmpty }
.bind(to: output.isAlarmEmpty)
.disposed(by: disposeBag)

sharedAlarmModel
.bind(to: output.myAlarmModel)
.disposed(by: disposeBag)

return output
}
}

struct MyAlarmInfo {
let thumbnailImageURL: URL?
let mainAlarm: String
let subAlarm: String
let timeLeft: String
}

0 comments on commit 3657a64

Please sign in to comment.