mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 11:39:17 +00:00
33 lines
695 B
Go
33 lines
695 B
Go
|
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))
|
||
|
}
|
||
|
|