Skip to content

Commit

Permalink
✅[CHORE] #285 postDetail 새로바뀐 dateModel ViewModel에 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
hryeong66 committed Jul 26, 2022
1 parent daaee9b commit 0b74e6a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
7 changes: 4 additions & 3 deletions ChaRo-iOS/ChaRo-iOS/Source/Models/PostDetailDataModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
66 changes: 59 additions & 7 deletions ChaRo-iOS/ChaRo-iOS/Source/ViewModels/PostDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,37 @@ class PostDetailViewModel {
let postId: Int
var isFavorite: Bool = false
var isStored: Bool = false
let postDetailSubject = ReplaySubject<PostDetailData>.create(bufferSize: 1)
var postDetailData: PostDetailDataModel?
let postDetailSubject = ReplaySubject<PostDetailDataModel>.create(bufferSize: 1)

init(postId: Int) {
self.postId = postId
getPostDetailData(postId: postId)
}

struct Input {

}

struct Output {
let postDetailSubject: ReplaySubject<PostDetailData>
let postDetailSubject: ReplaySubject<PostDetailDataModel>
}

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)
Expand Down Expand Up @@ -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
// }

0 comments on commit 0b74e6a

Please sign in to comment.