Skip to content

Commit f1a2fb1

Browse files
committed
domain/users: wires dataloader to users endpoint
1 parent 58d860c commit f1a2fb1

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

domain/users/handler.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/julienschmidt/httprouter"
99

10+
"github.com/admin-golang/admin/dataloader"
1011
"github.com/chris-ramon/golang-scaffolding/domain/users/mappers"
1112
userTypes "github.com/chris-ramon/golang-scaffolding/domain/users/types"
1213
)
@@ -26,7 +27,24 @@ func (h *handlers) GetUsers() httprouter.Handle {
2627

2728
usersAPI := mappers.UsersFromTypeToAPI(users)
2829

29-
resp, err := json.Marshal(usersAPI)
30+
response := dataloader.Response{
31+
Data: usersAPI,
32+
Meta: dataloader.Meta{
33+
Headers: []string{"ID", "Username"},
34+
Components: map[string]string{
35+
"id": "text",
36+
"username": "text",
37+
},
38+
Pagination: dataloader.Pagination{
39+
TotalCount: len(usersAPI),
40+
PerPage: 10,
41+
CurrentPage: 0,
42+
RowsPerPage: []int{10, 25, 50},
43+
},
44+
},
45+
}
46+
47+
resp, err := json.Marshal(response)
3048
if err != nil {
3149
http.Error(w, "failed to marshal response", http.StatusInternalServerError)
3250
return

0 commit comments

Comments
 (0)