flattener

package
v0.0.0-...-47e58eb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package flattener is a generated GoMock package.

Package flattener is a generated GoMock package.

Index

Constants

View Source
const (
	FlatCollection = "flats"
	DbName         = "flattenerdb"
	DbNameTest     = "flattenerdbtest"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DataInfo

type DataInfo struct {
	DataType  string `bson:"type"`
	DataValue string `bson:"value"`
}

DataInfo represents the information of the value of the array node

type EdgeSecuence

type EdgeSecuence struct {
	From int `bson:"from"`
	To   int `bson:"to"`
}

EdgeSecuence represents the connections between the nodes

type FlatInfo

type FlatInfo struct {
	ID             string           `json:"id" bson:"_id,omitempty"`
	Graph          *Graph           `bson:"-"`
	VertexSecuence []VertexSecuence `bson:"vertex_secuence"`
	MaxDepth       int              `bson:"max_depth"`
	ProcessedAt    time.Time        `bson:"processed_at"`
}

FlatInfo represents the structure to be saved in the db

func FlatArray

func FlatArray(input []interface{}) (FlatInfo, apierrors.RestErr)

FlatArray it receive an input array an recursive will find the max depth of the array and will build a Graph. This info is wrapped in a FlatInfo

type FlatInfoResponse

type FlatInfoResponse struct {
	ID          string        `json:"id"`
	ProcessedAt time.Time     `json:"processed_at"`
	Unflatted   []interface{} `json:"unflatted"`
	Flatted     []interface{} `json:"flatted"`
}

FlatResponse represents the client response for GET /flats

type FlatResponse

type FlatResponse struct {
	MaxDepth int           `json:"max_depth"`
	Data     []interface{} `json:"flatted_data"`
}

FlatResponse represents the client response for POST /flats

type Gateway

type Gateway interface {
	// FlatResponse will try to flat an array of mixed simple values an will save a FlatInfo
	// returns a FlatResponse with the flatted array and the max depth
	FlatResponse([]interface{}) (FlatResponse, apierrors.RestErr)

	// GetFlats will return a FlatInfoResponse that contains ->
	// id: auto-generated by the db;
	// processed_at: is the date when the process was made;
	// flatted: the original array flatted;
	// unflatted: the original request array;
	GetFlats() ([]FlatInfoResponse, apierrors.RestErr)
}

func NewGateway

func NewGateway(s Storage) Gateway

type Graph

type Graph struct {
	Vertices map[int]*Vertex
	// contains filtered or unexported fields
}

Graph contains all the information about the array knows how to flat and unflat an array

func BuildGraphFromVertexSecuence

func BuildGraphFromVertexSecuence(vertexSecuence []VertexSecuence) (*Graph, apierrors.RestErr)

func NewDirectedGraph

func NewDirectedGraph() *Graph

func (*Graph) AddEdge

func (g *Graph) AddEdge(k1, k2 int) error

AddEdge connect to Vertex

func (*Graph) AddVertex

func (g *Graph) AddVertex(key int, val interface{})

AddVertex creates a new Vertex and added to the Graph

func (*Graph) GetVertexSecuence

func (g *Graph) GetVertexSecuence() []VertexSecuence

GetVertexSecuence build the secuence necesary to be saved in db to be use to rebuild the Graph and the array

func (*Graph) ToArray

func (g *Graph) ToArray() []interface{}

ToArray will build the array with the information in the Graph

func (*Graph) ToFlat

func (g *Graph) ToFlat() []interface{}

ToFlat will return the flatted array with the Graph information

type Handler

type Handler interface {
	Post(c *gin.Context)
	GetAll(c *gin.Context)
}

func NewHandler

func NewHandler(flatGateway Gateway) Handler

type MockGateway

type MockGateway struct {
	// contains filtered or unexported fields
}

MockGateway is a mock of Gateway interface.

func NewMockGateway

func NewMockGateway(ctrl *gomock.Controller) *MockGateway

NewMockGateway creates a new mock instance.

func (*MockGateway) EXPECT

func (m *MockGateway) EXPECT() *MockGatewayMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockGateway) FlatResponse

func (m *MockGateway) FlatResponse(arg0 []interface{}) (FlatResponse, apierrors.RestErr)

FlatResponse mocks base method.

func (*MockGateway) GetFlats

func (m *MockGateway) GetFlats() ([]FlatInfoResponse, apierrors.RestErr)

GetFlats mocks base method.

type MockGatewayMockRecorder

type MockGatewayMockRecorder struct {
	// contains filtered or unexported fields
}

MockGatewayMockRecorder is the mock recorder for MockGateway.

func (*MockGatewayMockRecorder) FlatResponse

func (mr *MockGatewayMockRecorder) FlatResponse(arg0 interface{}) *gomock.Call

FlatResponse indicates an expected call of FlatResponse.

func (*MockGatewayMockRecorder) GetFlats

func (mr *MockGatewayMockRecorder) GetFlats() *gomock.Call

GetFlats indicates an expected call of GetFlats.

type MockStorage

type MockStorage struct {
	// contains filtered or unexported fields
}

MockStorage is a mock of Storage interface.

func NewMockStorage

func NewMockStorage(ctrl *gomock.Controller) *MockStorage

NewMockStorage creates a new mock instance.

func (*MockStorage) EXPECT

func (m *MockStorage) EXPECT() *MockStorageMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

type MockStorageMockRecorder

type MockStorageMockRecorder struct {
	// contains filtered or unexported fields
}

MockStorageMockRecorder is the mock recorder for MockStorage.

type Storage

type Storage interface {
	// contains filtered or unexported methods
}

Storage will execute all de CRUD operations flat_info related

func NewStorage

func NewStorage(db *mongo.Client) Storage

func NewTestStorage

func NewTestStorage(db *mongo.Client) Storage

type Vertex

type Vertex struct {
	Key      int
	Value    interface{}
	Vertices map[int]*Vertex
}

Vertex represents the nodes in the Graph and the connection between each other

func NewVertex

func NewVertex(key int, value interface{}) *Vertex

func (*Vertex) GetVertexSecuence

func (v *Vertex) GetVertexSecuence() VertexSecuence

GetVertexSecuence is called by Graph

func (*Vertex) ToArray

func (v *Vertex) ToArray() interface{}

ToArray is called by Graph to build the array

func (*Vertex) ToFlat

func (v *Vertex) ToFlat() interface{}

ToFlat is called by Graph to build the flaated array

type VertexSecuence

type VertexSecuence struct {
	Key      int      `bson:"key"`
	DataInfo DataInfo `bson:"data"`
	Edges    []int    `json:"edges"`
}

VertexSecuence contains all the nodes information to restore the flatted array with the EdgeSecuence

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL