Skip to content

Commit 2d76dbb

Browse files
committed
[ITDS-73] refactor: #56 - PostKind를 DomainLayer로 분리
1 parent f0cbd57 commit 2d76dbb

File tree

8 files changed

+62
-40
lines changed

8 files changed

+62
-40
lines changed

Targets/DesignSystem/Sources/Component/Home/PostCollectionView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public final class PostCollectionView: UIView {
5050
ofKind: UICollectionView.elementKindSectionHeader,
5151
for: indexPath)
5252
let sectionModel = dataSource.sectionModels[indexPath.section]
53-
header.setData(title: sectionModel.header, summary: sectionModel.summary)
53+
header.setData(title: sectionModel.kind.title, summary: sectionModel.kind.summary)
5454
header.tapObservable
5555
.map { indexPath }
5656
.bind(to: headerTapRelay)

Targets/DomainLayer/Sources/Entities/PostCellData.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public extension PostCellData {
4747
// MARK: - toPostSection
4848

4949
public extension Array<PostCellData> {
50-
func toPostSection(header: String, summary: String) -> PostSection {
51-
.init(header: header, summary: summary, items: self)
50+
func toPostSection(kind: PostKind) -> PostSection {
51+
.init(kind: kind, items: self)
5252
}
5353
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// PostKind.swift
3+
// DomainLayer
4+
//
5+
// Created by 이원빈 on 1/17/25.
6+
// Copyright © 2025 MOZIP. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public enum PostKind: String, CaseIterable {
12+
case 공모전
13+
case 해커톤
14+
case 동아리
15+
16+
public var id: Int {
17+
switch self {
18+
case .공모전: 1
19+
case .해커톤: 2
20+
case .동아리: 3
21+
}
22+
}
23+
public var title: String {
24+
switch self {
25+
case .공모전: "공모전 📑"
26+
case .해커톤: "해커톤 🏆"
27+
case .동아리: "IT 동아리 💻"
28+
}
29+
}
30+
31+
public var summary: String {
32+
switch self {
33+
case .공모전: "커리어 성장을 위한 IT 공모전 모음"
34+
case .해커톤: "단기간 프로젝트를 경험할 수 있는 해커톤"
35+
case .동아리: "사이드 프로젝트 경험을 쌓는 IT 동아리"
36+
}
37+
}
38+
}

Targets/DomainLayer/Sources/Entities/PostSection.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
import RxDataSources
1010

1111
public struct PostSection: Equatable {
12-
public let header: String
13-
public let summary: String
12+
public let kind: PostKind
1413
public var items: [Item]
1514
}
1615

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

2827
public extension PostSection {
29-
static func stub(header: String = "공모전",
30-
summary: String = "커리어 성장을 위한 IT 공모전 모음",
28+
static func stub(kind: PostKind = .공모전,
3129
items: [PostCellData] = [.stub(), .stub(), .stub(), .stub(), .stub()]) -> Self {
32-
.init(header: header, summary: summary, items: items)
30+
.init(kind: kind, items: items)
3331
}
3432
}

Targets/PresentationLayer/Sources/Home/Coordinator/HomeCoordinator.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import DomainLayer
1111
import UIKit
1212

1313
public protocol HomeCoordinatorType: CoordinatorType {
14-
func pushPostList(code: String)
14+
func pushPostList(postKind: PostKind)
1515
func pushLoginPage()
1616
func pushMyPage()
1717
func pushPostDetail(id: Int)
@@ -38,10 +38,10 @@ final class HomeCoordinator: HomeCoordinatorType {
3838

3939
func didFinish() {}
4040

41-
func pushPostList(code: String) {
41+
func pushPostList(postKind: PostKind) {
4242
let coordinator = PostListCoordinator(navigationController: navigationController)
4343
coordinator.parentCoordinator = self
44-
coordinator.start(with: code)
44+
coordinator.start(with: postKind)
4545
self.addChild(coordinator)
4646
}
4747

Targets/PresentationLayer/Sources/Home/Reactor/HomeReactor.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ final class HomeReactor: Reactor {
4848
struct State {
4949
var isSuccessPostFetch: Bool = false
5050
var isSuccessBannerFetch: Bool = false
51-
var postHeaderTitles: [String] = []
52-
var selectedCell: PostCellData?
51+
var postHeaders: [PostKind] = []
52+
var selectedCell: PostCellData?
5353

5454
var postSections: [PostSection] = []
5555
var banners: [BannerCellData] = []
@@ -71,7 +71,7 @@ final class HomeReactor: Reactor {
7171
switch mutation {
7272
case let .setPosts(data):
7373
newState.postSections = data
74-
newState.postHeaderTitles = data.map { $0.header }
74+
newState.postHeaders = data.map { $0.kind }
7575
newState.isSuccessPostFetch = true
7676
case let .setBanners(data):
7777
newState.banners = data
@@ -102,9 +102,9 @@ final class HomeReactor: Reactor {
102102
)
103103
.map { (firstGroup, secondGroup, thirdGroup) in
104104
.setPosts(data: [
105-
firstGroup.toPostSection(header: "공모전 📑", summary: "커리어 성장을 위한 IT 공모전 모음"),
106-
secondGroup.toPostSection(header: "해커톤 🏆", summary: "단기간 프로젝트를 경험할 수 있는 해커톤"),
107-
thirdGroup.toPostSection(header: "IT 동아리 💻", summary: "사이드 프로젝트 경험을 쌓는 IT 동아리")
105+
firstGroup.toPostSection(kind: .공모전),
106+
secondGroup.toPostSection(kind: .해커톤),
107+
thirdGroup.toPostSection(kind: .동아리)
108108
])
109109
}
110110
// TODO: .catch { error in ... } 에러처리 필요.

Targets/PresentationLayer/Sources/PostList/Coordinator/PostListCoordinator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import DomainLayer
1111
import UIKit
1212

1313
protocol PostListCoordinatorType: CoordinatorType {
14-
func start(with code: String)
14+
func start(with postKind: PostKind)
1515
func pushPostDetail(id: Int)
1616
}
1717

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

35-
func start(with code: String) {
36-
let vc = postListViewController(with: code)
35+
func start(with postKind: PostKind) {
36+
let vc = postListViewController(with: postKind)
3737
navigationController.pushViewController(vc, animated: true)
3838
}
3939

@@ -61,12 +61,12 @@ final class PostListCoordinator: PostListCoordinatorType {
6161

6262
// MARK: - Private
6363
private extension PostListCoordinator {
64-
func postListViewController(with code: String) -> PostListViewController {
64+
func postListViewController(with postKind: PostKind) -> PostListViewController {
6565
guard let fetchPostListUseCase = DIContainer.shared.resolve(type: FetchPostListUseCaseType.self) else {
6666
fatalError()
6767
}
6868
let reactor = PostListReactor(fetchPostListUseCase: fetchPostListUseCase)
69-
let viewController = PostListViewController(reactor: reactor, code: code)
69+
let viewController = PostListViewController(reactor: reactor, postKind: postKind)
7070
viewController.coordinator = self
7171
return viewController
7272
}

Targets/PresentationLayer/Sources/PostList/View/PostListViewController.swift

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,13 @@ import RxCocoa
1717

1818
final class PostListViewController: BaseViewController<PostListReactor>, Coordinatable {
1919

20-
enum PostKind: String, CaseIterable {
21-
case 공모전 = "공모전 📑"
22-
case 해커톤 = "해커톤 🏆"
23-
case 동아리 = "IT 동아리 💻"
24-
25-
var title: String {
26-
switch self {
27-
case .공모전: "공모전"
28-
case .해커톤: "해커톤"
29-
case .동아리: "동아리"
30-
}
31-
}
32-
}
33-
3420
// MARK: Properties
3521
weak var coordinator: PostListCoordinator?
3622
private let postkind: PostKind
3723
private let orderRelay: BehaviorRelay<PostOrder> = .init(value: .latest)
3824

3925
private var categoryID: Int {
40-
Int(PostKind.allCases.firstIndex(of: postkind) ?? .zero) + 1
26+
postkind.id
4127
}
4228

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

6248
// MARK: Initializer
63-
init(reactor: PostListReactor, code: String) {
64-
self.postkind = PostKind.init(rawValue: code) ?? .공모전
49+
init(reactor: PostListReactor, postKind: PostKind) {
50+
self.postkind = postKind
6551

6652
super.init()
6753
self.reactor = reactor
@@ -108,7 +94,7 @@ final class PostListViewController: BaseViewController<PostListReactor>, Coordin
10894
private func setupInitialState() {
10995
scrollView.alpha = 0
11096
orderDropDownMenu.alpha = 0
111-
navigationBar.setNavigationTitle(postkind.title)
97+
navigationBar.setNavigationTitle(postkind.rawValue)
11298
}
11399
}
114100

0 commit comments

Comments
 (0)