From 0b74e6a822257a309f372845143b8d088d9bf683 Mon Sep 17 00:00:00 2001 From: hryeong66 Date: Tue, 26 Jul 2022 21:46:23 +0900 Subject: [PATCH] =?UTF-8?q?=20=E2=9C=85[CHORE]=20#285=20postDetail=20?= =?UTF-8?q?=EC=83=88=EB=A1=9C=EB=B0=94=EB=80=90=20dateModel=20ViewModel?= =?UTF-8?q?=EC=97=90=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Source/Models/PostDetailDataModel.swift | 7 +- .../ViewModels/PostDetailViewModel.swift | 66 +++++++++++++++++-- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/ChaRo-iOS/ChaRo-iOS/Source/Models/PostDetailDataModel.swift b/ChaRo-iOS/ChaRo-iOS/Source/Models/PostDetailDataModel.swift index c0c4367b..0a4c4036 100644 --- a/ChaRo-iOS/ChaRo-iOS/Source/Models/PostDetailDataModel.swift +++ b/ChaRo-iOS/ChaRo-iOS/Source/Models/PostDetailDataModel.swift @@ -65,9 +65,10 @@ struct PostDetailData: Codable { // MARK: - Course struct Course: Codable { - let address, latitude, longitude: String + let address, latitude, longitude: String? - func getPoint() -> CLLocationCoordinate2D{ - return CLLocationCoordinate2D(latitude: Double(latitude) ?? 0.0, longitude: Double(longitude) ?? 0.0) + func getPoint() -> CLLocationCoordinate2D { + return CLLocationCoordinate2D(latitude: Double(latitude ?? "0") ?? 0.0, + longitude: Double(longitude ?? "0") ?? 0.0) } } diff --git a/ChaRo-iOS/ChaRo-iOS/Source/ViewModels/PostDetailViewModel.swift b/ChaRo-iOS/ChaRo-iOS/Source/ViewModels/PostDetailViewModel.swift index 154cd8f0..3d037148 100644 --- a/ChaRo-iOS/ChaRo-iOS/Source/ViewModels/PostDetailViewModel.swift +++ b/ChaRo-iOS/ChaRo-iOS/Source/ViewModels/PostDetailViewModel.swift @@ -13,7 +13,8 @@ class PostDetailViewModel { let postId: Int var isFavorite: Bool = false var isStored: Bool = false - let postDetailSubject = ReplaySubject.create(bufferSize: 1) + var postDetailData: PostDetailDataModel? + let postDetailSubject = ReplaySubject.create(bufferSize: 1) init(postId: Int) { self.postId = postId @@ -21,27 +22,28 @@ class PostDetailViewModel { } struct Input { + } struct Output { - let postDetailSubject: ReplaySubject + let postDetailSubject: ReplaySubject } func transform(input: Input, disposeBag: DisposeBag) -> Output { return Output(postDetailSubject: postDetailSubject) } - - } extension PostDetailViewModel { func getPostDetailData(postId: Int) { - PostResultService.shared.getPostDetail(postId: postId) { response in + PostResultService.shared.getPostDetail(postId: postId) { [weak self] response in switch(response) { case .success(let resultData): - if let data = resultData as? PostDetailData{ - self.postDetailSubject.onNext(data) + print(resultData) + if let data = resultData as? PostDetailDataModel { + self?.postDetailData = data + self?.postDetailSubject.onNext(data) } case .requestErr(let message): print("requestErr", message) @@ -112,3 +114,53 @@ extension PostDetailViewModel { } } } + +// TODO: - 게시물 작성하기 마지막 눌렀을 때, 구경하기와 같은 뷰로 보이도록 +// public func setDataWhenConfirmPost(data: WritePostData, +// imageList: [UIImage], +// addressList: [AddressDataModel]) { +// isEditingMode = true +// isAuthor = true +// self.addressList = addressList +// self.imageList = imageList +// writedPostData = data +// +// let sendedPostDate = PostDetail(title: data.title, +// author: Constants.userId, +// isAuthor: true, +// profileImage: UserDefaults.standard.string(forKey: "profileImage")!, +// postingYear: Date.getCurrentYear(), +// postingMonth: Date.getCurrentMonth(), +// postingDay: Date.getCurrentDay(), +// isStored: false, +// isFavorite: false, +// likesCount: 0, +// images: [""], +// province: data.province, +// city: data.region, +// themes: data.theme, +// source: "", +// wayPoint: [""], +// destination: "", +// longtitude: [""], +// latitude: [""], +// isParking: data.isParking, +// parkingDesc: data.parkingDesc, +// warnings: data.warning, +// courseDesc: data.courseDesc) +// +// self.postData = sendedPostDate +// +// dump(writedPostData) +// +// print("넘겨져온 이미지야~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") +// print("imageList = \(imageList)") +// print("넘겨져온 이미지야~!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") +// +// var newAddressList :[Address] = [] +// for address in addressList { +// newAddressList.append(address.getAddressDataModel()) +// } +// +// writedPostData?.course = newAddressList +// }