Abstracting more the store concept

This commit is contained in:
Jesús Espino 2020-10-16 19:20:43 +02:00
parent 19ab85b329
commit 55e49bea51
5 changed files with 24 additions and 5 deletions

View file

@ -14,6 +14,9 @@ packdev:
go: go:
go build -o $(GOBIN) $(GOMAIN) go build -o $(GOBIN) $(GOMAIN)
watch-server:
cd server; modd
goUbuntu: goUbuntu:
env GOOS=linux GOARCH=amd64 go build -o $(GOBIN) $(GOMAIN) env GOOS=linux GOARCH=amd64 go build -o $(GOBIN) $(GOMAIN)

View file

@ -18,11 +18,11 @@ import (
type App struct { type App struct {
config *config.Configuration config *config.Configuration
store *store.SQLStore store store.Store
wsServer *ws.WSServer wsServer *ws.WSServer
} }
func New(config *config.Configuration, store *store.SQLStore, wsServer *ws.WSServer) *App { func New(config *config.Configuration, store store.Store, wsServer *ws.WSServer) *App {
return &App{config: config, store: store, wsServer: wsServer} return &App{config: config, store: store, wsServer: wsServer}
} }

View file

@ -9,6 +9,7 @@ import (
"github.com/mattermost/mattermost-octo-tasks/server/app" "github.com/mattermost/mattermost-octo-tasks/server/app"
"github.com/mattermost/mattermost-octo-tasks/server/services/config" "github.com/mattermost/mattermost-octo-tasks/server/services/config"
"github.com/mattermost/mattermost-octo-tasks/server/services/store" "github.com/mattermost/mattermost-octo-tasks/server/services/store"
"github.com/mattermost/mattermost-octo-tasks/server/services/store/sqlstore"
"github.com/mattermost/mattermost-octo-tasks/server/web" "github.com/mattermost/mattermost-octo-tasks/server/web"
"github.com/mattermost/mattermost-octo-tasks/server/ws" "github.com/mattermost/mattermost-octo-tasks/server/ws"
) )
@ -17,11 +18,11 @@ type Server struct {
config *config.Configuration config *config.Configuration
wsServer *ws.WSServer wsServer *ws.WSServer
webServer *web.WebServer webServer *web.WebServer
store *store.SQLStore store store.Store
} }
func New(config *config.Configuration) (*Server, error) { func New(config *config.Configuration) (*Server, error) {
store, err := store.NewSQLStore(config.DBType, config.DBConfigString) store, err := sqlstore.NewSQLStore(config.DBType, config.DBConfigString)
if err != nil { if err != nil {
log.Fatal("Unable to start the database", err) log.Fatal("Unable to start the database", err)
return nil, err return nil, err

View file

@ -1,4 +1,4 @@
package store package sqlstore
import ( import (
"database/sql" "database/sql"

View file

@ -0,0 +1,15 @@
package store
import "github.com/mattermost/mattermost-octo-tasks/server/model"
// Store represents the abstraction of the data storage
type Store interface {
GetBlocksWithParentAndType(parentID string, blockType string) ([]model.Block, error)
GetBlocksWithParent(parentID string) ([]model.Block, error)
GetBlocksWithType(blockType string) ([]model.Block, error)
GetSubTree(blockID string) ([]model.Block, error)
GetAllBlocks() ([]model.Block, error)
GetParentID(blockID string) (string, error)
InsertBlock(block model.Block) error
DeleteBlock(blockID string) error
}