mirror of
https://github.com/balzack/databag.git
synced 2025-02-11 19:19:16 +00:00
added status timestamp to cards
This commit is contained in:
parent
067422cfaf
commit
35a4a51094
@ -3510,6 +3510,9 @@ components:
|
||||
status:
|
||||
type: string
|
||||
enum: [ pending, confirmed, requested, connecting, connected ]
|
||||
statusUpdated:
|
||||
type: integer
|
||||
format: int64
|
||||
token:
|
||||
type: string
|
||||
notes:
|
||||
|
@ -1,6 +1,7 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"time"
|
||||
"databag/internal/store"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
@ -57,6 +58,7 @@ func AddCard(w http.ResponseWriter, r *http.Request) {
|
||||
Node: identity.Node,
|
||||
ProfileRevision: identity.Revision,
|
||||
Status: APPCardConfirmed,
|
||||
StatusUpdated: time.Now().Unix(),
|
||||
ViewRevision: 0,
|
||||
InToken: hex.EncodeToString(data),
|
||||
AccountID: account.GUID,
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"databag/internal/store"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"time"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/theckman/go-securerandom"
|
||||
"gorm.io/gorm"
|
||||
@ -105,6 +106,7 @@ func SetCardStatus(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
slot.Card.Status = status
|
||||
slot.Card.StatusUpdated = time.Now().Unix()
|
||||
slot.Card.NotifiedView = viewRevision
|
||||
slot.Card.NotifiedArticle = articleRevision
|
||||
slot.Card.NotifiedChannel = channelRevision
|
||||
|
@ -56,6 +56,9 @@ func SetCloseMessage(w http.ResponseWriter, r *http.Request) {
|
||||
if res := tx.Model(&card).Update("status", APPCardConfirmed).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Model(&card).Update("status_updated", time.Now().Unix()).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
}
|
||||
if res := tx.Model(&card).Update("detail_revision", account.CardRevision+1).Error; res != nil {
|
||||
return res
|
||||
|
@ -67,6 +67,7 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) {
|
||||
card.Node = connect.Node
|
||||
card.ProfileRevision = connect.ProfileRevision
|
||||
card.Status = APPCardPending
|
||||
card.StatusUpdated = time.Now().Unix()
|
||||
card.NotifiedProfile = connect.ProfileRevision
|
||||
card.NotifiedArticle = connect.ArticleRevision
|
||||
card.NotifiedView = connect.ViewRevision
|
||||
@ -124,9 +125,11 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if card.Status == APPCardConfirmed {
|
||||
card.Status = APPCardRequested
|
||||
card.StatusUpdated = time.Now().Unix()
|
||||
}
|
||||
if card.Status == APPCardConnecting {
|
||||
card.Status = APPCardConnected
|
||||
card.StatusUpdated = time.Now().Unix()
|
||||
}
|
||||
card.OutToken = connect.Token
|
||||
card.DetailRevision = account.CardRevision + 1
|
||||
|
@ -69,13 +69,14 @@ func getCardRevisionModel(slot *store.CardSlot) *Card {
|
||||
|
||||
func getCardDetailModel(slot *store.CardSlot) *CardDetail {
|
||||
|
||||
var groups []string
|
||||
var groups []string = []string{}
|
||||
for _, group := range slot.Card.Groups {
|
||||
groups = append(groups, group.GroupSlot.GroupSlotID)
|
||||
}
|
||||
|
||||
return &CardDetail{
|
||||
Status: slot.Card.Status,
|
||||
StatusUpdated: slot.Card.StatusUpdated,
|
||||
Token: slot.Card.OutToken,
|
||||
Notes: slot.Card.Notes,
|
||||
Groups: groups,
|
||||
|
@ -113,7 +113,9 @@ type CardData struct {
|
||||
type CardDetail struct {
|
||||
Status string `json:"status"`
|
||||
|
||||
Token string `json:"token,omitempty"`
|
||||
StatusUpdated int64 `json:"statusUpdated"`
|
||||
|
||||
Token string `json:"token,omitempty"`
|
||||
|
||||
Notes string `json:"notes,omitempty"`
|
||||
|
||||
|
@ -151,6 +151,7 @@ type Card struct {
|
||||
ProfileRevision int64 `gorm:"not null"`
|
||||
DetailRevision int64 `gorm:"not null;default:1"`
|
||||
Status string `gorm:"not null"`
|
||||
StatusUpdated int64
|
||||
InToken string `gorm:"not null;index:cardguid,unique"`
|
||||
OutToken string
|
||||
Notes string
|
||||
|
Loading…
Reference in New Issue
Block a user