-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an endpoint which returns events
- Loading branch information
Showing
11 changed files
with
112 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package app | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/boreq/errors" | ||
"github.com/planetary-social/nos-event-service/internal/logging" | ||
"github.com/planetary-social/nos-event-service/service/domain" | ||
) | ||
|
||
type GetEvent struct { | ||
id domain.EventId | ||
} | ||
|
||
func NewGetEvent(id domain.EventId) GetEvent { | ||
return GetEvent{id: id} | ||
} | ||
|
||
type GetEventHandler struct { | ||
transactionProvider TransactionProvider | ||
logger logging.Logger | ||
metrics Metrics | ||
} | ||
|
||
func NewGetEventHandler( | ||
transactionProvider TransactionProvider, | ||
logger logging.Logger, | ||
metrics Metrics, | ||
) *GetEventHandler { | ||
return &GetEventHandler{ | ||
transactionProvider: transactionProvider, | ||
logger: logger.New("getEventHandler"), | ||
metrics: metrics, | ||
} | ||
} | ||
|
||
func (h *GetEventHandler) Handle(ctx context.Context, cmd GetEvent) (event domain.Event, err error) { | ||
defer h.metrics.StartApplicationCall("getEvent").End(&err) | ||
|
||
if err := h.transactionProvider.Transact(ctx, func(ctx context.Context, adapters Adapters) error { | ||
tmp, err := adapters.Events.Get(ctx, cmd.id) | ||
if err != nil { | ||
return errors.Wrap(err, "error getting the event") | ||
} | ||
event = tmp | ||
return nil | ||
}); err != nil { | ||
return domain.Event{}, errors.Wrap(err, "transaction error") | ||
} | ||
|
||
return event, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters