mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
37 lines
860 B
Go
37 lines
860 B
Go
package databag
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
"gorm.io/gorm"
|
|
"github.com/gorilla/mux"
|
|
"databag/internal/store"
|
|
)
|
|
|
|
func GetCardDetail(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 slot store.CardSlot
|
|
if err := store.DB.Preload("Card.Groups").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
|
|
}
|
|
if slot.Card == nil {
|
|
ErrResponse(w, http.StatusNotFound, errors.New("referenced empty card slot"))
|
|
return
|
|
}
|
|
|
|
WriteResponse(w, getCardDetailModel(&slot))
|
|
}
|
|
|