Skip to content

Commit

Permalink
backend: Support GetMyEntrires
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphexion committed Oct 5, 2021
1 parent 8d6d4a6 commit ada3049
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Backend interface {

// Entries
GetEntries() ([]noko.Entry, error)
GetMyEntries() ([]noko.Entry, error)

// Output
Write(p []byte) (n int, err error)
Expand Down
13 changes: 9 additions & 4 deletions backend/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
var ErrNotImplemented = errors.New("not implemented")

type MockBackend struct {
Projects []noko.Project
Timers []noko.Timer
Entries []noko.Entry
Output *bytes.Buffer
Projects []noko.Project
Timers []noko.Timer
Entries []noko.Entry
MyEntries []noko.Entry
Output *bytes.Buffer
}

func (m *MockBackend) Init() error {
Expand Down Expand Up @@ -83,3 +84,7 @@ func (m *MockBackend) GetSomeProjects(withTimer bool) ([]noko.Project, error) {
func (m *MockBackend) GetEntries() ([]noko.Entry, error) {
return m.Entries, nil
}

func (m *MockBackend) GetMyEntries() ([]noko.Entry, error) {
return m.MyEntries, nil
}
10 changes: 9 additions & 1 deletion backend/real.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,18 @@ func (m *RealBackend) GetSomeProjects(withTimer bool) ([]noko.Project, error) {
}

func (m *RealBackend) GetEntries() ([]noko.Entry, error) {
return m.getEntries(false)
}

func (m *RealBackend) GetMyEntries() ([]noko.Entry, error) {
return m.getEntries(true)
}

func (m *RealBackend) getEntries(currentUser bool) ([]noko.Entry, error) {
client := noko.NewClient()
ctx, cancel := standardContext()
defer cancel()
return client.GetEntries(ctx, false)
return client.GetEntries(ctx, currentUser)
}

func standardContext() (context.Context, context.CancelFunc) {
Expand Down

0 comments on commit ada3049

Please sign in to comment.