3
0

Removed types.Field

This commit is contained in:
Mitja Zivkovic
2018-12-24 11:08:31 +01:00
committed by Denis Arh
parent a7e4e34a75
commit 672c38747f
11 changed files with 2 additions and 264 deletions

View File

@@ -1,37 +1,4 @@
[
{
"title": "Fields",
"description": "CRM input field definitions",
"package": "crm",
"entrypoint": "field",
"path": "/field",
"authentication": [],
"struct": [],
"apis": [
{
"name": "list",
"method": "GET",
"path": "/",
"title": "List available fields"
},
{
"name": "type",
"path": "/{typeID}",
"method": "GET",
"title": "Get field details",
"parameters": {
"path": [
{
"type": "string",
"name": "typeID",
"required": true,
"title": "Type ID"
}
]
}
}
]
},
{
"title": "Workflows",
"description": "CRM workflow definitions",

View File

@@ -1,36 +0,0 @@
{
"Title": "Fields",
"Description": "CRM input field definitions",
"Package": "crm",
"Interface": "Field",
"Struct": [],
"Parameters": null,
"Protocol": "",
"Authentication": [],
"Path": "/field",
"APIs": [
{
"Name": "list",
"Method": "GET",
"Title": "List available fields",
"Path": "/",
"Parameters": null
},
{
"Name": "type",
"Method": "GET",
"Title": "Get field details",
"Path": "/{typeID}",
"Parameters": {
"path": [
{
"name": "typeID",
"required": true,
"title": "Type ID",
"type": "string"
}
]
}
}
]
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1 @@
DROP TABLE `crm_field`;

View File

@@ -1,44 +0,0 @@
package repository
import (
"context"
"github.com/titpetric/factory"
"github.com/crusttech/crust/crm/types"
)
type (
FieldRepository interface {
With(ctx context.Context, db *factory.DB) FieldRepository
FindByType(t string) (*types.Field, error)
Find() ([]*types.Field, error)
}
field struct {
*repository
}
)
func Field(ctx context.Context, db *factory.DB) FieldRepository {
return (&field{}).With(ctx, db)
}
func (r *field) With(ctx context.Context, db *factory.DB) FieldRepository {
return &field{
repository: r.repository.With(ctx, db),
}
}
// FindByName returns field with a given name
func (f *field) FindByType(t string) (*types.Field, error) {
res := &types.Field{}
return res, f.db().Get(res, "SELECT * from crm_field where field_type=?", t)
}
// Find returns all known fields
func (f *field) Find() ([]*types.Field, error) {
mod := make([]*types.Field, 0)
return mod, f.db().Select(&mod, "SELECT * FROM crm_field ORDER BY field_name ASC")
}

View File

@@ -1,34 +0,0 @@
package rest
import (
"context"
"github.com/crusttech/crust/crm/rest/request"
"github.com/crusttech/crust/crm/service"
"github.com/crusttech/crust/crm/types"
)
type (
Field struct {
field service.FieldService
}
FieldService interface {
FindByType(ctx context.Context, t string) (*types.Field, error)
Find(ctx context.Context) ([]*types.Field, error)
}
)
func (Field) New() *Field {
return &Field{
field: service.DefaultField,
}
}
func (s *Field) List(ctx context.Context, _ *request.FieldList) (interface{}, error) {
return s.field.With(ctx).Find()
}
func (s *Field) Type(ctx context.Context, r *request.FieldType) (interface{}, error) {
return s.field.With(ctx).FindByType(r.TypeID)
}

View File

@@ -1,46 +0,0 @@
package service
import (
"context"
"github.com/titpetric/factory"
"github.com/crusttech/crust/crm/repository"
"github.com/crusttech/crust/crm/types"
)
type (
field struct {
db *factory.DB
ctx context.Context
repository repository.FieldRepository
}
FieldService interface {
With(ctx context.Context) FieldService
FindByType(t string) (*types.Field, error)
Find() ([]*types.Field, error)
}
)
func Field() FieldService {
return (&field{}).With(context.Background())
}
func (s *field) With(ctx context.Context) FieldService {
db := repository.DB(ctx)
return &field{
db: db,
ctx: ctx,
repository: repository.Field(ctx, db),
}
}
func (s *field) FindByType(t string) (*types.Field, error) {
return s.repository.FindByType(t)
}
func (s *field) Find() ([]*types.Field, error) {
return s.repository.Find()
}

View File

@@ -1,27 +0,0 @@
package service
import (
"context"
"testing"
)
func TestField(t *testing.T) {
repository := Field().With(context.Background())
{
// fetch all fields
{
ms, err := repository.Find()
must(t, err, "Error when retrieving fields")
assert(t, len(ms) > 1, "Expected more than one field")
}
// fetch named field
{
m, err := repository.FindByType("email")
must(t, err, "Error when retrieving field by name")
assert(t, m != nil, "Unexpected nil value for field by name")
assert(t, m.Type == "email", "Unexpected type, expected email, got %s", m.Type)
}
}
}

View File

@@ -7,7 +7,6 @@ import (
var (
o sync.Once
DefaultRecord RecordService
DefaultField FieldService
DefaultModule ModuleService
DefaultChart ChartService
DefaultPage PageService
@@ -18,7 +17,6 @@ var (
func Init() {
o.Do(func() {
DefaultRecord = Record()
DefaultField = Field()
DefaultModule = Module()
DefaultPage = Page()
DefaultChart = Chart()

View File

@@ -45,13 +45,6 @@ type (
RelatedRecordID string `json:"-" db:"rel_record_id"`
}
// Field - CRM input field definitions
Field struct {
Name string `json:"name" db:"field_name"`
Type string `json:"type" db:"field_type"`
Template string `json:"template,omitempty" db:"field_template"`
}
// Modules - CRM module definitions
Module struct {
ID uint64 `json:"moduleID,string" db:"id"`

View File

@@ -75,40 +75,6 @@
# Fields
CRM input field definitions
## List available fields
#### Method
| URI | Protocol | Method | Authentication |
| --- | -------- | ------ | -------------- |
| `/field/` | HTTP/S | GET | |
#### Request parameters
| Parameter | Type | Method | Description | Default | Required? |
| --------- | ---- | ------ | ----------- | ------- | --------- |
## Get field details
#### Method
| URI | Protocol | Method | Authentication |
| --- | -------- | ------ | -------------- |
| `/field/{typeID}` | HTTP/S | GET | |
#### Request parameters
| Parameter | Type | Method | Description | Default | Required? |
| --------- | ---- | ------ | ----------- | ------- | --------- |
| typeID | string | PATH | Type ID | N/A | YES |
# Jobs
Workflow Jobs