Skip to content

Commit

Permalink
🪛[chore] : bake model 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy-wonji committed Nov 4, 2023
1 parent d9a7d64 commit c18c329
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// BakeModel.swift
// Model
//
// Created by 서원지 on 11/5/23.
// Copyright © 2023 Wonji Suh. All rights reserved.
//

import Foundation

// MARK: - Welcome
public struct BakeModel: Codable {
public let status: Int?
public let data: BakeResponseModel?
public let message: String?

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

// MARK: - DataClass
struct BakeResponseModel: Codable {
public let regDttm, modDttm, 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, author, flavor, source: String?
public let mood: String?
public let likeYn: Bool?

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, likeYn
}

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?, likeYn: Bool?) {
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
self.likeYn = likeYn
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ struct FamousSayingBakeCardView: View {
bakeViewModel.bakeQuoteRequest(userId: "423",
flavor: (viewModel.selectFlavor?.type.english) ?? "",
source: (viewModel.selectSource?.type.english) ?? "",
mood: (viewModel.selectMood?.type.english) ?? "")
mood: (viewModel.selectMood?.type.english) ?? "", completion: {

})
authViewModel.searchUserIdRequest(uid: "423")
}
.onDisappear {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class BakeViewModel: ObservableObject {
@Published public var commonCodeModel: CommonCdModel?
var commonCodeCancellable: AnyCancellable?

@Published public var bakeQuoteModel: BaseModel?
@Published public var bakeQuoteModel: BakeModel?
var bakeQuoteCancellable: AnyCancellable?


Expand Down Expand Up @@ -66,11 +66,17 @@ public class BakeViewModel: ObservableObject {
})
}

public func bakequoteCodeToViewModel(_ list: BaseModel) {
public func bakequoteCodeToViewModel(_ list: BakeModel) {
self.bakeQuoteModel = list
}

public func bakeQuoteRequest(userId: String, flavor: String, source: String, mood: String) {
public func bakeQuoteRequest(
userId: String,
flavor: String,
source: String,
mood: String,
completion: @escaping () -> Void
) {
if let cancellable = bakeQuoteCancellable {
cancellable.cancel()
}
Expand All @@ -79,7 +85,7 @@ public class BakeViewModel: ObservableObject {
bakeQuoteCancellable = provider.requestWithProgressPublisher(.homeBakeQuote(userId: userId, flavor: flavor, source: source, mood: mood))
.compactMap { $0.response?.data}
.receive(on: DispatchQueue.main)
.decode(type: BaseModel.self, decoder: JSONDecoder())
.decode(type: BakeModel.self, decoder: JSONDecoder())
.sink(receiveCompletion: { [weak self] result in
switch result {
case .finished:
Expand All @@ -88,9 +94,13 @@ public class BakeViewModel: ObservableObject {
print("네트워크에러", error.localizedDescription)
}
}, receiveValue: { [weak self] model in
self?.bakequoteCodeToViewModel(model)
os_log("홈화면 랜덤 명언 굽기")
print("홈화면 랜덤 명언 굽기", model)
if let status = model.status {
if status == NetworkCode.success.status {
self?.bakequoteCodeToViewModel(model)
print("홈화면 랜덤 명언 굽기", model)
completion()
}
}
})
}
}
Expand Down

0 comments on commit c18c329

Please sign in to comment.