Skip to content

Commit

Permalink
fix(PPG/Event): change getEvents to use DTO
Browse files Browse the repository at this point in the history
  • Loading branch information
amarose committed Dec 12, 2024
1 parent 4ba6b84 commit dd60a2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion Sources/PPG_framework/Models/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@

import Foundation

public struct EventDTO {
init(event: Event) {
self.timestamp = event.timestamp
self.type = event.eventType.rawValue
self.campaign = event.campaign
self.button = event.button
self.sentAt = event.sentAt
}

var timestamp: String
var type: String
var campaign: String
var button: Int?
var sentAt: Date?
}

// Protocol defining the method for sending events.
protocol EventSender {
func send(event: Event, handler: @escaping (_ result: ActionResult) -> Void)
}

public class Event: Codable, CustomStringConvertible {
class Event: Codable, CustomStringConvertible {

public var eventType: EventType
public var timestamp: String // ISO8601 formatted timestamp
Expand Down Expand Up @@ -81,6 +97,10 @@ public class Event: Codable, CustomStringConvertible {
"""
}

public func toDTO() -> EventDTO {
return EventDTO(event: self)
}

func getKey() -> String {
return "\(eventType.rawValue)_\(button ?? 0)_\(campaign)"
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PPG_framework/PPG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public class PPG: NSObject, UNUserNotificationCenterDelegate {
ApiService.shared.sendBeacon(beacon: beacon, handler: handler)
}

public static func getEvents() -> [Event] {
return SharedData.shared.eventManager.getEvents()
public static func getEvents() -> [EventDTO] {
return SharedData.shared.eventManager.getEvents().map {$0.toDTO()}
}
}

0 comments on commit dd60a2a

Please sign in to comment.