diff --git a/KkuMulKum/Source/Promise/PromiseInfo/View/PromiseInfoView.swift b/KkuMulKum/Source/Promise/PromiseInfo/View/PromiseInfoView.swift index 04b4045f..023ad792 100644 --- a/KkuMulKum/Source/Promise/PromiseInfo/View/PromiseInfoView.swift +++ b/KkuMulKum/Source/Promise/PromiseInfo/View/PromiseInfoView.swift @@ -68,7 +68,7 @@ class PromiseInfoView: BaseView { $0.layer.cornerRadius = Screen.height(18) } - private let locationInfoLabel: UILabel = UILabel().then { + let locationInfoLabel: UILabel = UILabel().then { $0.setText("위치", style: .body05, color: .maincolor) } @@ -77,7 +77,7 @@ class PromiseInfoView: BaseView { $0.layer.cornerRadius = Screen.height(8) } - private let timeInfoLabel: UILabel = UILabel().then { + let timeInfoLabel: UILabel = UILabel().then { $0.setText("약속시간", style: .body05, color: .maincolor) } @@ -86,7 +86,7 @@ class PromiseInfoView: BaseView { $0.layer.cornerRadius = Screen.height(8) } - private let readyLevelInfoLabel: UILabel = UILabel().then { + let readyLevelInfoLabel: UILabel = UILabel().then { $0.setText("꾸레벨", style: .body05, color: .maincolor) } @@ -95,7 +95,7 @@ class PromiseInfoView: BaseView { $0.layer.cornerRadius = Screen.height(8) } - private let penaltyLevelInfoLabel: UILabel = UILabel().then { + let penaltyLevelInfoLabel: UILabel = UILabel().then { $0.setText("벌칙", style: .body05, color: .maincolor) } diff --git a/KkuMulKum/Source/Promise/PromiseInfo/ViewController/PromiseInfoViewController.swift b/KkuMulKum/Source/Promise/PromiseInfo/ViewController/PromiseInfoViewController.swift index 2267102b..5cebd940 100644 --- a/KkuMulKum/Source/Promise/PromiseInfo/ViewController/PromiseInfoViewController.swift +++ b/KkuMulKum/Source/Promise/PromiseInfo/ViewController/PromiseInfoViewController.swift @@ -42,6 +42,9 @@ class PromiseInfoViewController: BaseViewController { override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + + viewModel.fetchPromiseInfo() + viewModel.fetchPromiseParticipantList() } @@ -70,12 +73,77 @@ class PromiseInfoViewController: BaseViewController { extension PromiseInfoViewController { func setupBinding() { + viewModel.promiseInfo.bindOnMain(with: self) { owner, info in + guard let info else { return } + + owner.rootView.editButton.isHidden = !(info.isParticipant) + + owner.rootView.promiseNameLabel.setText(info.promiseName, style: .body01) + owner.rootView.locationContentLabel.setText(info.placeName, style: .body04) + owner.rootView.readyLevelContentLabel.setText(info.dressUpLevel, style: .body04) + owner.rootView.penaltyLevelContentLabel.setText(info.penalty, style: .body04) + owner.rootView.timeContentLabel.setText(info.time, style: .body04) + } + + viewModel.dDay.bindOnMain(with: self) { owner, dDay in + guard let dDay else { return } + + switch dDay { + case 1...: + owner.rootView.dDayLabel.setText("D+\(-dDay)", style: .body05, color: .gray4) + owner.rootView.promiseImageView.image = .imgPromiseGray + owner.rootView.promiseNameLabel.textColor = .gray4 + owner.rootView.locationInfoLabel.textColor = .gray4 + owner.rootView.timeInfoLabel.textColor = .gray4 + owner.rootView.readyLevelInfoLabel.textColor = .gray4 + owner.rootView.penaltyLevelInfoLabel.textColor = .gray4 + case 0: + owner.rootView.dDayLabel.setText("D-DAY", style: .body05, color: .mainorange) + case ..<0: + owner.rootView.dDayLabel.setText("D-\(dDay)", style: .body05, color: .gray5) + default: + break + } + } + viewModel.participants.bindOnMain(with: self) { owner, _ in + owner.rootView.participantCollectionView.reloadData() + } } @objc func editButtonDidTap() { + guard var dressUpLevel = viewModel.promiseInfo.value?.dressUpLevel else { return } + + let levels = ["LV1", "LV2", "LV3", "LV4", "FREE"] + if dressUpLevel.contains("마음대로 입고 오기") { + dressUpLevel = "FREE" + } else { + if let matched = levels.first(where: { level in + dressUpLevel.replacingOccurrences(of: " ", with: "").contains(level) + }) { + dressUpLevel = matched + } + } + + let viewController = EditPromiseViewController( + viewModel: EditPromiseViewModel( + promiseID: viewModel.promiseID, + promiseName: viewModel.promiseInfo.value?.promiseName, + placeName: viewModel.promiseInfo.value?.placeName, + xCoordinate: viewModel.promiseInfo.value?.x, + yCoordinate: viewModel.promiseInfo.value?.y, + address: viewModel.promiseInfo.value?.address, + roadAddress: viewModel.promiseInfo.value?.roadAddress, + time: viewModel.promiseInfo.value?.time, + dressUpLevel: dressUpLevel, + penalty: viewModel.promiseInfo.value?.penalty, + service: PromiseService() + ) + ) + + navigationController?.pushViewController(viewController, animated: true) } } @@ -87,7 +155,7 @@ extension PromiseInfoViewController: UICollectionViewDataSource { _ collectionView: UICollectionView, numberOfItemsInSection section: Int ) -> Int { - return 0 + return viewModel.participants.value.count } func collectionView( @@ -101,6 +169,14 @@ extension PromiseInfoViewController: UICollectionViewDataSource { return UICollectionViewCell() } + let info = viewModel.participants.value[indexPath.row] + + cell.userNameLabel.setText(info.name, style: .caption02, color: .gray6) + cell.profileImageView.kf.setImage( + with: URL(string: info.profileImageURL ?? ""), + placeholder: UIImage.imgProfile + ) + return cell } } diff --git a/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift b/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift index 7096d710..20123162 100644 --- a/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift +++ b/KkuMulKum/Source/Promise/ViewModel/PromiseViewModel.swift @@ -14,6 +14,8 @@ class PromiseViewModel { let promiseID: Int let promiseInfo = ObservablePattern(nil) + let participants = ObservablePattern<[Participant]>([]) + let dDay = ObservablePattern(nil) private let service: PromiseServiceProtocol @@ -29,6 +31,24 @@ class PromiseViewModel { // MARK: - Extension +private extension PromiseViewModel { + func calculateDday() { + let calendar = Calendar.current + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" + dateFormatter.locale = Locale(identifier: "ko_KR") + dateFormatter.timeZone = TimeZone(identifier: "Asia/Seoul") + + guard let dateWithTime = dateFormatter.date(from: promiseInfo.value?.time ?? "") else { return } + + let dateOnly = calendar.startOfDay(for: dateWithTime) + let today = calendar.startOfDay(for: Date()) + let components = calendar.dateComponents([.day], from: today, to: dateOnly) + + dDay.value = components.day + } +} + extension PromiseViewModel { /// 약속 상세 정보 조회 API 구현 함수 func fetchPromiseInfo() { @@ -40,16 +60,15 @@ extension PromiseViewModel { success == true else { print(">>>>> \(String(describing: result)) : \(#function)") - return } promiseInfo.value = result?.data + + calculateDday() } catch { print(">>>>> \(error.localizedDescription) : \(#function)") } - - } } @@ -57,13 +76,21 @@ extension PromiseViewModel { func fetchPromiseParticipantList() { Task { do { - let responseBody = try await service.fetchPromiseParticipantList(with: promiseID) + let result = try await service.fetchPromiseParticipantList(with: promiseID) - guard let success = responseBody?.success, - success == true + guard let success = result?.success, + success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") + return + } + + guard let data = result?.data else { + print(">>>>> \("데이터 없음") : \(#function)") return } + + participants.value = data.participants } catch { print(">>>>> \(error.localizedDescription) : \(#function)") } @@ -74,11 +101,12 @@ extension PromiseViewModel { func fetchMyReadyStatus() { Task { do { - let responseBody = try await service.fetchMyReadyStatus(with: promiseID) + let result = try await service.fetchMyReadyStatus(with: promiseID) - guard let success = responseBody?.success, + guard let success = result?.success, success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") return } } catch { @@ -91,11 +119,12 @@ extension PromiseViewModel { func updatePreparationStatus() { Task { do { - let responseBody = try await service.updatePreparationStatus(with: promiseID) + let result = try await service.updatePreparationStatus(with: promiseID) - guard let success = responseBody?.success, + guard let success = result?.success, success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") return } } @@ -109,11 +138,12 @@ extension PromiseViewModel { func updateDepartureStatus() { Task { do { - let responseBody = try await service.updateDepartureStatus(with: promiseID) + let result = try await service.updateDepartureStatus(with: promiseID) - guard let success = responseBody?.success, + guard let success = result?.success, success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") return } } @@ -127,11 +157,12 @@ extension PromiseViewModel { func updateArrivalStatus() { Task { do { - let responseBody = try await service.updateArrivalStatus(with: promiseID) + let result = try await service.updateArrivalStatus(with: promiseID) - guard let success = responseBody?.success, + guard let success = result?.success, success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") return } } @@ -145,11 +176,12 @@ extension PromiseViewModel { func fetchTardyInfo() { Task { do { - let responseBody = try await service.fetchTardyInfo(with: promiseID) + let result = try await service.fetchTardyInfo(with: promiseID) - guard let success = responseBody?.success, + guard let success = result?.success, success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") return } } catch { @@ -162,11 +194,12 @@ extension PromiseViewModel { func updatePromiseCompletion() { Task { do { - let responseBody = try await service.updatePromiseCompletion(with: promiseID) + let result = try await service.updatePromiseCompletion(with: promiseID) - guard let success = responseBody?.success, + guard let success = result?.success, success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") return } } catch { @@ -184,6 +217,7 @@ extension PromiseViewModel { guard let success = result?.success, success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") return } } catch { @@ -201,6 +235,7 @@ extension PromiseViewModel { guard let success = result?.success, success == true else { + print(">>>>> \(String(describing: result)) : \(#function)") return } } catch {