databag/net/server/internal/api_getAccountListingMessage.go

48 lines
1.2 KiB
Go
Raw Normal View History

2022-04-05 23:52:39 +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-04-05 23:52:39 +00:00
)
func GetAccountListingMessage(w http.ResponseWriter, r *http.Request) {
2022-07-22 19:28:14 +00:00
// get referenced account guid
params := mux.Vars(r)
guid := params["guid"]
2022-04-05 23:52:39 +00:00
2022-07-22 19:28:14 +00:00
var account store.Account
if err := store.DB.Preload("AccountDetail").Where("guid = ? AND searchable = ? AND disabled = ?", guid, true, false).First(&account).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
ErrResponse(w, http.StatusNotFound, err)
} else {
ErrResponse(w, http.StatusInternalServerError, err)
}
return
}
detail := account.AccountDetail
2022-04-05 23:52:39 +00:00
2022-07-22 19:28:14 +00:00
// generate identity DataMessage
identity := Identity{
Revision: account.ProfileRevision,
Handle: account.Username,
Name: detail.Name,
Description: detail.Description,
Location: detail.Location,
Image: detail.Image,
Version: APPVersion,
Node: getStrConfigValue(CNFDomain, ""),
}
msg, res := WriteDataMessage(detail.PrivateKey, detail.PublicKey, detail.KeyType,
APPSignPKCS1V15, account.GUID, APPMsgIdentity, &identity)
if res != nil {
ErrResponse(w, http.StatusInternalServerError, res)
return
}
2022-04-05 23:52:39 +00:00
2022-07-22 19:28:14 +00:00
WriteResponse(w, msg)
2022-04-05 23:52:39 +00:00
}