Skip to content

Commit

Permalink
fix: notification event ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgacsal committed Aug 23, 2024
1 parent d76d914 commit ba7da2a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion internal/notification/httpdriver/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/openmeterio/openmeter/pkg/framework/transport/httptransport"
"github.com/openmeterio/openmeter/pkg/models"
"github.com/openmeterio/openmeter/pkg/pagination"
"github.com/openmeterio/openmeter/pkg/sortx"
)

type (
Expand All @@ -32,7 +33,8 @@ func (h *handler) ListEvents() ListEventsHandler {

req := ListEventsRequest{
Namespaces: []string{ns},
OrderBy: defaultx.WithDefault(params.OrderBy, notification.EventOrderByID),
Order: sortx.Order(defaultx.WithDefault(params.Order, api.ListNotificationEventsParamsOrderSortOrderDESC)),
OrderBy: defaultx.WithDefault(params.OrderBy, notification.EventOrderByCreatedAt),
Page: pagination.Page{
PageSize: defaultx.WithDefault(params.PageSize, notification.DefaultPageSize),
PageNumber: defaultx.WithDefault(params.Page, notification.DefaultPageNumber),
Expand Down
8 changes: 4 additions & 4 deletions internal/notification/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,18 +532,18 @@ func (r repository) ListEvents(ctx context.Context, params notification.ListEven
query.WithChannels()
})

order := entutils.GetOrdering(sortx.OrderDefault)
order := entutils.GetOrdering(sortx.OrderDesc)
if !params.Order.IsDefaultValue() {
order = entutils.GetOrdering(params.Order)
}

switch params.OrderBy {
case notification.EventOrderByCreatedAt:
query = query.Order(eventdb.ByCreatedAt(order...))
case notification.EventOrderByID:
query = query.Order(eventdb.ByID(order...))
case notification.EventOrderByCreatedAt:
fallthrough
default:
query = query.Order(eventdb.ByID(order...))
query = query.Order(eventdb.ByCreatedAt(order...))
}

response := pagination.PagedResponse[notification.Event]{
Expand Down

0 comments on commit ba7da2a

Please sign in to comment.