-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add total events counter to the debug page
Co-authored-by: Łukasz Reszke <[email protected]>
- Loading branch information
1 parent
95250e6
commit 4376e1f
Showing
7 changed files
with
117 additions
and
17 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
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 |
---|---|---|
@@ -1,21 +1,37 @@ | ||
module Page.Debug exposing (..) | ||
|
||
import Flags exposing (Flags) | ||
import Html exposing (..) | ||
import Flags exposing (Flags) | ||
import Api exposing (getStats, Stats) | ||
import Http | ||
|
||
type alias Model = { resVersion : String, repositoryAdapter : String, eventsInTotal : String } | ||
|
||
type alias Model = | ||
{ resVersion : String, repositoryAdapter : String } | ||
|
||
type Msg | ||
= GotStats (Result Http.Error Stats) | ||
|
||
init : Flags -> Model | ||
init flags = | ||
{ resVersion = flags.resVersion, repositoryAdapter = flags.repositoryAdapter } | ||
init flags = | ||
{ resVersion = flags.resVersion, repositoryAdapter = flags.repositoryAdapter, eventsInTotal = "" } | ||
|
||
initCmd : Flags -> Cmd Msg | ||
initCmd flags = | ||
getStats GotStats flags | ||
|
||
view : Model -> Html a | ||
view: Model -> Html a | ||
view model = | ||
div [] | ||
[ p [] [ text ("RubyEventStore version: " ++ model.resVersion) ] | ||
, p [] [ text ("RubyEventStore adapter: " ++ model.repositoryAdapter) ] | ||
] | ||
div [] [ | ||
p [] [text ("RubyEventStore version: " ++ model.resVersion)], | ||
p [] [text ("RubyEventStore adapter: " ++ model.repositoryAdapter)], | ||
p [] [text ("Events in total: " ++ model.eventsInTotal)] | ||
] | ||
|
||
update : Msg -> Model -> (Model, Cmd Msg) | ||
update msg model = | ||
case msg of | ||
GotStats result -> | ||
case result of | ||
Ok stats -> | ||
({ model | eventsInTotal = String.fromInt stats.eventsInTotal }, Cmd.none) | ||
Err _ -> | ||
(model, Cmd.none) |
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
27 changes: 27 additions & 0 deletions
27
ruby_event_store-browser/lib/ruby_event_store/browser/get_stats.rb
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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
module RubyEventStore | ||
module Browser | ||
class GetStats | ||
def initialize(event_store:) | ||
@event_store = event_store | ||
end | ||
|
||
def to_h | ||
{ | ||
meta: { | ||
events_in_total: events | ||
} | ||
} | ||
end | ||
|
||
private | ||
|
||
def events | ||
event_store.read.count | ||
end | ||
|
||
attr_reader :event_store | ||
end | ||
end | ||
end |
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "spec_helper" | ||
|
||
module RubyEventStore | ||
::RSpec.describe Browser do | ||
include Browser::IntegrationHelpers | ||
|
||
specify "not existing" do | ||
api_client.get "/api/stats" | ||
expect(api_client.parsed_body["meta"]).to match({ | ||
"events_in_total" => 0 | ||
}) | ||
end | ||
end | ||
end |