-
Notifications
You must be signed in to change notification settings - Fork 24
박스오피스 앱 [STEP 4] Matthew, Kyle #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: d_Matthew
Are you sure you want to change the base?
Changes from 36 commits
b6b4dc6
dfbeca1
cf250e9
7fa5b74
553324d
4cdee98
2e5a676
471108a
0f1d566
cac53ec
d8d52e6
73a4e21
bb09d06
0ac9e35
8f239b1
58db67d
60eafb3
186da18
4129046
0dfffa6
a7b94c1
12ed889
217aa92
85d731a
4fa307a
fd6e46b
a49e293
8df6464
fa5fcf2
85d4759
5a36a52
e4e760d
c7dcd5c
1419c9c
8025c2a
296fc81
a15fe3a
c5f2c2b
7afcf0c
5356d9c
9b840be
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // | ||
| // BoxOfficeDetailViewController.swift | ||
| // BoxOffice | ||
| // | ||
| // Created by Matthew on 3/8/24. | ||
| // | ||
|
|
||
| import UIKit | ||
|
|
||
| final class BoxOfficeDetailViewController: UIViewController { | ||
| private let movieName: String | ||
| private let movieCode: String | ||
| private let movieManager: MovieManager | ||
| private let scrollView = BoxOfficeDetailView() | ||
|
|
||
| init( | ||
| movieName: String, | ||
| movieCode: String, | ||
| movieManager: MovieManager | ||
| ) { | ||
| self.movieName = movieName | ||
| self.movieCode = movieCode | ||
| self.movieManager = movieManager | ||
| super.init(nibName: nil, bundle: nil) | ||
| } | ||
|
|
||
| required init?(coder: NSCoder) { | ||
| fatalError("init(coder:) has not been implemented") | ||
| } | ||
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| setupView() | ||
| fetchBoxOfficeDetailData() | ||
| } | ||
| } | ||
|
|
||
| private extension BoxOfficeDetailViewController { | ||
| func setupView() { | ||
| LoadingIndicatorView.showLoading() | ||
| view = scrollView | ||
| view.backgroundColor = .white | ||
| self.title = movieName | ||
| } | ||
|
|
||
| func fetchBoxOfficeDetailData() { | ||
| Task { | ||
| do { | ||
| try await fetchMoiveImageURL() | ||
| try await fetchMovieInfo() | ||
| try await setupMovieImage() | ||
| } catch { | ||
| print(error.localizedDescription) | ||
| } | ||
| LoadingIndicatorView.hideLoading() | ||
| } | ||
|
Comment on lines
+47
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 로딩 인디케이터가 사라져야 하는 시점이 언제일지 다시 한번 확인해보세요~ |
||
| } | ||
|
|
||
| func fetchMovieInfo() async throws { | ||
| let data = try await movieManager.fetchMovieInfoResultData(code: movieCode) | ||
| self.scrollView.setupDetailView(data: data) | ||
| } | ||
|
|
||
| func fetchMoiveImageURL() async throws { | ||
| try await movieManager.fetchMoiveImageURL(movieName: movieName) | ||
| } | ||
|
|
||
| func setupMovieImage() async throws { | ||
| guard let data = try await movieManager.fetchImageData() else { return } | ||
| self.scrollView.setupImage(image: UIImage(data: data)) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,10 +27,7 @@ final class BoxOfficeViewController: UIViewController { | |
|
|
||
| override func viewDidLoad() { | ||
| super.viewDidLoad() | ||
| boxOfficeListView.boxOfficeListDelegate = self | ||
| boxOfficeListView.delegate = self | ||
| boxOfficeListView.dataSource = dataSource | ||
| view = boxOfficeListView | ||
| setupBoxOfficeListView() | ||
| setupBoxOfficeData() | ||
| } | ||
| } | ||
|
|
@@ -40,13 +37,22 @@ private extension BoxOfficeViewController { | |
| self.title = Date.titleDateFormatter.string(from: date) | ||
| } | ||
|
|
||
| func setupBoxOfficeListView() { | ||
| LoadingIndicatorView.showLoading() | ||
| boxOfficeListView.boxOfficeListDelegate = self | ||
| boxOfficeListView.delegate = self | ||
| boxOfficeListView.dataSource = dataSource | ||
| view = boxOfficeListView | ||
| } | ||
|
Comment on lines
40
to
38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 비슷한 역할을 하는 것들끼리 묶어두셨네요! 좋은 방법인 것 같습니다. |
||
|
|
||
| func setupBoxOfficeData() { | ||
| movieManager.fetchBoxOfficeResultData(date: Date.movieDateToString) { result in | ||
| switch result { | ||
| case .success(let success): | ||
| self.reloadCollectionListData(result: success) | ||
| case .failure(let failure): | ||
| print("fetchBoxOfficeResultData 실패: \(failure)") | ||
| Task { | ||
| do { | ||
| let result = try await movieManager.fetchBoxOfficeResultData(date: Date.movieDateToString) | ||
| self.reloadCollectionListData(result: result) | ||
| LoadingIndicatorView.hideLoading() | ||
| } catch { | ||
| print(error.localizedDescription) | ||
| } | ||
|
Comment on lines
+41
to
48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 로딩 인디케이터가 사라져야 하는 시점이 언제일지 다시 한번 확인해보세요~ |
||
| } | ||
| } | ||
|
|
@@ -60,27 +66,26 @@ private extension BoxOfficeViewController { | |
| } | ||
|
|
||
| func updateBoxOfficeList() { | ||
| movieManager.fetchBoxOfficeResultData(date: Date.movieDateToString) { [weak self] result in | ||
| switch result { | ||
| case .success(let result): | ||
| DispatchQueue.main.async { | ||
| self?.applyBoxOfficeList(result: result) | ||
| guard | ||
| let date = result.showRange.toDateFromRange() | ||
| else { | ||
| return | ||
| } | ||
| self?.configureNavigation(date: date) | ||
| Task { | ||
| do { | ||
| let result = try await self.movieManager.fetchBoxOfficeResultData( | ||
| date: Date.movieDateToString | ||
| ) | ||
| self.applyBoxOfficeList(result: result) | ||
| guard | ||
| let date = result.showRange.toDateFromRange() | ||
| else { | ||
| return | ||
| } | ||
| case .failure(let error): | ||
| self.configureNavigation(date: date) | ||
| } catch { | ||
| print(error.localizedDescription) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func reloadCollectionListData(result: BoxOfficeResult) { | ||
| DispatchQueue.main.async { | ||
| self.boxOfficeListView.indicatorView.stopAnimating() | ||
| self.configureNavigation(date: Date.yesterday) | ||
| self.applyBoxOfficeList(result: result) | ||
| self.boxOfficeListView.isScrollEnabled = true | ||
|
|
@@ -90,7 +95,17 @@ private extension BoxOfficeViewController { | |
|
|
||
| extension BoxOfficeViewController: UICollectionViewDelegate { | ||
| func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { | ||
| self.navigationController?.popViewController(animated: true) | ||
| guard | ||
| let data = movieManager.setupBoxOfficeDetailData(for: indexPath.row) | ||
| else { | ||
| return | ||
| } | ||
| let detailViewController = BoxOfficeDetailViewController( | ||
| movieName: data.movieName, | ||
| movieCode: data.movieCode, | ||
| movieManager: movieManager | ||
| ) | ||
| self.navigationController?.pushViewController(detailViewController, animated: true) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // | ||
| // Document.swift | ||
| // BoxOffice | ||
| // | ||
| // Created by 강창현 on 3/8/24. | ||
| // | ||
|
|
||
| struct Document: Codable { | ||
| let collection: String | ||
| let thumbnailURL: String | ||
| let imageURL: String | ||
| let width: Int | ||
| let height: Int | ||
| let displaySiteName: String | ||
| let docURL: String | ||
| let datetime: String | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case collection | ||
| case thumbnailURL = "thumbnail_url" | ||
| case imageURL = "image_url" | ||
| case width | ||
| case height | ||
| case displaySiteName = "display_sitename" | ||
| case docURL = "doc_url" | ||
| case datetime | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // | ||
| // Meta.swift | ||
| // BoxOffice | ||
| // | ||
| // Created by 강창현 on 3/8/24. | ||
| // | ||
|
|
||
| struct Meta: Codable { | ||
| let totalCount: Int | ||
| let pageableCount: Int | ||
| let isEnd: Bool | ||
|
|
||
| enum CodingKeys: String, CodingKey { | ||
| case isEnd = "is_end" | ||
| case pageableCount = "pageable_count" | ||
| case totalCount = "total_count" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // | ||
| // MovieImage.swift | ||
| // BoxOffice | ||
| // | ||
| // Created by 강창현 on 3/8/24. | ||
| // | ||
|
|
||
| struct MovieImage: Codable { | ||
| let meta: Meta | ||
| let documents: [Document] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BoxOfficeDetailView가 ScrollView를 상속받고 있긴 하지만 하는 역할은 영화 상세 페이지에 대한 UI가 담겨 있는 것 같습니다.
그에 맞게 네이밍이 수정되면 좋을 것 같아요.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵!
boxOfficeDetaiView로 수정하여 반영하도록 하겠습니다~!