Skip to content

Commit

Permalink
[Feat] sopt-makers#360 - 파트 내 랭킹 API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
lsj8706 committed Apr 5, 2024
1 parent 9bf0d73 commit 3b5a0b7
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ extension RankingRepository: RankingRepositoryInterface {
$0.map { $0.toDomain() }
}.eraseToAnyPublisher()
}

public func fetchRankingListInPart(part: String) -> AnyPublisher<[RankingModel], Error> {
return self.rankService
.fetchRankingListInPart(part: part)
.map {
$0.map { $0.toDomain() }
}
.eraseToAnyPublisher()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ import Combine
public protocol RankingRepositoryInterface {
func fetchRankingListModel(isCurrentGeneration: Bool) -> AnyPublisher<[RankingModel], Error>
func fetchPartRanking() -> AnyPublisher<[Domain.PartRankingModel], Error>
func fetchRankingListInPart(part: String) -> AnyPublisher<[RankingModel], Error>
}
11 changes: 11 additions & 0 deletions SOPT-iOS/Projects/Domain/Sources/UseCase/RankingUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Core

public protocol RankingUseCase {
func fetchRankingList(isCurrentGeneration: Bool)
func fetchRankingList(part: String)
func findMyRanking()
func fetchPartRanking()

Expand Down Expand Up @@ -61,6 +62,16 @@ extension DefaultRankingUseCase: RankingUseCase {
}.store(in: cancelBag)
}

public func fetchRankingList(part: String) {
self.repository
.fetchRankingListInPart(part: part)
.sink { completion in
print(completion)
} receiveValue: { [weak self] rankingModels in
self?.rankingListModelFetched.send(rankingModels)
}.store(in: cancelBag)
}

public func findMyRanking() {
let myRankingIndex = self.findMyRankingIndex(model: rankingListModelFetched.value)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Part.swift
// StampFeatureInterface
//
// Created by Aiden.lee on 2024/04/06.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import Foundation

public enum Part: String, CaseIterable {
case plan = "기획"
case design = "디자인"
case web = ""
case ios = "아요"
case android = "안드"
case server = "서버"

public func uppercasedName() -> String {
switch self {
case .plan: return "PLAN"
case .design: return "DESIGN"
case .web: return "WEB"
case .ios: return "IOS"
case .android: return "ANDROID"
case .server: return "SERVER"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum RankingViewType {
case all
case currentGeneration(info: UsersActiveGenerationStatusViewResponse)
case partRanking
case individualRankingInPart(part: Part)
}

public protocol StampFeatureViewBuildable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ import Domain

public protocol MissionListViewControllable: ViewControllable & MissionListCoordinatable { }
public protocol MissionListCoordinatable {
var onSwiped: (() -> Void)? { get set }
var onNaviBackTap: (() -> Void)? { get set }
var onPartRankingButtonTap: ((RankingViewType) -> Void)? { get set }
var onCurrentGenerationRankingButtonTap: ((RankingViewType) -> Void)? { get set }
var onGuideTap: (() -> Void)? { get set }
var onCellTap: ((MissionListModel, _ username: String?) -> Void)? { get set }
var onSwiped: (() -> Void)? { get set }
var onNaviBackTap: (() -> Void)? { get set }
var onPartRankingButtonTap: ((RankingViewType) -> Void)? { get set }
var onCurrentGenerationRankingButtonTap: ((RankingViewType) -> Void)? { get set }
var onGuideTap: (() -> Void)? { get set }
var onCellTap: ((MissionListModel, _ username: String?) -> Void)? { get set }
}
public protocol ListDetailViewControllable: ViewControllable & ListDetailCoordinatable { }
public protocol ListDetailCoordinatable {
var onComplete: ((StarViewLevel, (() -> Void)?) -> Void)? { get set }
var onComplete: ((StarViewLevel, (() -> Void)?) -> Void)? { get set }
}
public protocol MissionCompletedViewControllable: ViewControllable { }
public protocol RankingViewControllable: ViewControllable & RankingCoordinatable { }
public protocol RankingCoordinatable {
var onCellTap: ((_ username: String, _ sentence: String) -> Void)? { get set }
var onNaviBackTap: (() -> Void)? { get set }
var onCellTap: ((_ username: String, _ sentence: String) -> Void)? { get set }
var onNaviBackTap: (() -> Void)? { get set }
}
public protocol PartRankingViewControllable: ViewControllable & RankingCoordinatable { }

public protocol PartRankingCoordinatable {
var onCellTap: ((_ part: Part) -> Void)? { get set }
var onNaviBackTap: (() -> Void)? { get set }
}
public protocol PartRankingViewControllable: ViewControllable & PartRankingCoordinatable { }
public protocol StampGuideViewControllable: ViewControllable { }
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,30 @@ final class RankingCoordinator: DefaultCoordinator {

public override func start() {
switch rankingViewType {
case .all, .currentGeneration:
showRanking()
case .all, .currentGeneration, .individualRankingInPart:
showRanking(rankingViewType: rankingViewType)
case .partRanking:
showPartRanking()
}
}

private func showRanking() {
var ranking = factory.makeRankingVC(rankingViewType: self.rankingViewType)
private func showRanking(rankingViewType: RankingViewType) {
var ranking = factory.makeRankingVC(rankingViewType: rankingViewType)

ranking.onCellTap = { [weak self] (username, sentence) in
self?.showOtherMissionList(username, sentence)
}
ranking.onNaviBackTap = { [weak self] in
self?.router.popModule()
self?.finishFlow?()
}
router.push(ranking)
}

private func showPartRanking() {
var ranking = factory.makePartRankingVC(rankingViewType: self.rankingViewType)

ranking.onCellTap = { [weak self] (username, sentence) in
self?.showOtherMissionList(username, sentence)
ranking.onCellTap = { [weak self] part in
self?.showRanking(rankingViewType: .individualRankingInPart(part: part))
}
ranking.onNaviBackTap = { [weak self] in
self?.router.popModule()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ final class PartRankingListCVC: UICollectionViewCell, UICollectionViewRegisterab
// MARK: - Properties

static var isFromNib: Bool = false
var model: PartRankingModel?

// MARK: - UI Components

Expand Down Expand Up @@ -95,10 +96,11 @@ extension PartRankingListCVC {

extension PartRankingListCVC {

public func setData(rank: Int, partName: String, score: Int) {
rankLabel.text = String(rank)
partNameLabel.text = partName
scoreLabel.text = "\(score)"
public func setData(model: PartRankingModel) {
self.model = model
rankLabel.text = String(model.rank)
partNameLabel.text = model.part
scoreLabel.text = "\(model.points)"
scoreLabel.partFontChange(targetString: "",
font: DSKitFontFamily.Pretendard.medium.font(size: 12))
setDefaultRanking()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class PartRankingVC: UIViewController, PartRankingViewControllable {

// MARK: - RankingCoordinatable

public var onCellTap: ((String, String) -> Void)?
public var onCellTap: ((Part) -> Void)?
public var onNaviBackTap: (() -> Void)?

// MARK: - UI Components
Expand Down Expand Up @@ -159,7 +159,7 @@ extension PartRankingVC {
case .list:
guard let rankingListCell = collectionView.dequeueReusableCell(withReuseIdentifier: PartRankingListCVC.className, for: indexPath) as? PartRankingListCVC,
let model = itemIdentifier as? PartRankingModel else { return UICollectionViewCell() }
rankingListCell.setData(rank: model.rank, partName: model.part, score: model.points)
rankingListCell.setData(model: model)

return rankingListCell
}
Expand All @@ -186,8 +186,9 @@ extension PartRankingVC: UICollectionViewDelegate {
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard indexPath.section >= 1 else { return }

guard let tappedCell = collectionView.cellForItem(at: indexPath) as? RankingListTappable,
let item = tappedCell.getModelItem() else { return }
self.onCellTap?(item.username, item.sentence)
guard let tappedCell = collectionView.cellForItem(at: indexPath) as? PartRankingListCVC,
let model = tappedCell.model else { return }
guard let part = Part(rawValue: model.part) else { return }
self.onCellTap?(part)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import SnapKit
import Then

import StampFeatureInterface
import BaseFeatureDependency

public class RankingVC: UIViewController, RankingViewControllable {

Expand Down Expand Up @@ -73,10 +74,15 @@ public class RankingVC: UIViewController, RankingViewControllable {

super.init(nibName: nil, bundle: nil)

guard case .currentGeneration(let info) = rankingViewType else { return }

if case .currentGeneration(let info) = rankingViewType {
let navigationTitle = String(describing: info.currentGeneration) + "기 랭킹"
self.naviBar.setTitle(navigationTitle)
}

if case .individualRankingInPart(let part) = rankingViewType {
let navigationTitle = String(describing: part.rawValue) + " 랭킹"
self.naviBar.setTitle(navigationTitle)
}
}

required init?(coder: NSCoder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ extension RankingViewModel {
.withUnretained(self)
.sink { owner, _ in
switch self.rankingViewType {
case .all: owner.useCase.fetchRankingList(isCurrentGeneration: false)
case .currentGeneration: owner.useCase.fetchRankingList(isCurrentGeneration: true)
case .all:
owner.useCase.fetchRankingList(isCurrentGeneration: false)
case .currentGeneration:
owner.useCase.fetchRankingList(isCurrentGeneration: true)
case .individualRankingInPart(let part):
owner.useCase.fetchRankingList(part: part.uppercasedName())
default:
return
}
Expand Down
3 changes: 3 additions & 0 deletions SOPT-iOS/Projects/Modules/Networks/Sources/API/RankAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public enum RankAPI {
case currentRank
case rankDetail(userName: String)
case rankPart
case currentRankInPart(partName: String)
}

extension RankAPI: BaseAPI {
Expand All @@ -42,6 +43,8 @@ extension RankAPI: BaseAPI {
return "/detail"
case .rankPart:
return "/part"
case .currentRankInPart(let partName):
return "/current/part/\(partName)"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public protocol RankService {
func fetchRankingList(isCurrentGeneration: Bool) -> AnyPublisher<[RankingEntity], Error>
func fetchRankDetail(userName: String) -> AnyPublisher<RankDetailEntity, Error>
func fetchPartRanking() -> AnyPublisher<[PartRankingEntity], Error>
func fetchRankingListInPart(part: String) -> AnyPublisher<[RankingEntity], Error>
}

extension DefaultRankService: RankService {
Expand All @@ -32,4 +33,8 @@ extension DefaultRankService: RankService {
public func fetchPartRanking() -> AnyPublisher<[PartRankingEntity], Error> {
requestObjectInCombine(.rankPart)
}

public func fetchRankingListInPart(part: String) -> AnyPublisher<[RankingEntity], Error> {
requestObjectInCombine(.currentRankInPart(partName: part))
}
}

0 comments on commit 3b5a0b7

Please sign in to comment.