github.com/pbberlin/go-pwa@v0.0.0-20220328105622-7c26e0ca1ab8/pkg/db/model-creditcard.go (about)

     1  package db
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  type CreditCard struct { // tag unique - belongs to one entry - no multiple uses
     8  	// gorm.Model
     9  	ID uint `gorm:"primarykey"`
    10  
    11  	// Issuer  string `gorm:"index:idx_credit_card1,unique;index:idx_credit_card2,unique"` // unique composite indexes over issuer, number - with and without entry ID
    12  	// Number  uint   `gorm:"index:idx_credit_card1,unique;index:idx_credit_card2,unique"` //
    13  	// EntryID uint   `gorm:"index:idx_credit_card1,unique"`                               //
    14  	Issuer  string `gorm:"index:idx_credit_card1,unique"` // unique composite indexes over issuer, number - with and without entry ID
    15  	Number  uint   `gorm:"index:idx_credit_card1,unique"` //
    16  	EntryID uint   `gorm:"index:idx_credit_card1,unique"` //
    17  }
    18  
    19  // MarshalJSON only essential data
    20  func (e CreditCard) MarshalJSON() ([]byte, error) {
    21  
    22  	et := struct{ Name string }{}
    23  	et.Name = e.Issuer
    24  
    25  	j, err := json.Marshal(et)
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	return j, nil
    31  }