diff --git a/net/server/internal/api_addCard.go b/net/server/internal/api_addCard.go index 891dae2c..8456f4db 100644 --- a/net/server/internal/api_addCard.go +++ b/net/server/internal/api_addCard.go @@ -38,7 +38,7 @@ func AddCard(w http.ResponseWriter, r *http.Request) { // populate new record card.CardId = uuid.New().String() - card.AccountID = account.ID + card.AccountID = account.Guid card.Guid = guid card.Username = identity.Handle card.Name = identity.Name diff --git a/net/server/internal/api_getCard.go b/net/server/internal/api_getCard.go index bbb4022f..7b1c5a6f 100644 --- a/net/server/internal/api_getCard.go +++ b/net/server/internal/api_getCard.go @@ -18,7 +18,7 @@ func GetCard(w http.ResponseWriter, r *http.Request) { cardId := mux.Vars(r)["cardId"] var card store.Card - if err := store.DB.Where("account_id = ? AND card_id = ?", account.ID, cardId).First(&card).Error; err != nil { + if err := store.DB.Where("account_id = ? AND card_id = ?", account.Guid, cardId).First(&card).Error; err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { ErrResponse(w, http.StatusNotFound, err) } else { diff --git a/net/server/internal/api_getCardView.go b/net/server/internal/api_getCardView.go index 94f76aae..9f7ea94d 100644 --- a/net/server/internal/api_getCardView.go +++ b/net/server/internal/api_getCardView.go @@ -22,7 +22,7 @@ func GetCardView(w http.ResponseWriter, r *http.Request) { } var views []CardView - if err := store.DB.Model(&store.Card{}).Where("account_id = ?", account.ID).Find(&views).Error; err != nil { + if err := store.DB.Model(&store.Card{}).Where("account_id = ?", account.Guid).Find(&views).Error; err != nil { ErrResponse(w, http.StatusInternalServerError, err) return } diff --git a/net/server/internal/api_getOpenMessage.go b/net/server/internal/api_getOpenMessage.go index f5ad2d11..545b4ad2 100644 --- a/net/server/internal/api_getOpenMessage.go +++ b/net/server/internal/api_getOpenMessage.go @@ -19,7 +19,7 @@ func GetOpenMessage(w http.ResponseWriter, r *http.Request) { cardId := mux.Vars(r)["cardId"] var card store.Card - if err := store.DB.Where("account_id = ? AND card_id = ?", account.ID, cardId).First(&card).Error; err != nil { + if err := store.DB.Where("account_id = ? AND card_id = ?", account.Guid, cardId).First(&card).Error; err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { ErrResponse(w, http.StatusInternalServerError, err) } else { diff --git a/net/server/internal/api_setAccountApp.go b/net/server/internal/api_setAccountApp.go index 860b7b85..f34d640b 100644 --- a/net/server/internal/api_setAccountApp.go +++ b/net/server/internal/api_setAccountApp.go @@ -36,7 +36,7 @@ func SetAccountApp(w http.ResponseWriter, r *http.Request) { // create app entry app := store.App { - AccountID: token.AccountID, + AccountID: token.Account.Guid, Name: appData.Name, Description: appData.Description, Image: appData.Image, diff --git a/net/server/internal/api_setCardStatus.go b/net/server/internal/api_setCardStatus.go index bad4f355..75631978 100644 --- a/net/server/internal/api_setCardStatus.go +++ b/net/server/internal/api_setCardStatus.go @@ -38,7 +38,7 @@ func SetCardStatus(w http.ResponseWriter, r *http.Request) { // load referenced card var card store.Card - if err := store.DB.Preload("Groups").Where("account_id = ? AND card_id = ?", account.ID, cardId).First(&card).Error; err != nil { + if err := store.DB.Preload("Groups").Where("account_id = ? AND card_id = ?", account.Guid, cardId).First(&card).Error; err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { ErrResponse(w, http.StatusInternalServerError, err) } else { diff --git a/net/server/internal/api_setOpenMessage.go b/net/server/internal/api_setOpenMessage.go index 6eee7d57..f151224d 100644 --- a/net/server/internal/api_setOpenMessage.go +++ b/net/server/internal/api_setOpenMessage.go @@ -41,7 +41,7 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) { // see if card exists var card store.Card - if err := store.DB.Where("account_id = ? AND guid = ?", account.ID, guid).First(&card).Error; err != nil { + if err := store.DB.Where("account_id = ? AND guid = ?", account.Guid, guid).First(&card).Error; err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { ErrResponse(w, http.StatusInternalServerError, err) return @@ -49,7 +49,7 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) { // populate new record card.CardId = uuid.New().String() - card.AccountID = account.ID + card.AccountID = account.Guid card.Guid = guid card.Username = connect.Handle card.Name = connect.Name diff --git a/net/server/internal/authUtil.go b/net/server/internal/authUtil.go index 10c14508..90952d7f 100644 --- a/net/server/internal/authUtil.go +++ b/net/server/internal/authUtil.go @@ -13,6 +13,7 @@ import ( type accountLogin struct { ID uint + Guid string Password []byte } @@ -73,7 +74,7 @@ func BearerAccountToken(r *http.Request) (store.AccountToken, error) { // find token record var accountToken store.AccountToken - if err := store.DB.Where("token = ?", token).First(&accountToken).Error; err != nil { + if err := store.DB.Preload("Account").Where("token = ?", token).First(&accountToken).Error; err != nil { return accountToken, err } if accountToken.Expires < time.Now().Unix() { diff --git a/net/server/internal/notify.go b/net/server/internal/notify.go index 7c4f746c..c2c0b28a 100644 --- a/net/server/internal/notify.go +++ b/net/server/internal/notify.go @@ -78,7 +78,7 @@ func SetProfileNotification(account *store.Account) { // select all connected cards var cards []store.Card - if err := store.DB.Where("account_id = ? AND status = ?", account.ID, APP_CARDCONNECTED).Find(&cards).Error; err != nil { + if err := store.DB.Where("account_id = ? AND status = ?", account.Guid, APP_CARDCONNECTED).Find(&cards).Error; err != nil { ErrMsg(err) return } @@ -111,7 +111,7 @@ func SetContentNotification(account *store.Account) { // select all connected cards var cards []store.Card - if err := store.DB.Where("account_id = ? AND status = ?", account.ID, APP_CARDCONNECTED).Find(&cards).Error; err != nil { + if err := store.DB.Where("account_id = ? AND status = ?", account.Guid, APP_CARDCONNECTED).Find(&cards).Error; err != nil { ErrMsg(err) return } @@ -143,7 +143,7 @@ func SetContactContentNotification(account *store.Account, cardId string) { // select card if connected var cards []store.Card - if err := store.DB.Where("account_id = ? AND status = ? AND card_id = ?", account.ID, APP_CARDCONNECTED, cardId).Find(&cards).Error; err != nil { + if err := store.DB.Where("account_id = ? AND status = ? AND card_id = ?", account.Guid, APP_CARDCONNECTED, cardId).Find(&cards).Error; err != nil { ErrMsg(err) return } diff --git a/net/server/internal/store/schema.go b/net/server/internal/store/schema.go index 26193de3..1305a012 100644 --- a/net/server/internal/store/schema.go +++ b/net/server/internal/store/schema.go @@ -87,14 +87,14 @@ type AccountDetail struct { type App struct { ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` - AccountID uint `gorm:"index"` + AccountID string `gorm:"index"` Name string Description string Image string Url string Token string `gorm:"not null;index"` Created int64 `gorm:"autoCreateTime"` - Account Account + Account Account `gorm:"references:Guid"` } type Group struct { @@ -124,7 +124,7 @@ type Label struct { type Card struct { ID uint `gorm:"primaryKey;not null;unique;autoIncrement"` CardId string `gorm:"not null;index:card,unique"` - AccountID uint `gorm:"not null;index:card,unique;index:guid,unqiue"` + AccountID string `gorm:"not null;index:card,unique;index:guid,unqiue"` Guid string `gorm:"not null;index:guid,unique"` Username string Name string @@ -144,7 +144,7 @@ type Card struct { ViewRevision int64 `gorm:"not null"` RemoteProfile int64 RemoteContent int64 - Account Account + Account Account `gorm:"references:Guid"` Groups []Group `gorm:"many2many:card_groups;"` }