mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
retrieving pending card in test
This commit is contained in:
parent
e427f1c302
commit
718d726eab
@ -23,11 +23,6 @@ func ClearCardNotes(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func GetCard(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func GetCardData(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
32
net/server/internal/api_getCard.go
Normal file
32
net/server/internal/api_getCard.go
Normal file
@ -0,0 +1,32 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"gorm.io/gorm"
|
||||
"github.com/gorilla/mux"
|
||||
"databag/internal/store"
|
||||
)
|
||||
|
||||
func GetCard(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account, code, err := BearerAppToken(r, false);
|
||||
if err != nil {
|
||||
ErrResponse(w, code, err)
|
||||
return
|
||||
}
|
||||
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 errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
ErrResponse(w, http.StatusNotFound, err)
|
||||
} else {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
WriteResponse(w, getCardModel(&card))
|
||||
}
|
||||
|
@ -31,10 +31,10 @@ func SetOpenMessage(w http.ResponseWriter, r *http.Request) {
|
||||
// load referenced account
|
||||
var account store.Account
|
||||
if err := store.DB.Where("guid = ?", connect.Contact).First(&account).Error; err != nil {
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
} else {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
ErrResponse(w, http.StatusNotFound, err)
|
||||
} else {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -74,13 +74,22 @@ func TestConnectContact(t *testing.T) {
|
||||
assert.NoError(t, ReadResponse(w, &contactStatus))
|
||||
|
||||
// get view of cards in A
|
||||
r, w, _ = NewRequest("GET", "/contact/card/view", nil)
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/view", nil)
|
||||
SetBearerAuth(r, access[0])
|
||||
GetCardView(w, r)
|
||||
var views []CardView
|
||||
assert.NoError(t, ReadResponse(w, &views))
|
||||
assert.Equal(t, len(views), 1)
|
||||
|
||||
PrintMsg(views);
|
||||
// get B card in A
|
||||
r, w, _ = NewRequest("GET", "/contact/cards/{cardId}", nil)
|
||||
vars = map[string]string{ "cardId": views[0].CardId }
|
||||
r = mux.SetURLVars(r, vars)
|
||||
SetBearerAuth(r, access[0])
|
||||
GetCard(w, r)
|
||||
assert.NoError(t, ReadResponse(w, &card))
|
||||
|
||||
PrintMsg(card);
|
||||
|
||||
|
||||
// get new card
|
||||
|
Loading…
Reference in New Issue
Block a user