fix: make list webhooks params optional

This commit is contained in:
Lakhan Samani
2022-07-11 22:05:44 +05:30
parent 4f5a6c77f8
commit bfaa0f9d89
5 changed files with 36 additions and 29 deletions

View File

@@ -12,7 +12,7 @@ import (
)
// WebhookLogsResolver resolver for getting the list of webhook_logs based on pagination & webhook identifier
func WebhookLogsResolver(ctx context.Context, params model.ListWebhookLogRequest) (*model.WebhookLogs, error) {
func WebhookLogsResolver(ctx context.Context, params *model.ListWebhookLogRequest) (*model.WebhookLogs, error) {
gc, err := utils.GinContextFromContext(ctx)
if err != nil {
log.Debug("Failed to get GinContext: ", err)
@@ -24,11 +24,20 @@ func WebhookLogsResolver(ctx context.Context, params model.ListWebhookLogRequest
return nil, fmt.Errorf("unauthorized")
}
pagination := utils.GetPagination(&model.PaginatedInput{
Pagination: params.Pagination,
})
var pagination model.Pagination
var webhookID string
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, pagination, utils.StringValue(params.WebhookID))
if params != nil {
pagination = utils.GetPagination(&model.PaginatedInput{
Pagination: params.Pagination,
})
webhookID = utils.StringValue(params.WebhookID)
} else {
pagination = utils.GetPagination(nil)
webhookID = ""
}
webhookLogs, err := db.Provider.ListWebhookLogs(ctx, pagination, webhookID)
if err != nil {
log.Debug("failed to get webhook logs: ", err)
return nil, err