Skip to content

Commit

Permalink
Merge pull request #91 from yangsubinn/fix/#86
Browse files Browse the repository at this point in the history
[Fix] #86 - 랭킹에서 다른 사람 스탬프 상세 조회 연결, userId 분기처리
  • Loading branch information
yangsubinn authored Jan 8, 2023
2 parents 09cf0ad + 5a9dca2 commit 2e6962a
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Network

public class ListDetailRepository {

private let userId: Int = UserDefaultKeyList.Auth.userId ?? 0
private let userId: Int = UserDefaultKeyList.Auth.userId ?? 1
private let stampService: StampService
private let cancelBag = CancelBag()

Expand All @@ -24,8 +24,9 @@ public class ListDetailRepository {
}

extension ListDetailRepository: ListDetailRepositoryInterface {
public func fetchListDetail(missionId: Int) -> Driver<ListDetailModel> {
return stampService.fetchStampListDetail(userId: userId, missionId: missionId)
public func fetchListDetail(missionId: Int, userId: Int?) -> Driver<ListDetailModel> {
let targetUserId = userId ?? (self.userId)
return stampService.fetchStampListDetail(userId: targetUserId, missionId: missionId)
.map { $0.toDomain() }
.asDriver()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Core
import Combine

public protocol ListDetailRepositoryInterface {
func fetchListDetail(missionId: Int) -> Driver<ListDetailModel>
func fetchListDetail(missionId: Int, userId: Int?) -> Driver<ListDetailModel>
func postStamp(missionId: Int, stampData: [Any]) -> Driver<ListDetailModel>
func putStamp(missionId: Int, stampData: [Any]) -> Driver<Int>
func deleteStamp(stampId: Int) -> Driver<Bool>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Combine

public protocol ListDetailUseCase {
func fetchListDetail(missionId: Int)
func fetchOtherListDetail(userId: Int, missionId: Int)
func postStamp(missionId: Int, stampData: ListDetailRequestModel)
func putStamp(missionId: Int, stampData: ListDetailRequestModel)
func deleteStamp(stampId: Int)
Expand All @@ -36,7 +37,14 @@ public class DefaultListDetailUseCase {

extension DefaultListDetailUseCase: ListDetailUseCase {
public func fetchListDetail(missionId: Int) {
repository.fetchListDetail(missionId: missionId)
repository.fetchListDetail(missionId: missionId, userId: nil)
.sink { model in
self.listDetailModel.send(model)
}.store(in: self.cancelBag)
}

public func fetchOtherListDetail(userId: Int, missionId: Int) {
repository.fetchListDetail(missionId: missionId, userId: userId)
.sink { model in
self.listDetailModel.send(model)
}.store(in: self.cancelBag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ extension CustomNavigationBar {
}
}

public func hideRightButton(_ isHidden: Bool = true) {
self.rightButton.isHidden = isHidden
}

private func setAddTarget() {
self.leftButton.addTarget(self, action: #selector(popToPreviousVC), for: .touchUpInside)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,10 @@ extension ListDetailVC {
self.dateLabel.isHidden = false
self.missionImageView.isUserInteractionEnabled = false
}

if viewModel.otherUserId != nil {
self.naviBar.hideRightButton()
}
}

private func setDefaultUI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class ListDetailViewModel: ViewModelType {
public var missionId: Int!
public var missionTitle: String!
public var stampId: Int!
public var otherUserId: Int!

// MARK: - Inputs

Expand All @@ -48,12 +49,13 @@ public class ListDetailViewModel: ViewModelType {

// MARK: - init

public init(useCase: ListDetailUseCase, sceneType: ListDetailSceneType, starLevel: StarViewLevel, missionId: Int, missionTitle: String) {
public init(useCase: ListDetailUseCase, sceneType: ListDetailSceneType, starLevel: StarViewLevel, missionId: Int, missionTitle: String, otherUserId: Int?) {
self.useCase = useCase
self.sceneType = sceneType
self.starLevel = starLevel
self.missionId = missionId
self.missionTitle = missionTitle
self.otherUserId = otherUserId
}
}

Expand All @@ -67,7 +69,11 @@ extension ListDetailViewModel {
.withUnretained(self)
.sink { owner, _ in
if owner.sceneType == .completed {
owner.useCase.fetchListDetail(missionId: owner.missionId)
if let otherUserId = self.otherUserId {
owner.useCase.fetchOtherListDetail(userId: otherUserId, missionId: owner.missionId)
} else {
owner.useCase.fetchListDetail(missionId: owner.missionId)
}
}
}.store(in: cancelBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ extension MissionListVC: UICollectionViewDelegate {
case .default:
return true
case .ranking:
return false
return true
}
default:
return false
Expand All @@ -309,7 +309,8 @@ extension MissionListVC: UICollectionViewDelegate {
let detailVC = factory.makeListDetailVC(sceneType: sceneType,
starLevel: starLevel,
missionId: model.id,
missionTitle: model.title)
missionTitle: model.title,
otherUserId: viewModel.otherUserId)
self.navigationController?.pushViewController(detailVC, animated: true)
default:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class MissionListViewModel: ViewModelType {
private let useCase: MissionListUseCase
private var cancelBag = CancelBag()
public var missionListsceneType: MissionListSceneType!
public var otherUserId: Int?

// MARK: - Inputs

Expand Down Expand Up @@ -76,6 +77,7 @@ extension MissionListViewModel {
private func fetchMissionList() {
switch self.missionListsceneType {
case .ranking(_, _, let userId):
self.otherUserId = userId
self.useCase.fetchOtherUserMissionList(type: .complete, userId: userId)
default:
self.useCase.fetchMissionList(type: .all)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public protocol ModuleFactoryInterface {
// MARK: - Main Flow

func makeMissionListVC(sceneType: MissionListSceneType) -> MissionListVC
func makeListDetailVC(sceneType: ListDetailSceneType, starLevel: StarViewLevel, missionId: Int, missionTitle: String) -> ListDetailVC
func makeListDetailVC(sceneType: ListDetailSceneType, starLevel: StarViewLevel, missionId: Int, missionTitle: String, otherUserId: Int?) -> ListDetailVC
func makeMissionCompletedVC(starLevel: StarViewLevel) -> MissionCompletedVC
func makeRankingVC() -> RankingVC

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

window = UIWindow(frame: scene.coordinateSpace.bounds)
window?.windowScene = scene
let rootVC = ModuleFactory.shared.makeSignUpVC()
let rootVC = ModuleFactory.shared.makeSplashVC()
window?.rootViewController = UINavigationController(rootViewController: rootVC)
window?.makeKeyAndVisible()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ extension ModuleFactory: ModuleFactoryInterface {
return missionListVC
}

public func makeListDetailVC(sceneType: ListDetailSceneType, starLevel: StarViewLevel, missionId: Int, missionTitle: String) -> ListDetailVC {
public func makeListDetailVC(sceneType: ListDetailSceneType, starLevel: StarViewLevel, missionId: Int, missionTitle: String, otherUserId: Int?) -> ListDetailVC {
let repository = ListDetailRepository(service: stampService)
let useCase = DefaultListDetailUseCase(repository: repository)
let viewModel = ListDetailViewModel(useCase: useCase, sceneType: sceneType, starLevel: starLevel, missionId: missionId, missionTitle: missionTitle)
let viewModel = ListDetailViewModel(useCase: useCase, sceneType: sceneType, starLevel: starLevel, missionId: missionId, missionTitle: missionTitle, otherUserId: otherUserId)
let listDetailVC = ListDetailVC()
listDetailVC.viewModel = viewModel
listDetailVC.factory = self
Expand Down

0 comments on commit 2e6962a

Please sign in to comment.