databag/net/server/internal/api_getCard.go

33 lines
757 B
Go
Raw Normal View History

2022-02-09 07:54:09 +00:00
package databag
import (
2022-07-22 19:28:14 +00:00
"databag/internal/store"
"errors"
"github.com/gorilla/mux"
"gorm.io/gorm"
"net/http"
2022-02-09 07:54:09 +00:00
)
2022-07-25 19:48:57 +00:00
//GetCard retrieves contacts set by account
2022-02-09 07:54:09 +00:00
func GetCard(w http.ResponseWriter, r *http.Request) {
2022-10-25 06:09:39 +00:00
account, code, err := ParamAgentToken(r, false)
if err != nil {
ErrResponse(w, code, err)
return
}
cardID := mux.Vars(r)["cardID"]
2022-02-09 07:54:09 +00:00
2022-07-22 19:28:14 +00:00
var slot store.CardSlot
if err := store.DB.Preload("Card.Groups.GroupSlot").Where("account_id = ? AND card_slot_id = ?", account.ID, cardID).First(&slot).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
ErrResponse(w, http.StatusNotFound, err)
} else {
ErrResponse(w, http.StatusInternalServerError, err)
}
return
}
2022-02-09 07:54:09 +00:00
2022-07-22 19:28:14 +00:00
WriteResponse(w, getCardModel(&slot))
2022-02-09 07:54:09 +00:00
}