Skip to content

Commit 668258f

Browse files
author
Anand
committed
ref issue #28 - Enhanced schema for entries table plus new address table for new types
1 parent 397eea1 commit 668258f

1 file changed

Lines changed: 74 additions & 5 deletions

File tree

db.go

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,23 @@ import (
1717
// Structure representing an entry in the db
1818
type Entry struct {
1919
ID int `gorm:"column:id;autoIncrement;primaryKey"`
20+
Type string `gorm:"column:type"` // Type of entry - password (default), card, identity etc
2021
Title string `gorm:"column:title"`
22+
Name string `gorm:"column:name"` // Card holder name/ID card name - for types cards/identity
23+
Company string `gorm:"column:company"` // Company name of person - for type identity and
24+
// Credit card company for type CC
25+
Number string `gorm:"column:number"` // Number type - CC number for credit cards
26+
// ID card number for identity types
27+
SecurityCode string `gorm:"security_code"` // CVV number/security code for CC type
28+
ExpiryMonth string `gorm:"expiry_month"` // CC or Identity document expiry month
29+
ExpiryDay string `gorm:"expiry_day"` // Identity document expiry day
30+
ExpiryYear string `gorm:"expiry_year"` // CC or Identity document expiry year
31+
FirstName string `gorm:"column:first_name"` // first name - for ID card types
32+
MiddleName string `gorm:"column:middle_name"` // middle name - for ID card types
33+
LastName string `gorm:"column:last_name"` // last name - for ID card types
34+
Email string `gorm:"email"` // Email - for ID card types
35+
PhoneNumber string `gorm:"phone_number"` // Phone number - for ID card types
36+
2137
User string `gorm:"column:user"`
2238
Url string `gorm:"column:url"`
2339
Password string `gorm:"column:password"`
@@ -45,15 +61,68 @@ func (ex *ExtendedEntry) TableName() string {
4561
return "exentries"
4662
}
4763

64+
type Address struct {
65+
ID int `gorm:"column:id;autoIncrement;primaryKey"`
66+
Number string `gorm:"column:number"` // Flat or building number
67+
Building string `gorm:"column:building"` // Apartment or building or society name
68+
Street string `gorm:"column:street"` // Street address
69+
Locality string `gorm:"column:locality"` // Name of the locality e.g: Whitefield
70+
Area string `gorm:"column:area"` // Name of the larger area e.g: East Bangalore
71+
City string `gorm:"column:city"` // Name of the city e.g: Bangalore
72+
State string `gorm:"column:state"` // Name of the state e.g: Karnataka
73+
Country string `gorm:"column:country"` // Name of the country e.g: India
74+
75+
Landmark string `gorm:"column:landmark"` // Name of landmark if any
76+
ZipCode string `gorm:"column:zipcode"` // PIN/ZIP code
77+
Type string `gorm:"column:type"` // Type of address: Home/Work/Business
78+
79+
Entry Entry `gorm:"foreignKey:EntryID"`
80+
EntryID int
81+
}
82+
83+
func (ad *Address) TableName() string {
84+
return "address"
85+
}
86+
4887
// Clone an entry
4988
func (e1 *Entry) Copy(e2 *Entry) {
5089

5190
if e2 != nil {
52-
e1.Title = e2.Title
53-
e1.User = e2.User
54-
e1.Url = e2.Url
55-
e1.Password = e2.Password
56-
e1.Notes = e2.Notes
91+
switch (e2.Type) {
92+
case "password":
93+
e1.Title = e2.Title
94+
e1.User = e2.User
95+
e1.Url = e2.Url
96+
e1.Password = e2.Password
97+
e1.Notes = e2.Notes
98+
e1.Tags = e2.Tags
99+
e1.Type = e2.Type
100+
case "card":
101+
e1.Title = e2.Title
102+
e1.Name = e2.Name // card holder name
103+
e1.Company = e2.Company
104+
e1.Number = e2.Number
105+
e1.SecurityCode = e2.SecurityCode
106+
e1.ExpiryMonth = e2.ExpiryMonth
107+
e1.ExpiryYear = e2.ExpiryYear
108+
e1.Tags = e2.Tags
109+
e1.Notes = e2.Notes
110+
e1.Type = e2.Type
111+
case "identity":
112+
e1.Title = e2.Title
113+
e1.Name = e2.Name
114+
e1.Company = e2.Company
115+
e1.FirstName = e2.FirstName
116+
e1.LastName = e2.LastName
117+
e1.MiddleName = e2.MiddleName
118+
e1.User = e2.User
119+
e1.Email = e2.Email
120+
e1.PhoneNumber = e2.PhoneNumber
121+
e1.Number = e2.Number
122+
e1.Notes = e2.Notes
123+
e1.Tags = e2.Tags
124+
e1.Type = e2.Type
125+
}
57126
}
58127
}
59128

0 commit comments

Comments
 (0)