Skip to content

Commit

Permalink
✨ 신고 삭제 로직 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
chopmozzi committed Dec 11, 2023
1 parent 8a1dfc7 commit 8b23d23
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class PlaybackCell: UICollectionViewCell {

weak var delegate: PlaybackViewControllerDelegate?

private var memberID: Int?
private (set) var memberID: Int?

let playbackView: PlaybackView = PlaybackView()

Expand Down
7 changes: 5 additions & 2 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,11 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore {
}

func setSeeMoreButton() {
guard let parentView else { return }
let response: Models.SetSeemoreButton.Response = Models.SetSeemoreButton.Response(parentView: parentView)
guard let worker,
let currentCellMemberID: Int = previousCell?.memberID
else { return }
let buttonType: Models.SetSeemoreButton.ButtonType = worker.isMyVideo(currentCellMemberID: currentCellMemberID) ? .delete : .report
let response: Models.SetSeemoreButton.Response = Models.SetSeemoreButton.Response(buttonType: buttonType)
presenter?.presentSetSeemoreButton(with: response)
}

Expand Down
2 changes: 1 addition & 1 deletion iOS/Layover/Layover/Scenes/Playback/PlaybackModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ enum PlaybackModels {
}

struct Response {
let parentView: ParentView
let buttonType: ButtonType
}

struct ViewModel {
Expand Down
3 changes: 1 addition & 2 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ final class PlaybackPresenter: PlaybackPresentationLogic {
}

func presentSetSeemoreButton(with response: PlaybackModels.SetSeemoreButton.Response) {
let buttonType: Models.SetSeemoreButton.ButtonType = response.parentView == .myProfile ? .delete : .report
viewController?.setSeemoreButton(viewModel: Models.SetSeemoreButton.ViewModel(buttonType: buttonType))
viewController?.setSeemoreButton(viewModel: Models.SetSeemoreButton.ViewModel(buttonType: response.buttonType))
}

func presentDeleteVideo(with response: PlaybackModels.DeletePlaybackVideo.Response) {
Expand Down
30 changes: 23 additions & 7 deletions iOS/Layover/Layover/Scenes/Playback/PlaybackViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,17 @@ final class PlaybackViewController: BaseViewController {

override func setUI() {
super.setUI()
interactor?.setSeeMoreButton()
setSeeMoreButton()
self.navigationController?.navigationBar.tintColor = .layoverWhite
}

@objc private func reportButtonDidTap() {
private func setSeeMoreButton() {
guard let button = seemoreButton.customView as? UIButton else { return }
button.addTarget(self, action: #selector(seeMoreButtonDidTap), for: .touchUpInside)
self.navigationItem.rightBarButtonItem = seemoreButton
}

private func reportButtonDidTap() {
let alert: UIAlertController = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
let reportAction: UIAlertAction = UIAlertAction(title: "신고", style: .destructive, handler: {
[weak self] _ in
Expand All @@ -159,7 +165,7 @@ final class PlaybackViewController: BaseViewController {
})
}

@objc private func deleteButtonDidTap() {
private func deleteButtonDidTap() {
let visibleIndexPaths = playbackCollectionView.indexPathsForVisibleItems
if visibleIndexPaths.count > 1 { return }
guard let currentItemIndex = visibleIndexPaths.first else { return }
Expand All @@ -180,6 +186,10 @@ final class PlaybackViewController: BaseViewController {
self.interactor?.leavePlaybackView()
})
}

@objc private func seeMoreButtonDidTap() {
interactor?.setSeeMoreButton()
}
}

extension PlaybackViewController: PlaybackDisplayLogic {
Expand Down Expand Up @@ -277,14 +287,20 @@ extension PlaybackViewController: PlaybackDisplayLogic {
}

func setSeemoreButton(viewModel: Models.SetSeemoreButton.ViewModel) {
guard let button = seemoreButton.customView as? UIButton else { return }
// guard let button = seemoreButton.customView as? UIButton else { return }
// switch viewModel.buttonType {
// case .delete:
// button.addTarget(self, action: #selector(deleteButtonDidTap), for: .touchUpInside)
// case .report:
// button.addTarget(self, action: #selector(reportButtonDidTap), for: .touchUpInside)
// }
// self.navigationItem.rightBarButtonItem = seemoreButton
switch viewModel.buttonType {
case .delete:
button.addTarget(self, action: #selector(deleteButtonDidTap), for: .touchUpInside)
deleteButtonDidTap()
case .report:
button.addTarget(self, action: #selector(reportButtonDidTap), for: .touchUpInside)
reportButtonDidTap()
}
self.navigationItem.rightBarButtonItem = seemoreButton
}

func deleteVideo(viewModel: PlaybackModels.DeletePlaybackVideo.ViewModel) {
Expand Down
10 changes: 9 additions & 1 deletion iOS/Layover/Layover/Scenes/Playback/PlaybackWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protocol PlaybackWorkerProtocol {
func fetchHomePosts() async -> [Post]?
func fetchProfilePosts(profileID: Int?, page: Int) async -> [Post]?
func fetchTagPosts(selectedTag: String, page: Int) async -> [Post]?
func isMyVideo(currentCellMemberID: Int) -> Bool
}

final class PlaybackWorker: PlaybackWorkerProtocol {
Expand All @@ -28,17 +29,19 @@ final class PlaybackWorker: PlaybackWorkerProtocol {
typealias Models = PlaybackModels

private let provider: ProviderType
private let authManager: AuthManagerProtocol
private let defaultPostManagerEndPointFactory: PostManagerEndPointFactory
private let defaultPostEndPointFactory: PostEndPointFactory
private let defaultUserEndPointFactory: UserEndPointFactory

// MARK: - Methods

init(provider: ProviderType = Provider(), defaultPostManagerEndPointFactory: PostManagerEndPointFactory = DefaultPostManagerEndPointFactory(), defaultPostEndPointFactory: PostEndPointFactory = DefaultPostEndPointFactory(), defaultUserEndPointFactory: UserEndPointFactory = DefaultUserEndPointFactory()) {
init(provider: ProviderType = Provider(), authManager: AuthManagerProtocol = AuthManager.shared, defaultPostManagerEndPointFactory: PostManagerEndPointFactory = DefaultPostManagerEndPointFactory(), defaultPostEndPointFactory: PostEndPointFactory = DefaultPostEndPointFactory(), defaultUserEndPointFactory: UserEndPointFactory = DefaultUserEndPointFactory()) {
self.provider = provider
self.defaultPostManagerEndPointFactory = defaultPostManagerEndPointFactory
self.defaultPostEndPointFactory = defaultPostEndPointFactory
self.defaultUserEndPointFactory = defaultUserEndPointFactory
self.authManager = authManager
}

func makeInfiniteScroll(posts: [Post]) -> [Post] {
Expand Down Expand Up @@ -118,4 +121,9 @@ final class PlaybackWorker: PlaybackWorkerProtocol {
return nil
}
}

func isMyVideo(currentCellMemberID: Int) -> Bool {
let myMemberID = authManager.memberID
return currentCellMemberID == myMemberID
}
}
14 changes: 12 additions & 2 deletions iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol {
typealias Models = PlaybackModels

private let provider: ProviderType
private let authManager: AuthManagerProtocol

// MARK: - Methods

init(provider: ProviderType = Provider(session: .initMockSession())) {
// init(provider: ProviderType = Provider(session: .initMockSession())) {
// self.provider = provider
// }

init(provider: ProviderType = Provider(session: .initMockSession()), authManager: AuthManagerProtocol = StubAuthManager()) {
self.provider = provider
self.authManager = authManager
}

func makeInfiniteScroll(posts: [Post]) -> [Post] {
guard let tempLastVideo: Post = posts.last,
let tempFirstVideo: Post = posts.first
Expand Down Expand Up @@ -176,4 +182,8 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol {
}
}

func isMyVideo(currentCellMemberID: Int) -> Bool {
return currentCellMemberID == authManager.memberID
}

}

0 comments on commit 8b23d23

Please sign in to comment.