-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemstore.go
39 lines (32 loc) · 970 Bytes
/
memstore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package store
import (
"context"
"github.com/ricleal/twitter-clone/internal/service/repository"
"github.com/ricleal/twitter-clone/internal/service/repository/memory"
)
type memStore struct {
TransactionError bool
users repository.UserRepository
tweets repository.TweetRepository
}
// NewMemStore creates a new memory store.
func NewMemStore() *memStore {
// Note that we are using the memory repository implementations here.
// When we use Tweets() or Users() we are returning the current memory repository
return &memStore{
users: memory.NewUserHandler(),
tweets: memory.NewTweetHandler(),
}
}
func (s *memStore) Tweets() repository.TweetRepository {
return s.tweets
}
func (s *memStore) Users() repository.UserRepository {
return s.users
}
func (s *memStore) ExecTx(_ context.Context, fn func(Store) error) error {
if s.TransactionError {
return NewExecTxError("a transaction related error occurred")
}
return fn(s)
}