Skip to content

Commit

Permalink
feat/#240 약속 정보 API 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
youz2me committed Jul 18, 2024
1 parent 48bf47b commit 6446233
Show file tree
Hide file tree
Showing 15 changed files with 315 additions and 109 deletions.
12 changes: 12 additions & 0 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
DD3F9DD22C485753008E1FF7 /* UtilService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3F9DD12C485753008E1FF7 /* UtilService.swift */; };
DD3F9DD42C4858A3008E1FF7 /* UtilTargetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3F9DD32C4858A3008E1FF7 /* UtilTargetType.swift */; };
DD3F9DD62C4988E2008E1FF7 /* RegisterMeetingsResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3F9DD52C4988E2008E1FF7 /* RegisterMeetingsResponseModel.swift */; };
DD3F9DD82C49C25D008E1FF7 /* PagePromiseServiceType.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD3F9DD72C49C25D008E1FF7 /* PagePromiseServiceType.swift */; };
DD41BEFA2C41D4160095A068 /* TardyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41BEF92C41D4160095A068 /* TardyView.swift */; };
DD41BEFC2C41D54D0095A068 /* TardyPenaltyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41BEFB2C41D54D0095A068 /* TardyPenaltyView.swift */; };
DD41BEFF2C41DAA40095A068 /* TardyEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD41BEFE2C41DAA40095A068 /* TardyEmptyView.swift */; };
Expand Down Expand Up @@ -304,6 +305,7 @@
DD3F9DD12C485753008E1FF7 /* UtilService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilService.swift; sourceTree = "<group>"; };
DD3F9DD32C4858A3008E1FF7 /* UtilTargetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilTargetType.swift; sourceTree = "<group>"; };
DD3F9DD52C4988E2008E1FF7 /* RegisterMeetingsResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RegisterMeetingsResponseModel.swift; sourceTree = "<group>"; };
DD3F9DD72C49C25D008E1FF7 /* PagePromiseServiceType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PagePromiseServiceType.swift; sourceTree = "<group>"; };
DD41BEF92C41D4160095A068 /* TardyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TardyView.swift; sourceTree = "<group>"; };
DD41BEFB2C41D54D0095A068 /* TardyPenaltyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TardyPenaltyView.swift; sourceTree = "<group>"; };
DD41BEFE2C41DAA40095A068 /* TardyEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TardyEmptyView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -764,6 +766,7 @@
DD39768D2C41CA0700E2A4C4 /* PagePromise */ = {
isa = PBXGroup;
children = (
DD3F9DD92C49CF05008E1FF7 /* Service */,
DD39768E2C41CABE00E2A4C4 /* ViewController */,
DD39768F2C41CAC700E2A4C4 /* ViewModel */,
DD3976902C41CACF00E2A4C4 /* View */,
Expand Down Expand Up @@ -855,6 +858,14 @@
path = ServiceType;
sourceTree = "<group>";
};
DD3F9DD92C49CF05008E1FF7 /* Service */ = {
isa = PBXGroup;
children = (
DD3F9DD72C49C25D008E1FF7 /* PagePromiseServiceType.swift */,
);
path = Service;
sourceTree = "<group>";
};
DD41BEFD2C41D85F0095A068 /* View */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1766,6 +1777,7 @@
DD3F9DD02C48571A008E1FF7 /* MeetingListServiceType.swift in Sources */,
A39F2B212C499CE5008DA5F5 /* SetReadyStatusInfoServiceType.swift in Sources */,
DE6D4D132C3F14D80005584B /* MeetingMemberCell.swift in Sources */,
DD3F9DD82C49C25D008E1FF7 /* PagePromiseServiceType.swift in Sources */,
DDAF1C932C3D6E3D008A37D3 /* PagePromiseViewController.swift in Sources */,
789D73BE2C47FE0F00C7077D /* AuthInterceptor.swift in Sources */,
789D73B32C47CC6D00C7077D /* LocalNotificationManager.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ final class AddPromiseCompleteViewController: BaseViewController {
rootViewController.navigationController?.pushViewController(
PagePromiseViewController(
promiseViewModel: PagePromiseViewModel(
promiseID: self.promiseID
promiseID: self.promiseID,
service: PromiseService()
)
),
animated: true
Expand Down
6 changes: 4 additions & 2 deletions KkuMulKum/Source/Home/ViewController/HomeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ extension HomeViewController: UICollectionViewDelegateFlowLayout {
) {
let pagePromiseViewController = PagePromiseViewController(
promiseViewModel: PagePromiseViewModel(
promiseID: viewModel.upcomingPromiseList.value?.data?.promises[indexPath.item].promiseID ?? 0
promiseID: viewModel.upcomingPromiseList.value?.data?.promises[indexPath.item].promiseID ?? 0,
service: PromiseService()
)
)

Expand Down Expand Up @@ -390,7 +391,8 @@ private extension HomeViewController {
func todayButtonDidTap(_ sender: UIButton) {
let viewController = PagePromiseViewController(
promiseViewModel: PagePromiseViewModel(
promiseID: viewModel.nearestPromise.value?.data?.promiseID ?? 0
promiseID: viewModel.nearestPromise.value?.data?.promiseID ?? 0,
service: PromiseService()
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ extension MeetingInfoViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let pagePromiseViewController = PagePromiseViewController(
promiseViewModel: PagePromiseViewModel(
promiseID: viewModel.meetingPromises[indexPath.item].promiseID
promiseID: viewModel.meetingPromises[indexPath.item].promiseID,
service: PromiseService()
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// PagePromiseServiceType.swift
// KkuMulKum
//
// Created by YOUJIM on 7/19/24.
//

import Foundation

protocol PagePromiseServiceType {
func fetchPromiseInfo(with promiseId: Int) async throws -> ResponseBodyDTO<PromiseInfoModel>?
}

extension PromiseService: PagePromiseServiceType {
func fetchPromiseInfo(with promiseId: Int) async throws -> ResponseBodyDTO<PromiseInfoModel>? {
return try await request(
with: .fetchPromiseInfo(
promiseID: promiseId
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ class PagePromiseViewController: BaseViewController {

private let promiseViewModel: PagePromiseViewModel

// TODO: 서버 연결 시 데이터 바인딩 필요
private var promiseViewControllerList: [BaseViewController] = []

private let promiseInfoViewController: PromiseInfoViewController

private let promiseInfoViewModel: PromiseInfoViewModel

private let readyStatusViewController: ReadyStatusViewController

private let readyStatusViewModel: ReadyStatusViewModel

private let tardyViewController: TardyViewController

private lazy var promiseSegmentedControl = PagePromiseSegmentedControl(
Expand All @@ -30,53 +35,36 @@ class PagePromiseViewController: BaseViewController {
navigationOrientation: .vertical
)

override func viewDidLoad() {
super.viewDidLoad()

setupNavigationBarBackButton()
}

// MARK: - LifeCycle

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

navigationController?.isNavigationBarHidden = false

}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

navigationController?.isNavigationBarHidden = true
}


// MARK: Initialize
// MARK: Initializer

init(promiseViewModel: PagePromiseViewModel) {
self.promiseViewModel = promiseViewModel

// TODO: 네트워크 통신 필요
promiseViewModel.fetchPromiseInfo(promiseID: promiseViewModel.promiseID)

promiseInfoViewModel = PromiseInfoViewModel(
promiseID: promiseViewModel.promiseID,
promiseInfoService: PromiseService()
)

promiseInfoViewController = PromiseInfoViewController(
promiseInfoViewModel: PromiseInfoViewModel(
promiseInfoService: MockPromiseInfoService(),
promiseID: promiseViewModel.promiseID.value
)
promiseInfoViewModel: promiseInfoViewModel
)

readyStatusViewModel = ReadyStatusViewModel(
readyStatusService: MockReadyStatusService(),
promiseID: promiseViewModel.promiseID
)

readyStatusViewController = ReadyStatusViewController(
readyStatusViewModel: ReadyStatusViewModel(
readyStatusService: PromiseService(),
promiseID: promiseViewModel.promiseID.value
)
readyStatusViewModel: readyStatusViewModel
)

tardyViewController = TardyViewController(
tardyViewModel: TardyViewModel(
tardyService: MockTardyService(),
promiseID: promiseViewModel.promiseID.value
promiseID: promiseViewModel.promiseID
)
)

Expand All @@ -94,6 +82,30 @@ class PagePromiseViewController: BaseViewController {
}


// MARK: - LifeCycle

override func viewDidLoad() {
super.viewDidLoad()

setupNavigationBarBackButton()
setupBindings()
}


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

navigationController?.isNavigationBarHidden = false

}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)

navigationController?.isNavigationBarHidden = true
}


// MARK: - Setup

override func setupView() {
Expand Down Expand Up @@ -148,7 +160,6 @@ class PagePromiseViewController: BaseViewController {
}

override func setupDelegate() {
promisePageViewController.delegate = self
promisePageViewController.dataSource = self
}
}
Expand Down Expand Up @@ -186,14 +197,6 @@ extension PagePromiseViewController {
}



// MARK: - UIPageViewControllerDelegate

extension PagePromiseViewController: UIPageViewControllerDelegate {

}


// MARK: - UIPageViewControllerDataSource

extension PagePromiseViewController: UIPageViewControllerDataSource {
Expand All @@ -211,3 +214,16 @@ extension PagePromiseViewController: UIPageViewControllerDataSource {
return nil
}
}

private extension PagePromiseViewController {
func setupBindings() {
promiseViewModel.promiseInfo.bind { [weak self] model in
guard let model else { return }
DispatchQueue.main.async {
self?.setupNavigationBarTitle(with: model.promiseName)
self?.promiseInfoViewModel.promiseInfo.value = model
self?.readyStatusViewModel.promiseName.value = model.promiseName
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ class PagePromiseViewModel {


// MARK: Property

private let service: PagePromiseServiceType

var currentPage = ObservablePattern<Int>(0)
var promiseID: ObservablePattern<Int>
let promiseID: Int
let currentPage = ObservablePattern<Int>(0)
let promiseInfo = ObservablePattern<PromiseInfoModel?>(nil)
let promiseName: String = "Test"


// MARK: Initialize

init(promiseID: Int) {
self.promiseID = ObservablePattern<Int>(promiseID)
init(promiseID: Int, service: PagePromiseServiceType) {
self.service = service
self.promiseID = promiseID
}
}

Expand All @@ -33,7 +37,19 @@ extension PagePromiseViewModel {
currentPage.value = index
}

func promiseIDDidChanged(id: Int) {
promiseID.value = id
func fetchPromiseInfo(promiseID: Int) {
Task {
do {
let result = try await service.fetchPromiseInfo(with: promiseID)

guard let success = result?.success,
success == true
else {
return
}

promiseInfo.value = result?.data
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SnapKit
class ParticipantCollectionViewCell: BaseCollectionViewCell {


// MARK: Property
// MARK: - Property

let profileImageView: UIImageView = UIImageView().then {
$0.backgroundColor = .gray1
Expand Down
10 changes: 5 additions & 5 deletions KkuMulKum/Source/Promise/PromiseInfo/View/PromiseInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PromiseInfoView: BaseView {

// MARK: Property

private let participantNumberLabel: UILabel = UILabel().then {
let participantNumberLabel: UILabel = UILabel().then {
$0.setText("약속 참여 인원 n명", style: .body01)
$0.setHighlightText("n명", style: .body01, color: .maincolor)
}
Expand Down Expand Up @@ -57,7 +57,7 @@ class PromiseInfoView: BaseView {
$0.setText("위치", style: .caption01, color: .maincolor)
}

private let locationContentLabel: UILabel = UILabel().then {
let locationContentLabel: UILabel = UILabel().then {
$0.setText("sss역 s번 출구", style: .body04, color: .gray7)
}

Expand All @@ -69,7 +69,7 @@ class PromiseInfoView: BaseView {
$0.setText("약속시간", style: .caption01, color: .maincolor)
}

private let timeContentLabel: UILabel = UILabel().then {
let timeContentLabel: UILabel = UILabel().then {
$0.setText("mm월 dd일 hh:mm", style: .body04, color: .gray7)
}

Expand All @@ -81,7 +81,7 @@ class PromiseInfoView: BaseView {
$0.setText("준비레벨", style: .caption01, color: .maincolor)
}

private let readyLevelContentLabel: UILabel = UILabel().then {
let readyLevelContentLabel: UILabel = UILabel().then {
$0.setText("LV n. sss", style: .body04, color: .gray7)
}

Expand All @@ -93,7 +93,7 @@ class PromiseInfoView: BaseView {
$0.setText("벌칙", style: .caption01, color: .maincolor)
}

private let penaltyLevelContentLabel: UILabel = UILabel().then {
let penaltyLevelContentLabel: UILabel = UILabel().then {
$0.setText("ssss하기", style: .body04, color: .gray7)
}

Expand Down
Loading

0 comments on commit 6446233

Please sign in to comment.