Skip to content

Commit f744939

Browse files
authored
Cleanup datastore package (#400)
* Remove fetch api * Move it to projector, since it is used there
1 parent 7079d96 commit f744939

32 files changed

+85
-65
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package datastore
2+
3+
import "github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
4+
5+
// NewRecorder from datastore.NewRecorder
6+
var NewRecorder = datastore.NewRecorder
7+
8+
// DoesNotExistError is a type alias from datastore.DoesNotExistError
9+
type DoesNotExistError = datastore.DoesNotExistError

pkg/datastore/fetch.go renamed to internal/projector/datastore/fetch.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,9 @@ import (
55
"encoding/json"
66
"fmt"
77
"strings"
8-
)
98

10-
// Getter can get values from keys.
11-
//
12-
// The Datastore object implements this interface.
13-
type Getter interface {
14-
Get(ctx context.Context, keys ...string) (map[string][]byte, error)
15-
}
9+
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
10+
)
1611

1712
// Fetcher is a helper to fetch many keys from the datastore.
1813
//
@@ -24,12 +19,12 @@ type Getter interface {
2419
//
2520
// Make sure to call Fetcher.Err() at the end to see, if an error happend.
2621
type Fetcher struct {
27-
getter Getter
22+
getter datastore.Getter
2823
err error
2924
}
3025

3126
// NewFetcher initializes a Fetcher object.
32-
func NewFetcher(getter Getter) *Fetcher {
27+
func NewFetcher(getter datastore.Getter) *Fetcher {
3328
return &Fetcher{getter: getter}
3429
}
3530

@@ -85,7 +80,7 @@ func (f *Fetcher) FetchIfExist(ctx context.Context, value interface{}, keyFmt st
8580
}
8681

8782
if fields[idField] == nil {
88-
f.err = DoesNotExistError(fqid)
83+
f.err = datastore.DoesNotExistError(fqid)
8984
return
9085
}
9186
if fields[fqfield] == nil {
@@ -121,7 +116,7 @@ func (f *Fetcher) Object(ctx context.Context, fqID string, fields ...string) map
121116
}
122117

123118
if vals[fqID+"/id"] == nil {
124-
f.err = DoesNotExistError(fqID)
119+
f.err = datastore.DoesNotExistError(fqID)
125120
return nil
126121
}
127122

@@ -163,11 +158,3 @@ func String(ctx context.Context, fetch FetchFunc, keyFmt string, a ...interface{
163158
fetch(ctx, &value, keyFmt, a...)
164159
return value
165160
}
166-
167-
// DoesNotExistError is thrown by the methods of a Fetcher when an object does
168-
// not exist.
169-
type DoesNotExistError string
170-
171-
func (e DoesNotExistError) Error() string {
172-
return fmt.Sprintf("%s does not exist.", string(e))
173-
}

pkg/datastore/fetch_test.go renamed to internal/projector/datastore/fetch_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"testing"
99

10-
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
10+
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/datastore"
1111
"github.com/OpenSlides/openslides-autoupdate-service/pkg/dsmock"
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"

internal/projector/projector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"fmt"
88
"strings"
99

10-
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
10+
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/datastore"
1111
)
1212

1313
// Datastore gets values for keys and informs, if they change.

internal/projector/projector_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"testing"
99

1010
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector"
11-
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
11+
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/datastore"
1212
"github.com/OpenSlides/openslides-autoupdate-service/pkg/dsmock"
1313
"github.com/stretchr/testify/assert"
1414
"github.com/stretchr/testify/require"

internal/projector/slide/agenda.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"strings"
99

1010
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector"
11-
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
11+
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/datastore"
1212
)
1313

1414
type dbAgendaItem struct {

internal/projector/slide/agenda_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"testing"
66

77
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector"
8+
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/datastore"
89
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/slide"
9-
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
1010
"github.com/OpenSlides/openslides-autoupdate-service/pkg/dsmock"
1111
"github.com/stretchr/testify/assert"
1212
)

internal/projector/slide/assignment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"sort"
88

99
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector"
10-
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
10+
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/datastore"
1111
)
1212

1313
type dbAssignment struct {

internal/projector/slide/assignment_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"testing"
66

77
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector"
8+
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/datastore"
89
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/slide"
9-
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
1010
"github.com/OpenSlides/openslides-autoupdate-service/pkg/dsmock"
1111
"github.com/stretchr/testify/assert"
1212
)

internal/projector/slide/list_of_speakers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector"
12-
"github.com/OpenSlides/openslides-autoupdate-service/pkg/datastore"
12+
"github.com/OpenSlides/openslides-autoupdate-service/internal/projector/datastore"
1313
)
1414

1515
type dbListOfSpeakers struct {

0 commit comments

Comments
 (0)