Skip to content

Commit

Permalink
[ITDS-73] refactor: #56 - PostKind를 DomainLayer로 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
wongbingg committed Jan 17, 2025
1 parent f0cbd57 commit 2d76dbb
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public final class PostCollectionView: UIView {
ofKind: UICollectionView.elementKindSectionHeader,
for: indexPath)
let sectionModel = dataSource.sectionModels[indexPath.section]
header.setData(title: sectionModel.header, summary: sectionModel.summary)
header.setData(title: sectionModel.kind.title, summary: sectionModel.kind.summary)
header.tapObservable
.map { indexPath }
.bind(to: headerTapRelay)
Expand Down
4 changes: 2 additions & 2 deletions Targets/DomainLayer/Sources/Entities/PostCellData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public extension PostCellData {
// MARK: - toPostSection

public extension Array<PostCellData> {
func toPostSection(header: String, summary: String) -> PostSection {
.init(header: header, summary: summary, items: self)
func toPostSection(kind: PostKind) -> PostSection {
.init(kind: kind, items: self)
}
}
38 changes: 38 additions & 0 deletions Targets/DomainLayer/Sources/Entities/PostKind.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// PostKind.swift
// DomainLayer
//
// Created by 이원빈 on 1/17/25.
// Copyright © 2025 MOZIP. All rights reserved.
//

import Foundation

public enum PostKind: String, CaseIterable {
case 공모전
case 해커톤
case 동아리

public var id: Int {
switch self {
case .공모전: 1
case .해커톤: 2
case .동아리: 3
}
}
public var title: String {
switch self {
case .공모전: "공모전 📑"
case .해커톤: "해커톤 🏆"
case .동아리: "IT 동아리 💻"
}
}

public var summary: String {
switch self {
case .공모전: "커리어 성장을 위한 IT 공모전 모음"
case .해커톤: "단기간 프로젝트를 경험할 수 있는 해커톤"
case .동아리: "사이드 프로젝트 경험을 쌓는 IT 동아리"
}
}
}
8 changes: 3 additions & 5 deletions Targets/DomainLayer/Sources/Entities/PostSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import RxDataSources

public struct PostSection: Equatable {
public let header: String
public let summary: String
public let kind: PostKind
public var items: [Item]
}

Expand All @@ -26,9 +25,8 @@ extension PostSection: SectionModelType {
// MARK: - Stub

public extension PostSection {
static func stub(header: String = "공모전",
summary: String = "커리어 성장을 위한 IT 공모전 모음",
static func stub(kind: PostKind = .공모전,
items: [PostCellData] = [.stub(), .stub(), .stub(), .stub(), .stub()]) -> Self {
.init(header: header, summary: summary, items: items)
.init(kind: kind, items: items)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import DomainLayer
import UIKit

public protocol HomeCoordinatorType: CoordinatorType {
func pushPostList(code: String)
func pushPostList(postKind: PostKind)
func pushLoginPage()
func pushMyPage()
func pushPostDetail(id: Int)
Expand All @@ -38,10 +38,10 @@ final class HomeCoordinator: HomeCoordinatorType {

func didFinish() {}

func pushPostList(code: String) {
func pushPostList(postKind: PostKind) {
let coordinator = PostListCoordinator(navigationController: navigationController)
coordinator.parentCoordinator = self
coordinator.start(with: code)
coordinator.start(with: postKind)
self.addChild(coordinator)
}

Expand Down
12 changes: 6 additions & 6 deletions Targets/PresentationLayer/Sources/Home/Reactor/HomeReactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ final class HomeReactor: Reactor {
struct State {
var isSuccessPostFetch: Bool = false
var isSuccessBannerFetch: Bool = false
var postHeaderTitles: [String] = []
var selectedCell: PostCellData?
var postHeaders: [PostKind] = []
var selectedCell: PostCellData?

var postSections: [PostSection] = []
var banners: [BannerCellData] = []
Expand All @@ -71,7 +71,7 @@ final class HomeReactor: Reactor {
switch mutation {
case let .setPosts(data):
newState.postSections = data
newState.postHeaderTitles = data.map { $0.header }
newState.postHeaders = data.map { $0.kind }
newState.isSuccessPostFetch = true
case let .setBanners(data):
newState.banners = data
Expand Down Expand Up @@ -102,9 +102,9 @@ final class HomeReactor: Reactor {
)
.map { (firstGroup, secondGroup, thirdGroup) in
.setPosts(data: [
firstGroup.toPostSection(header: "공모전 📑", summary: "커리어 성장을 위한 IT 공모전 모음"),
secondGroup.toPostSection(header: "해커톤 🏆", summary: "단기간 프로젝트를 경험할 수 있는 해커톤"),
thirdGroup.toPostSection(header: "IT 동아리 💻", summary: "사이드 프로젝트 경험을 쌓는 IT 동아리")
firstGroup.toPostSection(kind: .공모전),
secondGroup.toPostSection(kind: .해커톤),
thirdGroup.toPostSection(kind: .동아리)
])
}
// TODO: .catch { error in ... } 에러처리 필요.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import DomainLayer
import UIKit

protocol PostListCoordinatorType: CoordinatorType {
func start(with code: String)
func start(with postKind: PostKind)
func pushPostDetail(id: Int)
}

Expand All @@ -32,8 +32,8 @@ final class PostListCoordinator: PostListCoordinatorType {
// FIXME: ViewController 사이 데이터를 주고받을 경우 고려
}

func start(with code: String) {
let vc = postListViewController(with: code)
func start(with postKind: PostKind) {
let vc = postListViewController(with: postKind)
navigationController.pushViewController(vc, animated: true)
}

Expand Down Expand Up @@ -61,12 +61,12 @@ final class PostListCoordinator: PostListCoordinatorType {

// MARK: - Private
private extension PostListCoordinator {
func postListViewController(with code: String) -> PostListViewController {
func postListViewController(with postKind: PostKind) -> PostListViewController {
guard let fetchPostListUseCase = DIContainer.shared.resolve(type: FetchPostListUseCaseType.self) else {
fatalError()
}
let reactor = PostListReactor(fetchPostListUseCase: fetchPostListUseCase)
let viewController = PostListViewController(reactor: reactor, code: code)
let viewController = PostListViewController(reactor: reactor, postKind: postKind)
viewController.coordinator = self
return viewController
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,13 @@ import RxCocoa

final class PostListViewController: BaseViewController<PostListReactor>, Coordinatable {

enum PostKind: String, CaseIterable {
case 공모전 = "공모전 📑"
case 해커톤 = "해커톤 🏆"
case 동아리 = "IT 동아리 💻"

var title: String {
switch self {
case .공모전: "공모전"
case .해커톤: "해커톤"
case .동아리: "동아리"
}
}
}

// MARK: Properties
weak var coordinator: PostListCoordinator?
private let postkind: PostKind
private let orderRelay: BehaviorRelay<PostOrder> = .init(value: .latest)

private var categoryID: Int {
Int(PostKind.allCases.firstIndex(of: postkind) ?? .zero) + 1
postkind.id
}

// MARK: UI
Expand All @@ -60,8 +46,8 @@ final class PostListViewController: BaseViewController<PostListReactor>, Coordin
}

// MARK: Initializer
init(reactor: PostListReactor, code: String) {
self.postkind = PostKind.init(rawValue: code) ?? .공모전
init(reactor: PostListReactor, postKind: PostKind) {
self.postkind = postKind

super.init()
self.reactor = reactor
Expand Down Expand Up @@ -108,7 +94,7 @@ final class PostListViewController: BaseViewController<PostListReactor>, Coordin
private func setupInitialState() {
scrollView.alpha = 0
orderDropDownMenu.alpha = 0
navigationBar.setNavigationTitle(postkind.title)
navigationBar.setNavigationTitle(postkind.rawValue)
}
}

Expand Down

0 comments on commit 2d76dbb

Please sign in to comment.