Remove old module/chart rest/svc/repo
This commit is contained in:
parent
7b39b764f8
commit
7ff12554b2
@ -7,7 +7,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/crm/rest/request"
|
||||
"github.com/crusttech/crust/crm/types"
|
||||
)
|
||||
|
||||
@ -15,8 +14,6 @@ type (
|
||||
ModuleRepository interface {
|
||||
With(ctx context.Context, db *factory.DB) ModuleRepository
|
||||
|
||||
Chart(r *request.ModuleChart) (interface{}, error)
|
||||
|
||||
FindByID(id uint64) (*types.Module, error)
|
||||
Find() (types.ModuleSet, error)
|
||||
Create(mod *types.Module) (*types.Module, error)
|
||||
|
||||
@ -30,7 +30,6 @@ type ModuleAPI interface {
|
||||
List(context.Context, *request.ModuleList) (interface{}, error)
|
||||
Create(context.Context, *request.ModuleCreate) (interface{}, error)
|
||||
Read(context.Context, *request.ModuleRead) (interface{}, error)
|
||||
Chart(context.Context, *request.ModuleChart) (interface{}, error)
|
||||
Edit(context.Context, *request.ModuleEdit) (interface{}, error)
|
||||
Delete(context.Context, *request.ModuleDelete) (interface{}, error)
|
||||
ContentReport(context.Context, *request.ModuleContentReport) (interface{}, error)
|
||||
@ -46,7 +45,6 @@ type Module struct {
|
||||
List func(http.ResponseWriter, *http.Request)
|
||||
Create func(http.ResponseWriter, *http.Request)
|
||||
Read func(http.ResponseWriter, *http.Request)
|
||||
Chart func(http.ResponseWriter, *http.Request)
|
||||
Edit func(http.ResponseWriter, *http.Request)
|
||||
Delete func(http.ResponseWriter, *http.Request)
|
||||
ContentReport func(http.ResponseWriter, *http.Request)
|
||||
@ -80,13 +78,6 @@ func NewModule(mh ModuleAPI) *Module {
|
||||
return mh.Read(r.Context(), params)
|
||||
})
|
||||
},
|
||||
Chart: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewModuleChart()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return mh.Chart(r.Context(), params)
|
||||
})
|
||||
},
|
||||
Edit: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewModuleEdit()
|
||||
@ -153,7 +144,6 @@ func (mh *Module) MountRoutes(r chi.Router, middlewares ...func(http.Handler) ht
|
||||
r.Get("/", mh.List)
|
||||
r.Post("/", mh.Create)
|
||||
r.Get("/{moduleID}", mh.Read)
|
||||
r.Get("/{moduleID}/chart", mh.Chart)
|
||||
r.Post("/{moduleID}", mh.Edit)
|
||||
r.Delete("/{moduleID}", mh.Delete)
|
||||
r.Get("/{moduleID}/report", mh.ContentReport)
|
||||
|
||||
@ -37,10 +37,6 @@ func (s *Module) Delete(ctx context.Context, r *request.ModuleDelete) (interface
|
||||
return resputil.OK(), s.module.With(ctx).DeleteByID(r.ModuleID)
|
||||
}
|
||||
|
||||
func (s *Module) Chart(ctx context.Context, r *request.ModuleChart) (interface{}, error) {
|
||||
return s.module.With(ctx).Chart(r)
|
||||
}
|
||||
|
||||
func (s *Module) Create(ctx context.Context, r *request.ModuleCreate) (interface{}, error) {
|
||||
item := &types.Module{
|
||||
Name: r.Name,
|
||||
|
||||
@ -168,99 +168,6 @@ func (m *ModuleRead) Fill(r *http.Request) (err error) {
|
||||
|
||||
var _ RequestFiller = NewModuleRead()
|
||||
|
||||
// Module chart request parameters
|
||||
type ModuleChart struct {
|
||||
Name string
|
||||
Description string
|
||||
XAxis string
|
||||
XMin string
|
||||
XMax string
|
||||
YAxis string
|
||||
GroupBy string
|
||||
Sum string
|
||||
Count string
|
||||
Kind string
|
||||
ModuleID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
func NewModuleChart() *ModuleChart {
|
||||
return &ModuleChart{}
|
||||
}
|
||||
|
||||
func (m *ModuleChart) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(m)
|
||||
|
||||
switch {
|
||||
case err == io.EOF:
|
||||
err = nil
|
||||
case err != nil:
|
||||
return errors.Wrap(err, "error parsing http request body")
|
||||
}
|
||||
}
|
||||
|
||||
if err = r.ParseForm(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
get := map[string]string{}
|
||||
post := map[string]string{}
|
||||
urlQuery := r.URL.Query()
|
||||
for name, param := range urlQuery {
|
||||
get[name] = string(param[0])
|
||||
}
|
||||
postVars := r.Form
|
||||
for name, param := range postVars {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
if val, ok := get["name"]; ok {
|
||||
|
||||
m.Name = val
|
||||
}
|
||||
if val, ok := get["description"]; ok {
|
||||
|
||||
m.Description = val
|
||||
}
|
||||
if val, ok := get["xAxis"]; ok {
|
||||
|
||||
m.XAxis = val
|
||||
}
|
||||
if val, ok := get["xMin"]; ok {
|
||||
|
||||
m.XMin = val
|
||||
}
|
||||
if val, ok := get["xMax"]; ok {
|
||||
|
||||
m.XMax = val
|
||||
}
|
||||
if val, ok := get["yAxis"]; ok {
|
||||
|
||||
m.YAxis = val
|
||||
}
|
||||
if val, ok := get["groupBy"]; ok {
|
||||
|
||||
m.GroupBy = val
|
||||
}
|
||||
if val, ok := get["sum"]; ok {
|
||||
|
||||
m.Sum = val
|
||||
}
|
||||
if val, ok := get["count"]; ok {
|
||||
|
||||
m.Count = val
|
||||
}
|
||||
if val, ok := get["kind"]; ok {
|
||||
|
||||
m.Kind = val
|
||||
}
|
||||
m.ModuleID = parseUInt64(chi.URLParam(r, "moduleID"))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewModuleChart()
|
||||
|
||||
// Module edit request parameters
|
||||
type ModuleEdit struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
|
||||
@ -1,27 +1,9 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/crusttech/crust/crm/rest/request"
|
||||
)
|
||||
|
||||
func TestModuleGraph(t *testing.T) {
|
||||
repository := Module().With(context.Background())
|
||||
|
||||
params := &request.ModuleChart{
|
||||
Kind: "line",
|
||||
}
|
||||
|
||||
{
|
||||
_, err := repository.Chart(params)
|
||||
assert(t, err == nil, "Error when getting module graph: %+v", err)
|
||||
}
|
||||
|
||||
{
|
||||
params.Kind = "404"
|
||||
_, err := repository.Chart(params)
|
||||
assert(t, err != nil, "Expected error when getting chart for 404")
|
||||
}
|
||||
// repository := Module().With(context.Background())
|
||||
}
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"github.com/titpetric/factory"
|
||||
|
||||
"github.com/crusttech/crust/crm/repository"
|
||||
"github.com/crusttech/crust/crm/rest/request"
|
||||
"github.com/crusttech/crust/crm/types"
|
||||
)
|
||||
|
||||
@ -23,8 +22,6 @@ type (
|
||||
ModuleService interface {
|
||||
With(ctx context.Context) ModuleService
|
||||
|
||||
Chart(r *request.ModuleChart) (interface{}, error)
|
||||
|
||||
FindByID(moduleID uint64) (*types.Module, error)
|
||||
Find() ([]*types.Module, error)
|
||||
|
||||
@ -65,10 +62,6 @@ func (s *module) Find() ([]*types.Module, error) {
|
||||
return s.moduleRepo.Find()
|
||||
}
|
||||
|
||||
func (s *module) Chart(r *request.ModuleChart) (interface{}, error) {
|
||||
return s.moduleRepo.Chart(r)
|
||||
}
|
||||
|
||||
func (s *module) Create(mod *types.Module) (*types.Module, error) {
|
||||
if len(mod.Fields) == 0 {
|
||||
return nil, errors.New("Error creating module: no fields")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user