@@ -9,58 +9,59 @@ import (
99
1010 "github.com/Scalingo/go-scalingo/v9/http"
1111 "github.com/Scalingo/go-utils/errors/v3"
12+ "github.com/Scalingo/go-utils/pagination"
1213)
1314
1415type EventsService interface {
1516 EventTypesList (context.Context ) ([]EventType , error )
1617 EventCategoriesList (context.Context ) ([]EventCategory , error )
17- EventsList (ctx context.Context , app string , opts PaginationOpts ) (Events , PaginationMeta , error )
18- UserEventsList (context.Context , PaginationOpts ) (Events , PaginationMeta , error )
18+ EventsList (ctx context.Context , app string , paginationReq pagination. Request ) (Events , pagination. Meta , error )
19+ UserEventsList (ctx context.Context , paginationReq pagination. Request ) (Events , pagination. Meta , error )
1920}
2021
2122var _ EventsService = (* Client )(nil )
2223
2324type EventsRes struct {
2425 Events []* Event `json:"events"`
2526 Meta struct {
26- PaginationMeta PaginationMeta `json:"pagination"`
27+ Pagination pagination. Meta `json:"pagination"`
2728 }
2829}
2930
30- func (c * Client ) EventsList (ctx context.Context , app string , opts PaginationOpts ) (Events , PaginationMeta , error ) {
31+ func (c * Client ) EventsList (ctx context.Context , app string , paginationReq pagination. Request ) (Events , pagination. Meta , error ) {
3132 var eventsRes EventsRes
32- err := c .ScalingoAPI ().SubresourceList (ctx , "apps" , app , "events" , opts . ToMap (), & eventsRes )
33+ err := c .ScalingoAPI ().SubresourceList (ctx , "apps" , app , "events" , paginationReq . ToURLValues (), & eventsRes )
3334 if err != nil {
34- return nil , PaginationMeta {}, errors .Wrap (ctx , err , "list app events" )
35+ return nil , pagination. Meta {}, errors .Wrap (ctx , err , "list app events" )
3536 }
3637 var events Events
3738 for _ , ev := range eventsRes .Events {
3839 events = append (events , ev .Specialize ())
3940 }
40- return events , eventsRes .Meta .PaginationMeta , nil
41+ return events , eventsRes .Meta .Pagination , nil
4142}
4243
43- func (c * Client ) UserEventsList (ctx context.Context , opts PaginationOpts ) (Events , PaginationMeta , error ) {
44+ func (c * Client ) UserEventsList (ctx context.Context , paginationReq pagination. Request ) (Events , pagination. Meta , error ) {
4445 req := & http.APIRequest {
4546 Endpoint : "/events" ,
46- Params : opts . ToMap (),
47+ Params : paginationReq . ToURLValues (),
4748 }
4849
4950 var eventsRes EventsRes
5051 res , err := c .ScalingoAPI ().Do (ctx , req )
5152 if err != nil {
52- return nil , PaginationMeta {}, errors .Wrap (ctx , err , "list user events" )
53+ return nil , pagination. Meta {}, errors .Wrap (ctx , err , "list user events" )
5354 }
5455 defer res .Body .Close ()
5556
5657 err = json .NewDecoder (res .Body ).Decode (& eventsRes )
5758 if err != nil {
58- return nil , PaginationMeta {}, errors .Wrap (ctx , err , "decode user events response" )
59+ return nil , pagination. Meta {}, errors .Wrap (ctx , err , "decode user events response" )
5960 }
6061
6162 var events Events
6263 for _ , ev := range eventsRes .Events {
6364 events = append (events , ev .Specialize ())
6465 }
65- return events , eventsRes .Meta .PaginationMeta , nil
66+ return events , eventsRes .Meta .Pagination , nil
6667}
0 commit comments