Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
issue #165: work above ProtectedStorage, review work with token
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Sep 5, 2018
1 parent 9b2e9bd commit 0e5498e
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 54 deletions.
21 changes: 10 additions & 11 deletions pkg/server/grpc/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import (

// ProtectedStorage TODO
type ProtectedStorage interface {
TokenByID(context.Context, domain.ID) (*types.Token, error)
CreateSchema(context.Context, *types.Token, query.CreateSchema) (types.Schema, error)
ReadSchema(context.Context, *types.Token, query.ReadSchema) (types.Schema, error)
UpdateSchema(context.Context, *types.Token, query.UpdateSchema) (types.Schema, error)
DeleteSchema(context.Context, *types.Token, query.DeleteSchema) (types.Schema, error)
CreateTemplate(context.Context, *types.Token, query.CreateTemplate) (types.Template, error)
ReadTemplate(context.Context, *types.Token, query.ReadTemplate) (types.Template, error)
UpdateTemplate(context.Context, *types.Token, query.UpdateTemplate) (types.Template, error)
DeleteTemplate(context.Context, *types.Token, query.DeleteTemplate) (types.Template, error)
ReadInputByID(context.Context, *types.Token, domain.ID) (types.Input, error)
ReadInputByFilter(context.Context, *types.Token, query.InputFilter) ([]types.Input, error)
CreateSchema(ctx context.Context, tokenID domain.ID, data query.CreateSchema) (types.Schema, error)
ReadSchema(ctx context.Context, tokenID domain.ID, data query.ReadSchema) (types.Schema, error)
UpdateSchema(ctx context.Context, tokenID domain.ID, data query.UpdateSchema) (types.Schema, error)
DeleteSchema(ctx context.Context, tokenID domain.ID, data query.DeleteSchema) (types.Schema, error)
CreateTemplate(ctx context.Context, tokenID domain.ID, data query.CreateTemplate) (types.Template, error)
ReadTemplate(ctx context.Context, tokenID domain.ID, data query.ReadTemplate) (types.Template, error)
UpdateTemplate(ctx context.Context, tokenID domain.ID, data query.UpdateTemplate) (types.Template, error)
DeleteTemplate(ctx context.Context, tokenID domain.ID, data query.DeleteTemplate) (types.Template, error)
ReadInputByID(ctx context.Context, tokenID, id domain.ID) (types.Input, error)
ReadInputByFilter(ctx context.Context, tokenID domain.ID, data query.InputFilter) ([]types.Input, error)
}
33 changes: 10 additions & 23 deletions pkg/server/grpc/mock_storage_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

69 changes: 49 additions & 20 deletions pkg/storage/protected.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,123 +8,152 @@ import (
"github.com/kamilsk/form-api/pkg/storage/types"
)

// TokenByID TODO
func (storage *Storage) TokenByID(ctx context.Context, id domain.ID) (*types.Token, error) {
// CreateSchema TODO
func (storage *Storage) CreateSchema(ctx context.Context, tokenID domain.ID, data query.CreateSchema) (types.Schema, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return nil, err
return types.Schema{}, err
}
defer closer()

return storage.exec.UserManager(ctx, conn).Token(id)
}

// CreateSchema TODO
func (storage *Storage) CreateSchema(ctx context.Context, token *types.Token, data query.CreateSchema) (types.Schema, error) {
conn, closer, err := storage.connection(ctx)
token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Schema{}, err
}
defer closer()

return storage.exec.SchemaEditor(ctx, conn).Create(token, data)
}

// ReadSchema TODO
func (storage *Storage) ReadSchema(ctx context.Context, token *types.Token, data query.ReadSchema) (types.Schema, error) {
func (storage *Storage) ReadSchema(ctx context.Context, tokenID domain.ID, data query.ReadSchema) (types.Schema, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return types.Schema{}, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Schema{}, err
}
return storage.exec.SchemaEditor(ctx, conn).Read(token, data)
}

// UpdateSchema TODO
func (storage *Storage) UpdateSchema(ctx context.Context, token *types.Token, data query.UpdateSchema) (types.Schema, error) {
func (storage *Storage) UpdateSchema(ctx context.Context, tokenID domain.ID, data query.UpdateSchema) (types.Schema, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return types.Schema{}, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Schema{}, err
}
return storage.exec.SchemaEditor(ctx, conn).Update(token, data)
}

// DeleteSchema TODO
func (storage *Storage) DeleteSchema(ctx context.Context, token *types.Token, data query.DeleteSchema) (types.Schema, error) {
func (storage *Storage) DeleteSchema(ctx context.Context, tokenID domain.ID, data query.DeleteSchema) (types.Schema, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return types.Schema{}, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Schema{}, err
}
return storage.exec.SchemaEditor(ctx, conn).Delete(token, data)
}

// CreateTemplate TODO
func (storage *Storage) CreateTemplate(ctx context.Context, token *types.Token, data query.CreateTemplate) (types.Template, error) {
func (storage *Storage) CreateTemplate(ctx context.Context, tokenID domain.ID, data query.CreateTemplate) (types.Template, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return types.Template{}, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Template{}, err
}
return storage.exec.TemplateEditor(ctx, conn).Create(token, data)
}

// ReadTemplate TODO
func (storage *Storage) ReadTemplate(ctx context.Context, token *types.Token, data query.ReadTemplate) (types.Template, error) {
func (storage *Storage) ReadTemplate(ctx context.Context, tokenID domain.ID, data query.ReadTemplate) (types.Template, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return types.Template{}, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Template{}, err
}
return storage.exec.TemplateEditor(ctx, conn).Read(token, data)
}

// UpdateTemplate TODO
func (storage *Storage) UpdateTemplate(ctx context.Context, token *types.Token, data query.UpdateTemplate) (types.Template, error) {
func (storage *Storage) UpdateTemplate(ctx context.Context, tokenID domain.ID, data query.UpdateTemplate) (types.Template, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return types.Template{}, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Template{}, err
}
return storage.exec.TemplateEditor(ctx, conn).Update(token, data)
}

// DeleteTemplate TODO
func (storage *Storage) DeleteTemplate(ctx context.Context, token *types.Token, data query.DeleteTemplate) (types.Template, error) {
func (storage *Storage) DeleteTemplate(ctx context.Context, tokenID domain.ID, data query.DeleteTemplate) (types.Template, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return types.Template{}, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Template{}, err
}
return storage.exec.TemplateEditor(ctx, conn).Delete(token, data)
}

// ReadInputByID TODO
func (storage *Storage) ReadInputByID(ctx context.Context, token *types.Token, id domain.ID) (types.Input, error) {
func (storage *Storage) ReadInputByID(ctx context.Context, tokenID domain.ID, id domain.ID) (types.Input, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return types.Input{}, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return types.Input{}, err
}
return storage.exec.InputReader(ctx, conn).ReadByID(token, id)
}

// ReadInputByFilter TODO
func (storage *Storage) ReadInputByFilter(ctx context.Context, token *types.Token, filter query.InputFilter) ([]types.Input, error) {
func (storage *Storage) ReadInputByFilter(ctx context.Context, tokenID domain.ID, filter query.InputFilter) ([]types.Input, error) {
conn, closer, err := storage.connection(ctx)
if err != nil {
return nil, err
}
defer closer()

token, err := storage.exec.UserManager(ctx, conn).Token(tokenID)
if err != nil {
return nil, err
}
return storage.exec.InputReader(ctx, conn).ReadByFilter(token, filter)
}

0 comments on commit 0e5498e

Please sign in to comment.