Skip to content

Commit

Permalink
✨ 프로필에서 재생화면으로 화면전환로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
loinsir committed Dec 6, 2023
1 parent ca70dc9 commit 44bbbcf
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 18 deletions.
28 changes: 21 additions & 7 deletions iOS/Layover/Layover/Scenes/Profile/ProfileInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import Foundation

protocol ProfileBusinessLogic {
@discardableResult
func fetchProfile() -> Task<Bool, Never>
func fetchProfile(with request: ProfileModels.FetchProfile.Request) -> Task<Bool, Never>

@discardableResult
func fetchMorePosts() -> Task<Bool, Never>
func fetchMorePosts(with request: ProfileModels.FetchMorePosts.Request) -> Task<Bool, Never>

func showPostDetail(with request: ProfileModels.ShowPostDetail.Request)
}

protocol ProfileDataStore {
Expand All @@ -22,6 +24,9 @@ protocol ProfileDataStore {
var profileImageData: Data? { get set }

var profileId: Int? { get set }

var playbackStartIndex: Int? { get set }
var posts: [Post] { get set }
}

final class ProfileInteractor: ProfileBusinessLogic, ProfileDataStore {
Expand All @@ -42,10 +47,13 @@ final class ProfileInteractor: ProfileBusinessLogic, ProfileDataStore {
var profileImageData: Data?
var profileId: Int?

var playbackStartIndex: Int?
var posts: [Post] = []

// MARK: - Methods

@discardableResult
func fetchProfile() -> Task<Bool, Never> {
func fetchProfile(with request: ProfileModels.FetchProfile.Request) -> Task<Bool, Never> {
Task {
guard let userProfile = await userWorker?.fetchProfile(by: profileId) else {
return false
Expand Down Expand Up @@ -75,7 +83,7 @@ final class ProfileInteractor: ProfileBusinessLogic, ProfileDataStore {
}

@discardableResult
func fetchMorePosts() -> Task<Bool, Never> {
func fetchMorePosts(with request: ProfileModels.FetchMorePosts.Request) -> Task<Bool, Never> {
Task {
guard canFetchMorePosts else { return false }
let fetchedPosts = await fetchPosts()
Expand All @@ -97,13 +105,14 @@ final class ProfileInteractor: ProfileBusinessLogic, ProfileDataStore {
}

private func fetchPosts() async -> [Models.Post] {
guard let posts = await userWorker?.fetchPosts(at: fetchPostsPage, of: profileId),
posts.count > 0 else {
guard let fetchedPosts = await userWorker?.fetchPosts(at: fetchPostsPage, of: profileId),
fetchedPosts.count > 0 else {
return []
}
posts += fetchedPosts

var responsePosts = [Models.Post]()
for post in posts {
for post in fetchedPosts {
guard let thumbnailURL = post.board.thumbnailImageURL,
let profileImageData = await userWorker?.fetchImageData(with: thumbnailURL) else {
responsePosts.append(.init(id: post.board.identifier, thumbnailImageData: nil))
Expand All @@ -116,4 +125,9 @@ final class ProfileInteractor: ProfileBusinessLogic, ProfileDataStore {
return responsePosts
}

func showPostDetail(with request: ProfileModels.ShowPostDetail.Request) {
playbackStartIndex = request.startIndex
presenter?.presentPostDetail(with: Models.ShowPostDetail.Response())
}

}
13 changes: 12 additions & 1 deletion iOS/Layover/Layover/Scenes/Profile/ProfileModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ enum ProfileModels {
}

enum FetchMorePosts {

struct Request {
}

Expand All @@ -50,4 +49,16 @@ enum ProfileModels {
let posts: [Post]
}
}

enum ShowPostDetail {
struct Request {
let startIndex: Int
}

struct Response {
}

struct ViewModel {
}
}
}
5 changes: 5 additions & 0 deletions iOS/Layover/Layover/Scenes/Profile/ProfilePresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit
protocol ProfilePresentationLogic {
func presentProfile(with response: ProfileModels.FetchProfile.Response)
func presentMorePosts(with response: ProfileModels.FetchMorePosts.Response)
func presentPostDetail(with response: ProfileModels.ShowPostDetail.Response)
}

final class ProfilePresenter: ProfilePresentationLogic {
Expand All @@ -33,4 +34,8 @@ final class ProfilePresenter: ProfilePresentationLogic {
viewController?.displayMorePosts(viewModel: viewModel)
}

func presentPostDetail(with response: ProfileModels.ShowPostDetail.Response) {
viewController?.routeToPostDetail(viewModel: Models.ShowPostDetail.ViewModel())
}

}
25 changes: 20 additions & 5 deletions iOS/Layover/Layover/Scenes/Profile/ProfileRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
import UIKit

protocol ProfileRoutingLogic {
func routeToEditProfileViewController()
func routeToSettingSceneViewController()
func routeToEditProfile()
func routeToSetting()
func routeToPlayback()
}

protocol ProfileDataPassing {
var dataStore: ProfileDataStore? { get }
}

final class ProfileRouter: NSObject, ProfileRoutingLogic, ProfileDataPassing {
final class ProfileRouter: ProfileRoutingLogic, ProfileDataPassing {

// MARK: - Properties

Expand All @@ -26,7 +27,7 @@ final class ProfileRouter: NSObject, ProfileRoutingLogic, ProfileDataPassing {

// MARK: - Routing

func routeToEditProfileViewController() {
func routeToEditProfile() {
let editProfileViewController = EditProfileViewController()
guard let source = dataStore,
var destination = editProfileViewController.router?.dataStore
Expand All @@ -38,16 +39,30 @@ final class ProfileRouter: NSObject, ProfileRoutingLogic, ProfileDataPassing {
viewController?.navigationController?.pushViewController(editProfileViewController, animated: true)
}

func routeToSettingSceneViewController() {
func routeToSetting() {
let settingSceneViewController: SettingSceneViewController = SettingSceneViewController()
viewController?.navigationController?.pushViewController(settingSceneViewController, animated: true)
}

func routeToPlayback() {
let playbackViewController = PlaybackViewController()
guard let source = dataStore,
var destination = playbackViewController.router?.dataStore
else { return }
passDataToPlayback(source: source, destination: &destination)
viewController?.navigationController?.pushViewController(playbackViewController, animated: true)
}

// MARK: - Data Passing

private func passDataToEditProfile(source: ProfileDataStore, destination: inout EditProfileDataStore) {
destination.nickname = source.nickname
destination.introduce = source.introduce
destination.profileImageData = source.profileImageData
}

private func passDataToPlayback(source: ProfileDataStore, destination: inout PlaybackDataStore) {
destination.posts = source.posts
destination.index = source.playbackStartIndex
}
}
26 changes: 21 additions & 5 deletions iOS/Layover/Layover/Scenes/Profile/ProfileViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import UIKit
protocol ProfileDisplayLogic: AnyObject {
func displayProfile(viewModel: ProfileModels.FetchProfile.ViewModel)
func displayMorePosts(viewModel: ProfileModels.FetchMorePosts.ViewModel)
func routeToPostDetail(viewModel: ProfileModels.ShowPostDetail.ViewModel)
}

final class ProfileViewController: BaseViewController {
Expand Down Expand Up @@ -47,7 +48,7 @@ final class ProfileViewController: BaseViewController {
// MARK: - Properties

typealias Models = ProfileModels
var router: (NSObjectProtocol & ProfileRoutingLogic & ProfileDataPassing)?
var router: (ProfileRoutingLogic & ProfileDataPassing)?
var interactor: ProfileBusinessLogic?
private let profileType: ProfileType

Expand Down Expand Up @@ -175,21 +176,21 @@ final class ProfileViewController: BaseViewController {
// MARK: - Use Case

private func fetchProfile() {
interactor?.fetchProfile()
interactor?.fetchProfile(with: Models.FetchProfile.Request())
}

private func fetchPosts() {
interactor?.fetchMorePosts()
interactor?.fetchMorePosts(with: Models.FetchMorePosts.Request())
}

// MARK: - Actions

@objc private func editbuttonDidTap() {
router?.routeToEditProfileViewController()
router?.routeToEditProfile()
}

@objc private func settingButtonDidTap() {
router?.routeToSettingSceneViewController()
router?.routeToSetting()
}

}
Expand All @@ -211,6 +212,10 @@ extension ProfileViewController: ProfileDisplayLogic {
snapshot.append(viewModel.posts)
collectionViewDatasource?.apply(snapshot, to: .posts)
}

func routeToPostDetail(viewModel: ProfileModels.ShowPostDetail.ViewModel) {
router?.routeToPlayback()
}
}

// MARK: - UICollectionViewDelegate
Expand All @@ -225,4 +230,15 @@ extension ProfileViewController: UICollectionViewDelegate {
fetchPosts()
}
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let section = Section(rawValue: indexPath.section) else { return }
switch section {
case .profile:
return
case .posts:
guard let post = collectionViewDatasource?.itemIdentifier(for: indexPath) as? Models.Post else { return }
interactor?.showPostDetail(with: Models.ShowPostDetail.Request(startIndex: indexPath.item))
}
}
}

0 comments on commit 44bbbcf

Please sign in to comment.