add new relational table requests
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
type Group struct {
|
||||
Id int `gorm:"primaryKey" json:"id"`
|
||||
Id uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
}
|
||||
|
||||
138
models/member.go
138
models/member.go
@@ -6,86 +6,106 @@ import (
|
||||
)
|
||||
|
||||
type Member struct {
|
||||
Id int `gorm:"primaryKey" json:"id,omitempty"`
|
||||
FirstName string `gorm:"column:firstName" json:"firstName,omitempty"`
|
||||
FirstNameHash string `gorm:"column:firstNameHash" json:"-"`
|
||||
LastName string `gorm:"column:lastName" json:"lastName,omitempty"`
|
||||
LastNameHash string `gorm:"column:lastNameHash" json:"-"`
|
||||
Birthday string `gorm:"column:birthday" json:"birthday,omitempty"`
|
||||
BirthdayHash string `gorm:"column:birthdayHash" json:"-"`
|
||||
Address string `gorm:"column:address" json:"address,omitempty"`
|
||||
Zip string `gorm:"column:zip" json:"zip,omitempty"`
|
||||
Town string `gorm:"column:town" json:"town,omitempty"`
|
||||
Phone string `gorm:"column:phone" json:"phone,omitempty"`
|
||||
Email string `gorm:"column:email" json:"email,omitempty"`
|
||||
FirstVisit string `gorm:"column:firstVisit" json:"firstVisit,omitempty"`
|
||||
LastVisit string `gorm:"column:lastVisit" json:"lastVisit,omitempty"`
|
||||
GroupId *int `json:"GroupId,omitempty"`
|
||||
Group *Group `gorm:"foreignKey:GroupId;constraint:OnDelete:CASCADE;"json:"group,omitempty"`
|
||||
ResponsibleId *int `json:"ResponsibleId,omitempty"`
|
||||
Responsible *Member `gorm:"foreignKey:ResponsibleId;constraint:OnDelete:CASCADE;" json:"responsible,omitempty"`
|
||||
Comment string `gorm:"column:comment" json:"comment,omitempty"`
|
||||
Events []*Event `gorm:"many2many:member_events;" `
|
||||
Id uint `gorm:"primaryKey" json:"id,omitempty"`
|
||||
FirstName string `gorm:"column:firstName" json:"firstName,omitempty"`
|
||||
FirstNameHash string `gorm:"column:firstNameHash" json:"-"`
|
||||
LastName string `gorm:"column:lastName" json:"lastName,omitempty"`
|
||||
LastNameHash string `gorm:"column:lastNameHash" json:"-"`
|
||||
Birthday string `gorm:"column:birthday" json:"birthday,omitempty"`
|
||||
BirthdayHash string `gorm:"column:birthdayHash" json:"-"`
|
||||
Address string `gorm:"column:address" json:"address,omitempty"`
|
||||
Zip string `gorm:"column:zip" json:"zip,omitempty"`
|
||||
Town string `gorm:"column:town" json:"town,omitempty"`
|
||||
Phone string `gorm:"column:phone" json:"phone,omitempty"`
|
||||
Email string `gorm:"column:email" json:"email,omitempty"`
|
||||
FirstVisit string `gorm:"column:firstVisit" json:"firstVisit,omitempty"`
|
||||
LastVisit string `gorm:"column:lastVisit" json:"lastVisit,omitempty"`
|
||||
GroupId *uint `json:"GroupId,omitempty"`
|
||||
Group *Group `gorm:"foreignKey:GroupId;constraint:OnDelete:CASCADE;" json:"group,omitempty"`
|
||||
ResponsibleId *uint `json:"ResponsibleId,omitempty"`
|
||||
Responsible *Responsible `gorm:"foreignKey:ResponsibleId;references:Id" json:"responsible,omitempty"`
|
||||
Comment string `gorm:"column:comment" json:"comment,omitempty"`
|
||||
Events []*Event `gorm:"many2many:member_events;" `
|
||||
}
|
||||
|
||||
func (m *Member) Encrypt(token []byte) (err error) {
|
||||
|
||||
m.FirstNameHash = utils.HashField(m.FirstName, token)
|
||||
m.FirstName, err = crypto.Encrypt(m.FirstName, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.FirstName != "" {
|
||||
m.FirstNameHash = utils.HashField(m.FirstName, token)
|
||||
m.FirstName, err = crypto.Encrypt(m.FirstName, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
if m.LastName != "" {
|
||||
m.LastNameHash = utils.HashField(m.LastName, token)
|
||||
m.LastName, err = crypto.Encrypt(m.LastName, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.LastNameHash = utils.HashField(m.LastName, token)
|
||||
m.LastName, err = crypto.Encrypt(m.LastName, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.Birthday != "" {
|
||||
m.BirthdayHash = utils.HashField(m.Birthday, token)
|
||||
m.Birthday, err = crypto.Encrypt(m.Birthday, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.BirthdayHash = utils.HashField(m.Birthday, token)
|
||||
m.Birthday, err = crypto.Encrypt(m.Birthday, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.Address != "" {
|
||||
m.Address, err = crypto.Encrypt(m.Address, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.Address, err = crypto.Encrypt(m.Address, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.Zip != "" {
|
||||
m.Zip, err = crypto.Encrypt(m.Zip, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.Zip, err = crypto.Encrypt(m.Zip, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.Town != "" {
|
||||
m.Town, err = crypto.Encrypt(m.Town, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.Town, err = crypto.Encrypt(m.Town, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.Phone != "" {
|
||||
m.Phone, err = crypto.Encrypt(m.Phone, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.Phone, err = crypto.Encrypt(m.Phone, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.Email != "" {
|
||||
m.Email, err = crypto.Encrypt(m.Email, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.Email, err = crypto.Encrypt(m.Email, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.FirstVisit != "" {
|
||||
m.FirstVisit, err = crypto.Encrypt(m.FirstVisit, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.FirstVisit, err = crypto.Encrypt(m.FirstVisit, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.LastVisit != "" {
|
||||
m.LastVisit, err = crypto.Encrypt(m.LastVisit, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
m.LastVisit, err = crypto.Encrypt(m.LastVisit, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.Comment, err = crypto.Encrypt(m.Comment, token)
|
||||
if err != nil {
|
||||
return
|
||||
if m.Comment != "" {
|
||||
m.Comment, err = crypto.Encrypt(m.Comment, token)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package models
|
||||
|
||||
type Responsible struct {
|
||||
Id uint `gorm:"primaryKey" json:"id"`
|
||||
MemberId uint
|
||||
Id uint `gorm:"primaryKey" json:"id"`
|
||||
MemberId uint `json:"memberId"`
|
||||
Member *Member `gorm:"foreignKey:MemberId;constraint:OnDelete:CASCADE;" json:"member"`
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user