qor icon indicating copy to clipboard operation
qor copied to clipboard

How to show entries from external DB (GRPC)

Open MarcSky opened this issue 6 years ago • 1 comments

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 = &notificationViews
		return nil
	}

type Notification struct {
	Title     string `json:"title"`
	Text      string `json:"text"`
	Type      string `json:"type"`
}

MarcSky avatar Jun 02 '19 15:06 MarcSky

Try changing notificationViews type to []*models.Notification

gstvg avatar Jun 13 '19 04:06 gstvg