-
Notifications
You must be signed in to change notification settings - Fork 0
/
User.swift
111 lines (96 loc) · 3.37 KB
/
User.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
//
// User.swift
// VenopsMobileApp
//
// Created by Sean Murphy on 1/30/16.
// Copyright © 2016 Jay Maloney. All rights reserved.
//
import Foundation
import Firebase
class User: Equatable, FirebaseType{
private let emailKey = "email"
private let firstNameKey = "firstName"
private let middleNameKey = "middleName"
private let lastNameKey = "lastName"
private let usernameKey = "username"
private let dateOfBirthKey = "dateOfBirth"
private let cityKey = "city"
private let stateKey = "state"
private let zipcodeKey = "zipcode"
private let licenseNumberKey = "licenseNumber"
var email = ""
var firstName: String?
// var middleName: String?
var lastName: String?
var username: String?
var dateOfBirth: String?
var city: String?
var state: String?
var zipcode: String?
var licenseNumber: String?
var identifier: String?
var endpoint: String {
return "users"
}
var jsonValue: [String: AnyObject] {
var json: [String: AnyObject] = [emailKey: email]
if let firstName = firstName {
json.updateValue(firstName, forKey: firstNameKey)
}
// if let middleName = middleName {
// json.updateValue(middleName, forKey: middleNameKey)
// }
if let lastName = lastName {
json.updateValue(lastName, forKey: lastNameKey)
}
if let username = username {
json.updateValue(username, forKey: usernameKey)
}
if let dateOfBirth = dateOfBirth {
json.updateValue(dateOfBirth, forKey: dateOfBirthKey)
}
if let city = city {
json.updateValue(city, forKey: cityKey)
}
if let state = state {
json.updateValue(state, forKey: stateKey)
}
if let zipcode = zipcode {
json.updateValue(zipcode, forKey: zipcodeKey)
}
if let licenseNumber = licenseNumber {
json.updateValue(licenseNumber, forKey: licenseNumberKey)
}
return json
}
required init?(json: [String: AnyObject], identifier: String) {
guard let email = json[emailKey] as? String else { return nil }
self.email = email
self.firstName = json[firstNameKey] as? String
// self.middleName = json[middleNameKey] as? String
self.lastName = json[lastNameKey] as? String
self.username = json[usernameKey] as? String
self.dateOfBirth = json[dateOfBirthKey] as? String
self.city = json[cityKey] as? String
self.state = json[stateKey] as? String
self.zipcode = json[zipcodeKey] as? String
self.licenseNumber = json[licenseNumberKey] as? String
self.identifier = identifier
}
init(email: String, uid: String, firstName: String?, lastName: String?, username: String?, dateOfBirth: String?, city: String?, state: String?, zipcode: String?, licenseNumber: String?) {
self.email = email
self.firstName = firstName
// self.middleName = middleName
self.lastName = lastName
self.username = username
self.dateOfBirth = dateOfBirth
self.city = city
self.state = state
self.zipcode = zipcode
self.licenseNumber = licenseNumber
self.identifier = uid
}
}
func ==(lhs: User, rhs: User) -> Bool {
return (lhs.email == rhs.email) && (lhs.identifier == rhs.identifier)
}