Skip to content

Commit

Permalink
Merge branch 'Dev' of github.com:DDD-Community/PINGPONG-IOS into Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Byeonjinha committed Nov 4, 2023
2 parents b705432 + d9a7d64 commit 40c36d5
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
//
// ArchiveModel.swift
// Model
//
// Created by 서원지 on 11/4/23.
// Copyright © 2023 Wonji Suh. All rights reserved.
//

import Foundation

// MARK: - Welcome
public struct ArchiveModel: Codable {
public let status: Int?
public let data: [ArchiveResponseModel]?
public let message: String?

public init(status: Int?, data: [ArchiveResponseModel]?, message: String?) {
self.status = status
self.data = data
self.message = message
}
}

// MARK: - Datum
public struct ArchiveResponseModel: Codable {
public let regDttm, modDttm: String?
public let regrID: String?
public let regrNm: String?
public let modrID: String?
public let modrNm: String?
public let rmk: String?
public let rowStatus: String?
public let quoteID: Int?
public let content: String?
public let author: String?
public let flavor: String?
public let source: String?
public let mood: String?

enum CodingKeys: String, CodingKey {
case regDttm, modDttm
case regrID = "regrId"
case regrNm
case modrID = "modrId"
case modrNm, rmk, rowStatus
case quoteID = "quoteId"
case content, author, flavor, source, mood
}

public init(regDttm: String?, modDttm: String?, regrID: String?, regrNm: String?, modrID: String?, modrNm: String?, rmk: String?, rowStatus: String?, quoteID: Int?, content: String?, author: String?, flavor: String?, source: String?, mood: String?) {
self.regDttm = regDttm
self.modDttm = modDttm
self.regrID = regrID
self.regrNm = regrNm
self.modrID = modrID
self.modrNm = modrNm
self.rmk = rmk
self.rowStatus = rowStatus
self.quoteID = quoteID
self.content = content
self.author = author
self.flavor = flavor
self.source = source
self.mood = mood
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// DeleteModel.swift
// Model
//
// Created by 서원지 on 11/5/23.
// Copyright © 2023 Wonji Suh. All rights reserved.
//

import Foundation

public struct DeleteModel: Codable {
public let status: Int?
public let data: DeleteResponseModel?
public let message: String?

public init(status: Int?, data: DeleteResponseModel?, message: String?) {
self.status = status
self.data = data
self.message = message
}
}

// MARK: - DataClass
public struct DeleteResponseModel: Codable {

public init() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,104 @@
//

import Foundation
import Combine
import Moya
import CombineMoya
import API
import Service
import Model

public class ArchiveViewViewModel: ObservableObject {

public init() { }

@Published public var isAscendingOrder = true

@Published public var archiveModel: ArchiveModel?
var archiveCancellable: AnyCancellable?

@Published public var deleteModel: DeleteModel?
var deleteCancellable: AnyCancellable?

public func archiveRequestToViewModel(_ list: ArchiveModel) {
self.archiveModel = list
}

public func archiveRequest(
userId: String,
completion: @escaping () -> Void

) async {
if let cancellable = archiveCancellable {
cancellable.cancel()
}

let provider = MoyaProvider<MyPageService>(plugins: [MoyaLoggingPlugin()])
archiveCancellable = provider.requestWithProgressPublisher(.myPageLikes(userId: userId))
.compactMap { $0.response?.data }
.receive(on: DispatchQueue.main)
.decode(type: ArchiveModel.self, decoder: JSONDecoder())
.sink(receiveCompletion: { [weak self] result in
switch result {
case .finished:
break
case .failure(let error):
print("네트워크 에러 \(error.localizedDescription)")
}
}, receiveValue: { [weak self] model in
if let status = model.status {
if status == NetworkCode.success.status {
self?.archiveRequestToViewModel(model)
print("마이페이지 좋아요 \(model)")
completion()
} else {

}
}
})

}

public func deleteToViewModel(_ list: DeleteModel){
self.deleteModel = list
}


public func deleteRequest(
likeId: String,
completion: @escaping () -> Void
) async {
if let cancellable = deleteCancellable {
cancellable.cancel()
}

let provider = MoyaProvider<MyPageService>(plugins: [MoyaLoggingPlugin()])
deleteCancellable = provider.requestWithProgressPublisher(.deleteLike(likeId: likeId))
.compactMap { $0.response?.data }
.receive(on: DispatchQueue.main)
.decode(type: DeleteModel.self, decoder: JSONDecoder())
.sink(receiveCompletion: { [weak self] result in
switch result {
case .finished:
break
case .failure(let error):
print("네트워크 에러 \(error.localizedDescription)")
}
}, receiveValue: { [weak self] model in
if let status = model.status {
if status == NetworkCode.success.status {
self?.deleteToViewModel(model)
print("마이페이지 좋아요 삭제 \(model)")
completion()
} else {
self?.deleteToViewModel(model)
print("마이페이지 좋아요 삭제 \(model)")
completion()
}
}
})



}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ public class ExploreViewModel: ObservableObject {
print("네트워크 에러 \(error.localizedDescription)")
}
}, receiveValue: { [weak self] model in
self?.searchRequestToViewModel(model)
print("검색 결과 \(model)")
completion()
if let status = model.status {
if status == NetworkCode.success.status {
self?.searchRequestToViewModel(model)
print("검색 결과 \(model)")
completion()
}
}
})

}

}

0 comments on commit 40c36d5

Please sign in to comment.