Skip to content

Commit

Permalink
feat/#64 yearReportCount, monthReportCount 서버 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
HEHEEUN committed Nov 28, 2024
1 parent 0dd0ae7 commit 633da6e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
4 changes: 3 additions & 1 deletion saftyReport/saftyReport/Source/Main/Cell/MyReportCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class MyReportCell: UICollectionViewCell {
}
}

func configure(with itemIndex: Int) {
func configure(with itemIndex: Int, yearReportCount: Int, monthReportCount: Int) {
let allViews: [UIView] = [
totalCountStackView,
myReportCountImageView,
Expand All @@ -195,13 +195,15 @@ class MyReportCell: UICollectionViewCell {
titleLabel.text = "나의 올해 신고"
totalCountStackView.isHidden = false
myReportCountImageView.isHidden = false
countLabel.text = "\(yearReportCount)"
myReportSubImageView.isHidden = false
reportCategoryStackView.isHidden = false
myReportCountImageView.isHidden = false
case 1:
titleLabel.text = "2024년 10월"
myMonthlyReportImageView.isHidden = false
myMonthlyReportCountStackView.isHidden = false
myMonthlyReportCountTargetLabel.text = "\(monthReportCount)"
subMonthlyReportCount.isHidden = false
default:
allViews.forEach { $0.isHidden = true }
Expand Down
43 changes: 40 additions & 3 deletions saftyReport/saftyReport/Source/Main/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ import SnapKit
import Then

class MainViewController: UIViewController {
private let networkManager = NetworkManager()

var yearReportCount: Int = 0
var monthReportCount: Int = 0
var milieage: Int = 0
var bannerList: [BannerList] = []

let customNavigationItem = CustomNavigationItem(title: "") // 반드시 타이틀 설정

private var isToggled = false
Expand Down Expand Up @@ -53,6 +60,13 @@ class MainViewController: UIViewController {
setUpNavigationBar()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
connectAPI()

collectionView.reloadData()
}

private func setUI() {
self.view.addSubviews(collectionView, floatingButton, tableView)
}
Expand Down Expand Up @@ -127,7 +141,7 @@ class MainViewController: UIViewController {
floatingButton.snp.updateConstraints {
$0.width.equalTo(newWidth)
}

UIView.animate(withDuration: 0.15) {
self.view.layoutIfNeeded() // 레이아웃 업데이트를 애니메이션으로 적용
self.floatingButton.transform = CGAffineTransform(rotationAngle: newAngle) // 45도 회전
Expand Down Expand Up @@ -182,15 +196,38 @@ class MainViewController: UIViewController {


// MARK: - Navigation Bar

private func setUpNavigationBar() {
navigationController?.setUpNavigationBarColor()
customNavigationItem.setUpNavigationBar(for: .leftRight)
customNavigationItem.setUpTitle(title: "")

navigationItem.title = customNavigationItem.title
navigationItem.leftBarButtonItem = customNavigationItem.leftBarButtonItem
navigationItem.rightBarButtonItem = customNavigationItem.rightBarButtonItem
}

// MARK: - Network

private func connectAPI() {
self.networkManager.homeAPI { [weak self] result in
guard let self = self else { return }

switch result {
case let .success(response):
yearReportCount = response.yearReportCount ?? 0
monthReportCount = response.monthReportCount ?? 0
milieage = response.mileage ?? 0
bannerList = response.bannerList
case let .failure(error):
print(error.localizedDescription)

}
DispatchQueue.main.async {
self.collectionView.reloadData()
}
}
}
}


Expand Down Expand Up @@ -256,7 +293,7 @@ extension MainViewController: UICollectionViewDataSource {
) as? MyReportCell else {
return UICollectionViewCell(frame: .zero)
}
cell.configure(with: indexPath.item)
cell.configure(with: indexPath.item, yearReportCount: yearReportCount, monthReportCount: monthReportCount)
return cell
case 1:
guard let cell = collectionView.dequeueReusableCell(
Expand Down

0 comments on commit 633da6e

Please sign in to comment.