From dfcbb3c49a5adb420a596964d45c92231a89e872 Mon Sep 17 00:00:00 2001 From: Roland Osborne Date: Wed, 2 Feb 2022 11:20:18 -0800 Subject: [PATCH] removing cardview --- doc/api.oa3 | 81 +++++++------------ net/server/internal/api_getCardView.go | 32 -------- net/server/internal/api_getCards.go | 23 ++++++ net/server/internal/models.go | 15 ---- net/server/internal/routers.go | 6 +- net/server/internal/ucConnectContact_test.go | 20 ++--- .../internal/ucProfileNotification_test.go | 26 +++--- 7 files changed, 78 insertions(+), 125 deletions(-) delete mode 100644 net/server/internal/api_getCardView.go create mode 100644 net/server/internal/api_getCards.go diff --git a/doc/api.oa3 b/doc/api.oa3 index 14d66062..1ffae6fa 100644 --- a/doc/api.oa3 +++ b/doc/api.oa3 @@ -938,6 +938,35 @@ paths: description: internal server error /contact/cards: + get: + tags: + - contact + description: Get list of cards. Access granted to app tokens of account holder. + operationId: get-cards + security: + - bearerAuth: [] + parameters: + - name: cardRevision + in: query + description: only return updated cards since specified revision + required: false + schema: + type: string + responses: + '200': + description: successful operation + content: + application/json: + schema: + type: array + items: + $ref: '#/components/schemas/Card' + '401': + description: permission denied + '410': + description: account disabled + '500': + description: internal server error post: tags: - contact @@ -961,30 +990,6 @@ paths: '500': description: internal server error - /contact/cards/view: - get: - tags: - - contact - description: Get list of card views. Access granted to app tokens of account holder. - operationId: get-card-view - security: - - bearerAuth: [] - responses: - '200': - description: successful operation - content: - application/json: - schema: - type: array - items: - $ref: '#/components/schemas/CardView' - '401': - description: permission denied - '410': - description: account disabled - '500': - description: internal server error - /contact/cards/{cardId}: get: tags: @@ -4042,34 +4047,6 @@ components: type: string format: base64 encoded image - CardView: - type: object - required: - - cardId - - profileRevision - - dataRevision - - notifiedProfile - - notifiedContent - - notifiedView - properties: - cardId: - type: string - profileRevision: - type: integer - format: int64 - dataRevision: - type: integer - format: int64 - notifiedProfile: - type: integer - format: int64 - notifiedContent: - type: integer - format: int64 - notifiedView: - type: integer - format: int64 - CardProfile: type: object required: diff --git a/net/server/internal/api_getCardView.go b/net/server/internal/api_getCardView.go deleted file mode 100644 index 43de7ec7..00000000 --- a/net/server/internal/api_getCardView.go +++ /dev/null @@ -1,32 +0,0 @@ -package databag - -import ( - "net/http" - "databag/internal/store" -) - -type cardView struct { - CardId string - ProfileRevision int64 - DataRevision int64 - NotifiedProfile int64 - NotifiedContent int64 - NotifiedView int64 -} - -func GetCardView(w http.ResponseWriter, r *http.Request) { - - account, code, err := BearerAppToken(r, false); - if err != nil { - ErrResponse(w, code, err) - return - } - - var views []CardView - if err := store.DB.Model(&store.Card{}).Where("account_id = ?", account.Guid).Find(&views).Error; err != nil { - ErrResponse(w, http.StatusInternalServerError, err) - return - } - - WriteResponse(w, &views) -} diff --git a/net/server/internal/api_getCards.go b/net/server/internal/api_getCards.go new file mode 100644 index 00000000..36a34ce8 --- /dev/null +++ b/net/server/internal/api_getCards.go @@ -0,0 +1,23 @@ +package databag + +import ( + "net/http" + "databag/internal/store" +) + +func GetCards(w http.ResponseWriter, r *http.Request) { + + account, code, err := BearerAppToken(r, false); + if err != nil { + ErrResponse(w, code, err) + return + } + + var cards []store.Card + if err := store.DB.Where("account_id = ?", account.Guid).Find(&cards).Error; err != nil { + ErrResponse(w, http.StatusInternalServerError, err) + return + } + + WriteResponse(w, &cards) +} diff --git a/net/server/internal/models.go b/net/server/internal/models.go index 484d5f43..93992f07 100644 --- a/net/server/internal/models.go +++ b/net/server/internal/models.go @@ -62,12 +62,6 @@ type ArticleData struct { TagRevision int64 `json:"tagRevision"` } -type ArticleView struct { - ArticleId string `json:"articleId"` - Revision int64 `json:"revision"` - TagRevision int64 `json:"tagRevision"` -} - type ArticleAccess struct { Labels []string `json:"labels"` Groups []string `json:"groups"` @@ -117,15 +111,6 @@ type CardProfile struct { Node string `json:"node"` } -type CardView struct { - CardId string `json:"cardId"` - ProfileRevision int64 `json:"profileRevision"` - DataRevision int64 `json:"dataRevision"` - NotifiedProfile int64 `json:"notifiedProfile"` - NotifiedContent int64 `json:"notifiedContent"` - NotifiedView int64 `json:"notifiedView"` -} - type ContentArticlesBody struct { Labels []string `json:"labels"` Groups []string `json:"groups"` diff --git a/net/server/internal/routers.go b/net/server/internal/routers.go index d312cd6e..566f6f1d 100644 --- a/net/server/internal/routers.go +++ b/net/server/internal/routers.go @@ -321,10 +321,10 @@ var routes = Routes{ }, Route{ - "GetCardView", + "GetCards", strings.ToUpper("Get"), - "/contact/cards/view", - GetCardView, + "/contact/cards", + GetCards, }, Route{ diff --git a/net/server/internal/ucConnectContact_test.go b/net/server/internal/ucConnectContact_test.go index afe39170..12f40db4 100644 --- a/net/server/internal/ucConnectContact_test.go +++ b/net/server/internal/ucConnectContact_test.go @@ -71,17 +71,17 @@ func TestConnectContact(t *testing.T) { SetOpenMessage(w, r) assert.NoError(t, ReadResponse(w, &contactStatus)) - // get view of cards in A - r, w, _ = NewRequest("GET", "/contact/cards/view", nil) + // get cards in A + r, w, _ = NewRequest("GET", "/contact/cards", nil) SetBearerAuth(r, a) - GetCardView(w, r) - var views []CardView - assert.NoError(t, ReadResponse(w, &views)) - assert.Equal(t, len(views), 1) + GetCards(w, r) + var cards []Card + assert.NoError(t, ReadResponse(w, &cards)) + assert.Equal(t, len(cards), 1) // get B card in A r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil) - vars = map[string]string{ "cardId": views[0].CardId } + vars = map[string]string{ "cardId": cards[0].CardId } r = mux.SetURLVars(r, vars) SetBearerAuth(r, a) GetCard(w, r) @@ -89,7 +89,7 @@ func TestConnectContact(t *testing.T) { // update B status to connecting r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status", APP_CARDCONNECTING) - vars = map[string]string{ "cardId": views[0].CardId } + vars = map[string]string{ "cardId": cards[0].CardId } r = mux.SetURLVars(r, vars) SetBearerAuth(r, a) SetCardStatus(w, r) @@ -97,7 +97,7 @@ func TestConnectContact(t *testing.T) { // get open message to B r, w, _ = NewRequest("GET", "/contact/cards/{cardId}/openMessage", nil) - vars = map[string]string{ "cardId": views[0].CardId } + vars = map[string]string{ "cardId": cards[0].CardId } r = mux.SetURLVars(r, vars) SetBearerAuth(r, a) GetOpenMessage(w, r) @@ -117,7 +117,7 @@ func TestConnectContact(t *testing.T) { // update B status to connected r, w, _ = NewRequest("PUT", "/contact/cards/{cardId}/status?token=" + contactStatus.Token, APP_CARDCONNECTED) - vars = map[string]string{ "cardId": views[0].CardId } + vars = map[string]string{ "cardId": cards[0].CardId } r = mux.SetURLVars(r, vars) SetBearerAuth(r, a) SetCardStatus(w, r) diff --git a/net/server/internal/ucProfileNotification_test.go b/net/server/internal/ucProfileNotification_test.go index 0ef55c5f..5e13c7ce 100644 --- a/net/server/internal/ucProfileNotification_test.go +++ b/net/server/internal/ucProfileNotification_test.go @@ -7,7 +7,7 @@ import ( ) func TestProfileNotification(t *testing.T) { - var views []CardView + var cards []Card var revision Revision var ws *websocket.Conn var err error @@ -20,13 +20,13 @@ func TestProfileNotification(t *testing.T) { OpenTestCard(a, aCard) OpenTestCard(b, bCard) - // get views list of cards - r, w, _ := NewRequest("GET", "/contact/cards/view", nil) + // get list of cards + r, w, _ := NewRequest("GET", "/contact/cards", nil) SetBearerAuth(r, a) - GetCardView(w, r) - assert.NoError(t, ReadResponse(w, &views)) - assert.Equal(t, len(views), 1) - profileRevision := views[0].NotifiedProfile + GetCards(w, r) + assert.NoError(t, ReadResponse(w, &cards)) + assert.Equal(t, len(cards), 1) + profileRevision := cards[0].NotifiedProfile // app connects websocket ws, err = StatusConnection(a, &revision); @@ -49,11 +49,11 @@ func TestProfileNotification(t *testing.T) { assert.NoError(t, err) assert.NotEqual(t, cardRevision, revision.Card) - // get views list of cards - r, w, _ = NewRequest("GET", "/contact/cards/view", nil) + // get list of cards + r, w, _ = NewRequest("GET", "/contact/cards", nil) SetBearerAuth(r, a) - GetCardView(w, r) - assert.NoError(t, ReadResponse(w, &views)) - assert.Equal(t, len(views), 1) - assert.NotEqual(t, profileRevision, views[0].NotifiedProfile) + GetCards(w, r) + assert.NoError(t, ReadResponse(w, &cards)) + assert.Equal(t, len(cards), 1) + assert.NotEqual(t, profileRevision, cards[0].NotifiedProfile) }