qor
qor copied to clipboard
How to show entries from external DB (GRPC)
Hello! I have a small question. In my project I want to get in the admin records from an external database. I get this data from Grpc. How can I draw them in the admin panel?
r := adm.AddResource(&models.Notification{})
r.FindManyHandler = func(result interface{}, context *qor.Context) error {
getNotification := notificationGRPC.GetNotificationsReq{}
res, err := notificationAccess.Client.GetNotifications(notificationAccess.Ctx, &getNotification)
if _, ok := context.GetDB().Get("qor:getting_total_count"); ok {
*(result.(*int)) = len(res.Notifications)
return nil
}
var notificationViews = make([]models.Notification, len(res.Notifications))
for i, v := range res.Notifications {
n := models.Notification{}
n.Title = v.Title
notificationViews[i] = n
}
result = ¬ificationViews
return nil
}
type Notification struct {
Title string `json:"title"`
Text string `json:"text"`
Type string `json:"type"`
}
Try changing notificationViews type to []*models.Notification