Skip to content

Commit

Permalink
[Feat] Runnect#84 - 목표 보상 API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
dlwogus0128 committed Jan 12, 2023
1 parent 78b4f1a commit cf349b4
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
//

import UIKit

import SnapKit
import Then
import Kingfisher

// MARK: - GoalRewardInfoCVC

Expand All @@ -33,6 +35,35 @@ final class GoalRewardInfoCVC: UICollectionViewCell {
}
}

// MARK: - Methods

extension GoalRewardInfoCVC {
func setData(model: GoalRewardStamp) {
stampStandardLabel.text = model.id
setStampImageView(model: model, image: stampImageView)
}

func setStampImageView(model: GoalRewardStamp, image: UIImageView) {
let userStampList = model.id
print(userStampList)
print("")
let stampNameList = ["c1", "c2", "c3",
"s1", "s2", "s3",
"u1", "u2", "u3",
"r1", "r2", "r3"]

if userStampList.contains(stampNameList[0]) {
image.image = ImageLiterals.imgLock
} else {
image.image = ImageLiterals.imgStamp
}
}

func setStampNameLabel(model: GoalRewardInfoModel) {
stampStandardLabel.text = model.stampStandard
}
}

extension GoalRewardInfoCVC {

// MARK: - Layout Helpers
Expand All @@ -50,11 +81,4 @@ extension GoalRewardInfoCVC {
make.centerX.equalToSuperview()
}
}

// MARK: - General Helpers

func dataBind(model: GoalRewardInfoModel) {
stampImageView.image = model.stampImg
stampStandardLabel.text = model.stampStandard
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
//

import UIKit

import SnapKit
import Then
import Moya

final class GoalRewardInfoVC: UIViewController {

// MARK: - Properties
private var goalRewardProvider = MoyaProvider<MyPageRouter>(
plugins: [NetworkLoggerPlugin(verbose: true)]
)

var stampList: [GoalRewardInfoModel] = [
var stampNameList: [GoalRewardInfoModel] = [
GoalRewardInfoModel(stampImg: ImageLiterals.imgStampC1, stampStandard: "그린 코스 1개"),
GoalRewardInfoModel(stampImg: ImageLiterals.imgStampC2, stampStandard: "그린 코스 5개"),
GoalRewardInfoModel(stampImg: ImageLiterals.imgStampC3, stampStandard: "그린 코스 10개"),
Expand All @@ -28,6 +33,9 @@ final class GoalRewardInfoVC: UIViewController {
GoalRewardInfoModel(stampImg: ImageLiterals.imgStampR2, stampStandard: "달리기 10회")
]

private var goalRewardList = [GoalRewardStamp]()
private var isStampExistList = [Bool]()

// MARK: - Constants

final let stampInset: UIEdgeInsets = UIEdgeInsets(top: 32, left: 34, bottom: 10, right: 34)
Expand Down Expand Up @@ -57,8 +65,6 @@ final class GoalRewardInfoVC: UIViewController {
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.isScrollEnabled = true
collectionView.showsVerticalScrollIndicator = false
collectionView.delegate = self
collectionView.dataSource = self

return collectionView
}()
Expand All @@ -71,6 +77,48 @@ final class GoalRewardInfoVC: UIViewController {
setUI()
setLayout()
register()
getGoalRewardInfo()
}
}

// MARK: - Methods

extension GoalRewardInfoVC {
private func setData(goalRewardList: [GoalRewardStamp]) {
self.goalRewardList = goalRewardList
print(self.goalRewardList)
stampCollectionView.reloadData()
}

private func setDelegate() {
stampCollectionView.delegate = self
stampCollectionView.dataSource = self
}

private func register() {
stampCollectionView.register(GoalRewardInfoCVC.self,
forCellWithReuseIdentifier: GoalRewardInfoCVC.className)
}

private func setIsStampExistList(list: [GoalRewardStamp]) -> [Bool] {
let resultList = [Bool]()
let stampNameList = ["c1", "c2", "c3",
"s1", "s2", "s3",
"u1", "u2", "u3",
"r1", "r2", "r3"]
var i = 0

// while i < 15 {
// if list.contains() {
// resultList[i] = true
// i += 1
// } else {
// resultList[i] = false
// i += 1
// }
// }
//
return resultList
}
}

Expand Down Expand Up @@ -121,13 +169,6 @@ extension GoalRewardInfoVC {
make.bottom.equalToSuperview()
}
}

// MARK: - General Helpers

private func register() {
stampCollectionView.register(GoalRewardInfoCVC.self,
forCellWithReuseIdentifier: GoalRewardInfoCVC.className)
}
}

// MARK: - UICollectionViewDelegateFlowLayout
Expand All @@ -153,12 +194,44 @@ extension GoalRewardInfoVC: UICollectionViewDelegateFlowLayout {

extension GoalRewardInfoVC: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return stampList.count
return stampNameList.count
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let stampCell = collectionView.dequeueReusableCell(withReuseIdentifier: GoalRewardInfoCVC.className, for: indexPath) as? GoalRewardInfoCVC else { return UICollectionViewCell()}
stampCell.dataBind(model: stampList[indexPath.item])
stampCell.setData(model: goalRewardList[indexPath.item])
return stampCell
}
}

// MARK: - Network

extension GoalRewardInfoVC {
func getGoalRewardInfo() {
LoadingIndicator.showLoading()
goalRewardProvider.request(.getGoalRewardInfo) { [weak self] response in
LoadingIndicator.hideLoading()
guard let self = self else { return }
switch response {
case .success(let result):
let status = result.statusCode
if 200..<300 ~= status {
do {
let responseDto = try result.map(BaseResponse<GoalRewardInfoDto>.self)
guard let data = responseDto.data else { return }
self.setData(goalRewardList: data.stamps)
} catch {
print(error.localizedDescription)
}
}
if status >= 400 {
print("400 error")
self.showNetworkFailureToast()
}
case .failure(let error):
print(error.localizedDescription)
self.showNetworkFailureToast()
}
}
}
}

0 comments on commit cf349b4

Please sign in to comment.