|
| 1 | +// |
| 2 | +// HistoryDTOModel.swift |
| 3 | +// Model |
| 4 | +// |
| 5 | +// Created by Wonji Suh on 3/26/26. |
| 6 | +// |
| 7 | + |
| 8 | +import Foundation |
| 9 | + |
| 10 | +public typealias HistoryDTOModel = BaseResponseDTO<HistoryPageResponseDTO> |
| 11 | + |
| 12 | +public struct HistoryPageResponseDTO: Decodable, Equatable { |
| 13 | + public let content: [HistoryItemResponseDTO] |
| 14 | + public let totalElements: Int |
| 15 | + public let totalPages: Int |
| 16 | + public let size: Int |
| 17 | + public let number: Int |
| 18 | + public let first: Bool |
| 19 | + public let last: Bool |
| 20 | + |
| 21 | + enum CodingKeys: String, CodingKey { |
| 22 | + case content |
| 23 | + case totalElements |
| 24 | + case totalPages |
| 25 | + case size |
| 26 | + case number |
| 27 | + case first |
| 28 | + case last |
| 29 | + case hasNext |
| 30 | + } |
| 31 | + |
| 32 | + public init( |
| 33 | + content: [HistoryItemResponseDTO], |
| 34 | + totalElements: Int, |
| 35 | + totalPages: Int, |
| 36 | + size: Int, |
| 37 | + number: Int, |
| 38 | + first: Bool, |
| 39 | + last: Bool |
| 40 | + ) { |
| 41 | + self.content = content |
| 42 | + self.totalElements = totalElements |
| 43 | + self.totalPages = totalPages |
| 44 | + self.size = size |
| 45 | + self.number = number |
| 46 | + self.first = first |
| 47 | + self.last = last |
| 48 | + } |
| 49 | + |
| 50 | + public init(from decoder: Decoder) throws { |
| 51 | + let container = try decoder.container(keyedBy: CodingKeys.self) |
| 52 | + let content = try container.decode([HistoryItemResponseDTO].self, forKey: .content) |
| 53 | + let totalElements = try container.decode(Int.self, forKey: .totalElements) |
| 54 | + let totalPages = try container.decode(Int.self, forKey: .totalPages) |
| 55 | + let size = try container.decode(Int.self, forKey: .size) |
| 56 | + let number = try container.decode(Int.self, forKey: .number) |
| 57 | + |
| 58 | + let hasNext = try container.decodeIfPresent(Bool.self, forKey: .hasNext) ?? false |
| 59 | + let first = try container.decodeIfPresent(Bool.self, forKey: .first) ?? (number == 0) |
| 60 | + let last = try container.decodeIfPresent(Bool.self, forKey: .last) ?? !hasNext |
| 61 | + |
| 62 | + self.init( |
| 63 | + content: content, |
| 64 | + totalElements: totalElements, |
| 65 | + totalPages: totalPages, |
| 66 | + size: size, |
| 67 | + number: number, |
| 68 | + first: first, |
| 69 | + last: last |
| 70 | + ) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +public struct HistoryItemResponseDTO: Decodable, Equatable { |
| 75 | + public let visitingHistoryID: Int |
| 76 | + public let stationID: Int |
| 77 | + public let stationName: String |
| 78 | + public let placeID: Int |
| 79 | + public let placeName: String |
| 80 | + public let placeCategory: String |
| 81 | + public let startTime: String |
| 82 | + public let endTime: String? |
| 83 | + public let trainDepartureTime: String |
| 84 | + public let totalDurationMinutes: Int |
| 85 | + public let isInProgress: Bool |
| 86 | + public let isSuccess: Bool |
| 87 | + public let createdAt: String |
| 88 | + |
| 89 | + enum CodingKeys: String, CodingKey { |
| 90 | + case visitingHistoryID = "visitingHistoryId" |
| 91 | + case stationID = "stationId" |
| 92 | + case stationName |
| 93 | + case placeID = "placeId" |
| 94 | + case placeName |
| 95 | + case placeCategory |
| 96 | + case startTime |
| 97 | + case endTime |
| 98 | + case trainDepartureTime |
| 99 | + case totalDurationMinutes |
| 100 | + case isInProgress |
| 101 | + case isSuccess |
| 102 | + case createdAt |
| 103 | + } |
| 104 | + |
| 105 | + public init( |
| 106 | + visitingHistoryID: Int, |
| 107 | + stationID: Int, |
| 108 | + stationName: String, |
| 109 | + placeID: Int, |
| 110 | + placeName: String, |
| 111 | + placeCategory: String, |
| 112 | + startTime: String, |
| 113 | + endTime: String?, |
| 114 | + trainDepartureTime: String, |
| 115 | + totalDurationMinutes: Int, |
| 116 | + isInProgress: Bool, |
| 117 | + isSuccess: Bool, |
| 118 | + createdAt: String |
| 119 | + ) { |
| 120 | + self.visitingHistoryID = visitingHistoryID |
| 121 | + self.stationID = stationID |
| 122 | + self.stationName = stationName |
| 123 | + self.placeID = placeID |
| 124 | + self.placeName = placeName |
| 125 | + self.placeCategory = placeCategory |
| 126 | + self.startTime = startTime |
| 127 | + self.endTime = endTime |
| 128 | + self.trainDepartureTime = trainDepartureTime |
| 129 | + self.totalDurationMinutes = totalDurationMinutes |
| 130 | + self.isInProgress = isInProgress |
| 131 | + self.isSuccess = isSuccess |
| 132 | + self.createdAt = createdAt |
| 133 | + } |
| 134 | +} |
0 commit comments