forked from agarwalayush9/Shelves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataModel.swift
131 lines (111 loc) · 2.67 KB
/
DataModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// DataModel.swift
// Shelves-User
//
// Created by Jhanvi Jindal on 11/07/24.
//
import Foundation
struct Event: Identifiable {
let id = UUID()
let title: String
let date: String
let time: String
let location: String
let price: String
let imageName: String
func toDictionary() -> [String: Any] {
return [
"id": id.uuidString,
"title": title,
"date": date,
"time": time,
"location": location,
"price": price,
"imageName": imageName
]
}
}
struct Author: Identifiable {
let id = UUID()
let name: String
let title: String
let description: String
let image: String
}
struct Member {
var email: String
var firstName: String
var lastName: String
var phoneNumber: Int
var subscriptionPlan: String
var registeredEvents: [Event]
var genre: [Genre]
func toDictionary() -> [String: Any] {
var dictionary: [String: Any] = [
"email": email,
"firstName": firstName,
"lastName": lastName,
"phoneNumber": phoneNumber,
"subscriptionPlan": subscriptionPlan,
"genre": genre.map { $0.rawValue } // Convert Genre enum to raw values (String)
]
// Convert registeredEvents to an array of dictionaries
let eventsArray = registeredEvents.map { event -> [String: Any] in
return event.toDictionary()
}
dictionary["registeredEvents"] = eventsArray
return dictionary
}
}
struct BronzeSubscription {
var monthly: Int
var yearly: Int
var activeUsers: Int
func toDictionary() -> [String: Any] {
return [
"monthly": monthly,
"yearly": yearly,
"activeUsers": activeUsers
]
}
}
struct SilverSubscription {
var monthly: Int
var yearly: Int
var activeUser: Int
func toDictionary() -> [String: Any] {
return [
"monthly": monthly,
"yearly": yearly,
"activeUsers": activeUser
]
}
}
struct GoldSubscription {
var monthly: Int
var yearly: Int
var activeUsers: Int
func toDictionary() -> [String: Any] {
return [
"monthly": monthly,
"yearly": yearly,
"activeUsers": activeUsers
]
}
}
enum Genre: String, Codable {
case Horror
case Mystery
case Fiction
case Finance
case Fantasy
case Business
case Romance
case Psychology
case YoungAdult
case SelfHelp
case HistoricalFiction
case NonFiction
case ScienceFiction
case Literature
}