Rename content to record on endpoints
This commit is contained in:
committed by
Denis Arh
parent
57c97c63a0
commit
37eb4ceccd
@@ -658,7 +658,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "content/report",
|
||||
"name": "record/report",
|
||||
"method": "GET",
|
||||
"title": "Generates report from module records",
|
||||
"path": "/{moduleID}/report",
|
||||
@@ -688,10 +688,10 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "content/list",
|
||||
"name": "record/list",
|
||||
"method": "GET",
|
||||
"title": "List/read contents from module section",
|
||||
"path": "/{moduleID}/content",
|
||||
"title": "List/read records from module section",
|
||||
"path": "/{moduleID}/record",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -730,10 +730,10 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "content/create",
|
||||
"name": "record/create",
|
||||
"method": "POST",
|
||||
"title": "List/read contents from module section",
|
||||
"path": "/{moduleID}/content",
|
||||
"title": "Create record in module section",
|
||||
"path": "/{moduleID}/record",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -748,16 +748,16 @@
|
||||
"type": "sqlxTypes.JSONText",
|
||||
"name": "fields",
|
||||
"required": true,
|
||||
"title": "Content JSON"
|
||||
"title": "Record JSON"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "content/read",
|
||||
"name": "record/read",
|
||||
"method": "GET",
|
||||
"title": "Read contents by ID from module section",
|
||||
"path": "/{moduleID}/content/{contentID}",
|
||||
"title": "Read records by ID from module section",
|
||||
"path": "/{moduleID}/record/{recordID}",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -768,18 +768,18 @@
|
||||
},
|
||||
{
|
||||
"type": "uint64",
|
||||
"name": "contentID",
|
||||
"name": "recordID",
|
||||
"required": true,
|
||||
"title": "Content ID"
|
||||
"title": "Record ID"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "content/edit",
|
||||
"name": "record/edit",
|
||||
"method": "POST",
|
||||
"title": "Add/update contents in module section",
|
||||
"path": "/{moduleID}/content/{contentID}",
|
||||
"title": "Add/update records in module section",
|
||||
"path": "/{moduleID}/record/{recordID}",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -790,9 +790,9 @@
|
||||
},
|
||||
{
|
||||
"type": "uint64",
|
||||
"name": "contentID",
|
||||
"name": "recordID",
|
||||
"required": true,
|
||||
"title": "Content ID"
|
||||
"title": "Record ID"
|
||||
}
|
||||
],
|
||||
"post": [
|
||||
@@ -800,16 +800,16 @@
|
||||
"type": "sqlxTypes.JSONText",
|
||||
"name": "fields",
|
||||
"required": true,
|
||||
"title": "Content JSON"
|
||||
"title": "Record JSON"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "content/delete",
|
||||
"name": "record/delete",
|
||||
"method": "DELETE",
|
||||
"title": "Delete content row from module section",
|
||||
"path": "/{moduleID}/content/{contentID}",
|
||||
"title": "Delete record row from module section",
|
||||
"path": "/{moduleID}/record/{recordID}",
|
||||
"parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -820,9 +820,9 @@
|
||||
},
|
||||
{
|
||||
"type": "uint64",
|
||||
"name": "contentID",
|
||||
"name": "recordID",
|
||||
"required": true,
|
||||
"title": "Content ID"
|
||||
"title": "Record ID"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "content/report",
|
||||
"Name": "record/report",
|
||||
"Method": "GET",
|
||||
"Title": "Generates report from module records",
|
||||
"Path": "/{moduleID}/report",
|
||||
@@ -147,10 +147,10 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "content/list",
|
||||
"Name": "record/list",
|
||||
"Method": "GET",
|
||||
"Title": "List/read contents from module section",
|
||||
"Path": "/{moduleID}/content",
|
||||
"Title": "List/read records from module section",
|
||||
"Path": "/{moduleID}/record",
|
||||
"Parameters": {
|
||||
"get": [
|
||||
{
|
||||
@@ -189,10 +189,10 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "content/create",
|
||||
"Name": "record/create",
|
||||
"Method": "POST",
|
||||
"Title": "List/read contents from module section",
|
||||
"Path": "/{moduleID}/content",
|
||||
"Title": "Create record in module section",
|
||||
"Path": "/{moduleID}/record",
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -206,17 +206,17 @@
|
||||
{
|
||||
"name": "fields",
|
||||
"required": true,
|
||||
"title": "Content JSON",
|
||||
"title": "Record JSON",
|
||||
"type": "sqlxTypes.JSONText"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "content/read",
|
||||
"Name": "record/read",
|
||||
"Method": "GET",
|
||||
"Title": "Read contents by ID from module section",
|
||||
"Path": "/{moduleID}/content/{contentID}",
|
||||
"Title": "Read records by ID from module section",
|
||||
"Path": "/{moduleID}/record/{recordID}",
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -226,19 +226,19 @@
|
||||
"type": "uint64"
|
||||
},
|
||||
{
|
||||
"name": "contentID",
|
||||
"name": "recordID",
|
||||
"required": true,
|
||||
"title": "Content ID",
|
||||
"title": "Record ID",
|
||||
"type": "uint64"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "content/edit",
|
||||
"Name": "record/edit",
|
||||
"Method": "POST",
|
||||
"Title": "Add/update contents in module section",
|
||||
"Path": "/{moduleID}/content/{contentID}",
|
||||
"Title": "Add/update records in module section",
|
||||
"Path": "/{moduleID}/record/{recordID}",
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -248,9 +248,9 @@
|
||||
"type": "uint64"
|
||||
},
|
||||
{
|
||||
"name": "contentID",
|
||||
"name": "recordID",
|
||||
"required": true,
|
||||
"title": "Content ID",
|
||||
"title": "Record ID",
|
||||
"type": "uint64"
|
||||
}
|
||||
],
|
||||
@@ -258,17 +258,17 @@
|
||||
{
|
||||
"name": "fields",
|
||||
"required": true,
|
||||
"title": "Content JSON",
|
||||
"title": "Record JSON",
|
||||
"type": "sqlxTypes.JSONText"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "content/delete",
|
||||
"Name": "record/delete",
|
||||
"Method": "DELETE",
|
||||
"Title": "Delete content row from module section",
|
||||
"Path": "/{moduleID}/content/{contentID}",
|
||||
"Title": "Delete record row from module section",
|
||||
"Path": "/{moduleID}/record/{recordID}",
|
||||
"Parameters": {
|
||||
"path": [
|
||||
{
|
||||
@@ -278,9 +278,9 @@
|
||||
"type": "uint64"
|
||||
},
|
||||
{
|
||||
"name": "contentID",
|
||||
"name": "recordID",
|
||||
"required": true,
|
||||
"title": "Content ID",
|
||||
"title": "Record ID",
|
||||
"type": "uint64"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -17,9 +17,10 @@ package handlers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/go-chi/chi"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi"
|
||||
|
||||
"github.com/titpetric/factory/resputil"
|
||||
|
||||
"github.com/crusttech/crust/crm/rest/request"
|
||||
@@ -32,27 +33,28 @@ type ModuleAPI interface {
|
||||
Read(context.Context, *request.ModuleRead) (interface{}, error)
|
||||
Edit(context.Context, *request.ModuleEdit) (interface{}, error)
|
||||
Delete(context.Context, *request.ModuleDelete) (interface{}, error)
|
||||
ContentReport(context.Context, *request.ModuleContentReport) (interface{}, error)
|
||||
ContentList(context.Context, *request.ModuleContentList) (interface{}, error)
|
||||
ContentCreate(context.Context, *request.ModuleContentCreate) (interface{}, error)
|
||||
ContentRead(context.Context, *request.ModuleContentRead) (interface{}, error)
|
||||
ContentEdit(context.Context, *request.ModuleContentEdit) (interface{}, error)
|
||||
ContentDelete(context.Context, *request.ModuleContentDelete) (interface{}, error)
|
||||
RecordReport(context.Context, *request.ModuleRecordReport) (interface{}, error)
|
||||
RecordList(context.Context, *request.ModuleRecordList) (interface{}, error)
|
||||
RecordCreate(context.Context, *request.ModuleRecordCreate) (interface{}, error)
|
||||
RecordRead(context.Context, *request.ModuleRecordRead) (interface{}, error)
|
||||
RecordEdit(context.Context, *request.ModuleRecordEdit) (interface{}, error)
|
||||
RecordDelete(context.Context, *request.ModuleRecordDelete) (interface{}, error)
|
||||
}
|
||||
|
||||
// HTTP API interface
|
||||
type Module struct {
|
||||
List func(http.ResponseWriter, *http.Request)
|
||||
Create func(http.ResponseWriter, *http.Request)
|
||||
Read func(http.ResponseWriter, *http.Request)
|
||||
Edit func(http.ResponseWriter, *http.Request)
|
||||
Delete func(http.ResponseWriter, *http.Request)
|
||||
ContentReport func(http.ResponseWriter, *http.Request)
|
||||
ContentList func(http.ResponseWriter, *http.Request)
|
||||
ContentCreate func(http.ResponseWriter, *http.Request)
|
||||
ContentRead func(http.ResponseWriter, *http.Request)
|
||||
ContentEdit func(http.ResponseWriter, *http.Request)
|
||||
ContentDelete func(http.ResponseWriter, *http.Request)
|
||||
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)
|
||||
RecordReport func(http.ResponseWriter, *http.Request)
|
||||
RecordList func(http.ResponseWriter, *http.Request)
|
||||
RecordCreate func(http.ResponseWriter, *http.Request)
|
||||
RecordRead func(http.ResponseWriter, *http.Request)
|
||||
RecordEdit func(http.ResponseWriter, *http.Request)
|
||||
RecordDelete func(http.ResponseWriter, *http.Request)
|
||||
}
|
||||
|
||||
func NewModule(mh ModuleAPI) *Module {
|
||||
@@ -92,46 +94,46 @@ func NewModule(mh ModuleAPI) *Module {
|
||||
return mh.Delete(r.Context(), params)
|
||||
})
|
||||
},
|
||||
ContentReport: func(w http.ResponseWriter, r *http.Request) {
|
||||
RecordReport: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewModuleContentReport()
|
||||
params := request.NewModuleRecordReport()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return mh.ContentReport(r.Context(), params)
|
||||
return mh.RecordReport(r.Context(), params)
|
||||
})
|
||||
},
|
||||
ContentList: func(w http.ResponseWriter, r *http.Request) {
|
||||
RecordList: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewModuleContentList()
|
||||
params := request.NewModuleRecordList()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return mh.ContentList(r.Context(), params)
|
||||
return mh.RecordList(r.Context(), params)
|
||||
})
|
||||
},
|
||||
ContentCreate: func(w http.ResponseWriter, r *http.Request) {
|
||||
RecordCreate: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewModuleContentCreate()
|
||||
params := request.NewModuleRecordCreate()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return mh.ContentCreate(r.Context(), params)
|
||||
return mh.RecordCreate(r.Context(), params)
|
||||
})
|
||||
},
|
||||
ContentRead: func(w http.ResponseWriter, r *http.Request) {
|
||||
RecordRead: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewModuleContentRead()
|
||||
params := request.NewModuleRecordRead()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return mh.ContentRead(r.Context(), params)
|
||||
return mh.RecordRead(r.Context(), params)
|
||||
})
|
||||
},
|
||||
ContentEdit: func(w http.ResponseWriter, r *http.Request) {
|
||||
RecordEdit: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewModuleContentEdit()
|
||||
params := request.NewModuleRecordEdit()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return mh.ContentEdit(r.Context(), params)
|
||||
return mh.RecordEdit(r.Context(), params)
|
||||
})
|
||||
},
|
||||
ContentDelete: func(w http.ResponseWriter, r *http.Request) {
|
||||
RecordDelete: func(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
params := request.NewModuleContentDelete()
|
||||
params := request.NewModuleRecordDelete()
|
||||
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
|
||||
return mh.ContentDelete(r.Context(), params)
|
||||
return mh.RecordDelete(r.Context(), params)
|
||||
})
|
||||
},
|
||||
}
|
||||
@@ -146,12 +148,12 @@ func (mh *Module) MountRoutes(r chi.Router, middlewares ...func(http.Handler) ht
|
||||
r.Get("/{moduleID}", mh.Read)
|
||||
r.Post("/{moduleID}", mh.Edit)
|
||||
r.Delete("/{moduleID}", mh.Delete)
|
||||
r.Get("/{moduleID}/report", mh.ContentReport)
|
||||
r.Get("/{moduleID}/content", mh.ContentList)
|
||||
r.Post("/{moduleID}/content", mh.ContentCreate)
|
||||
r.Get("/{moduleID}/content/{contentID}", mh.ContentRead)
|
||||
r.Post("/{moduleID}/content/{contentID}", mh.ContentEdit)
|
||||
r.Delete("/{moduleID}/content/{contentID}", mh.ContentDelete)
|
||||
r.Get("/{moduleID}/report", mh.RecordReport)
|
||||
r.Get("/{moduleID}/record", mh.RecordList)
|
||||
r.Post("/{moduleID}/record", mh.RecordCreate)
|
||||
r.Get("/{moduleID}/record/{recordID}", mh.RecordRead)
|
||||
r.Post("/{moduleID}/record/{recordID}", mh.RecordEdit)
|
||||
r.Delete("/{moduleID}/record/{recordID}", mh.RecordDelete)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func (s *Module) Edit(ctx context.Context, r *request.ModuleEdit) (interface{},
|
||||
return s.module.With(ctx).Update(item)
|
||||
}
|
||||
|
||||
func (s *Module) ContentReport(ctx context.Context, r *request.ModuleContentReport) (interface{}, error) {
|
||||
func (s *Module) RecordReport(ctx context.Context, r *request.ModuleRecordReport) (interface{}, error) {
|
||||
reportParams := &types.ContentReport{}
|
||||
|
||||
if strings.TrimSpace(r.Metrics) != "" {
|
||||
@@ -68,15 +68,15 @@ func (s *Module) ContentReport(ctx context.Context, r *request.ModuleContentRepo
|
||||
return s.content.With(ctx).Report(r.ModuleID, reportParams)
|
||||
}
|
||||
|
||||
func (s *Module) ContentList(ctx context.Context, r *request.ModuleContentList) (interface{}, error) {
|
||||
func (s *Module) RecordList(ctx context.Context, r *request.ModuleRecordList) (interface{}, error) {
|
||||
return s.content.With(ctx).Find(r.ModuleID, r.Query, r.Page, r.PerPage, r.Sort)
|
||||
}
|
||||
|
||||
func (s *Module) ContentRead(ctx context.Context, r *request.ModuleContentRead) (interface{}, error) {
|
||||
return s.content.With(ctx).FindByID(r.ContentID)
|
||||
func (s *Module) RecordRead(ctx context.Context, r *request.ModuleRecordRead) (interface{}, error) {
|
||||
return s.content.With(ctx).FindByID(r.RecordID)
|
||||
}
|
||||
|
||||
func (s *Module) ContentCreate(ctx context.Context, r *request.ModuleContentCreate) (interface{}, error) {
|
||||
func (s *Module) RecordCreate(ctx context.Context, r *request.ModuleRecordCreate) (interface{}, error) {
|
||||
item := &types.Content{
|
||||
ModuleID: r.ModuleID,
|
||||
Fields: r.Fields,
|
||||
@@ -84,15 +84,15 @@ func (s *Module) ContentCreate(ctx context.Context, r *request.ModuleContentCrea
|
||||
return s.content.With(ctx).Create(item)
|
||||
}
|
||||
|
||||
func (s *Module) ContentEdit(ctx context.Context, r *request.ModuleContentEdit) (interface{}, error) {
|
||||
func (s *Module) RecordEdit(ctx context.Context, r *request.ModuleRecordEdit) (interface{}, error) {
|
||||
item := &types.Content{
|
||||
ID: r.ContentID,
|
||||
ID: r.RecordID,
|
||||
ModuleID: r.ModuleID,
|
||||
Fields: r.Fields,
|
||||
}
|
||||
return s.content.With(ctx).Update(item)
|
||||
}
|
||||
|
||||
func (s *Module) ContentDelete(ctx context.Context, r *request.ModuleContentDelete) (interface{}, error) {
|
||||
return resputil.OK(), s.content.With(ctx).DeleteByID(r.ContentID)
|
||||
func (s *Module) RecordDelete(ctx context.Context, r *request.ModuleRecordDelete) (interface{}, error) {
|
||||
return resputil.OK(), s.content.With(ctx).DeleteByID(r.RecordID)
|
||||
}
|
||||
|
||||
@@ -260,18 +260,18 @@ func (m *ModuleDelete) Fill(r *http.Request) (err error) {
|
||||
|
||||
var _ RequestFiller = NewModuleDelete()
|
||||
|
||||
// Module content/report request parameters
|
||||
type ModuleContentReport struct {
|
||||
// Module record/report request parameters
|
||||
type ModuleRecordReport struct {
|
||||
Metrics string
|
||||
Dimensions string
|
||||
ModuleID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
func NewModuleContentReport() *ModuleContentReport {
|
||||
return &ModuleContentReport{}
|
||||
func NewModuleRecordReport() *ModuleRecordReport {
|
||||
return &ModuleRecordReport{}
|
||||
}
|
||||
|
||||
func (m *ModuleContentReport) Fill(r *http.Request) (err error) {
|
||||
func (m *ModuleRecordReport) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(m)
|
||||
|
||||
@@ -311,10 +311,10 @@ func (m *ModuleContentReport) Fill(r *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewModuleContentReport()
|
||||
var _ RequestFiller = NewModuleRecordReport()
|
||||
|
||||
// Module content/list request parameters
|
||||
type ModuleContentList struct {
|
||||
// Module record/list request parameters
|
||||
type ModuleRecordList struct {
|
||||
Query string
|
||||
Page int
|
||||
PerPage int
|
||||
@@ -322,11 +322,11 @@ type ModuleContentList struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
func NewModuleContentList() *ModuleContentList {
|
||||
return &ModuleContentList{}
|
||||
func NewModuleRecordList() *ModuleRecordList {
|
||||
return &ModuleRecordList{}
|
||||
}
|
||||
|
||||
func (m *ModuleContentList) Fill(r *http.Request) (err error) {
|
||||
func (m *ModuleRecordList) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(m)
|
||||
|
||||
@@ -374,19 +374,19 @@ func (m *ModuleContentList) Fill(r *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewModuleContentList()
|
||||
var _ RequestFiller = NewModuleRecordList()
|
||||
|
||||
// Module content/create request parameters
|
||||
type ModuleContentCreate struct {
|
||||
// Module record/create request parameters
|
||||
type ModuleRecordCreate struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
Fields sqlxTypes.JSONText
|
||||
}
|
||||
|
||||
func NewModuleContentCreate() *ModuleContentCreate {
|
||||
return &ModuleContentCreate{}
|
||||
func NewModuleRecordCreate() *ModuleRecordCreate {
|
||||
return &ModuleRecordCreate{}
|
||||
}
|
||||
|
||||
func (m *ModuleContentCreate) Fill(r *http.Request) (err error) {
|
||||
func (m *ModuleRecordCreate) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(m)
|
||||
|
||||
@@ -424,19 +424,19 @@ func (m *ModuleContentCreate) Fill(r *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewModuleContentCreate()
|
||||
var _ RequestFiller = NewModuleRecordCreate()
|
||||
|
||||
// Module content/read request parameters
|
||||
type ModuleContentRead struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
ContentID uint64 `json:",string"`
|
||||
// Module record/read request parameters
|
||||
type ModuleRecordRead struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
RecordID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
func NewModuleContentRead() *ModuleContentRead {
|
||||
return &ModuleContentRead{}
|
||||
func NewModuleRecordRead() *ModuleRecordRead {
|
||||
return &ModuleRecordRead{}
|
||||
}
|
||||
|
||||
func (m *ModuleContentRead) Fill(r *http.Request) (err error) {
|
||||
func (m *ModuleRecordRead) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(m)
|
||||
|
||||
@@ -464,25 +464,25 @@ func (m *ModuleContentRead) Fill(r *http.Request) (err error) {
|
||||
}
|
||||
|
||||
m.ModuleID = parseUInt64(chi.URLParam(r, "moduleID"))
|
||||
m.ContentID = parseUInt64(chi.URLParam(r, "contentID"))
|
||||
m.RecordID = parseUInt64(chi.URLParam(r, "recordID"))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewModuleContentRead()
|
||||
var _ RequestFiller = NewModuleRecordRead()
|
||||
|
||||
// Module content/edit request parameters
|
||||
type ModuleContentEdit struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
ContentID uint64 `json:",string"`
|
||||
Fields sqlxTypes.JSONText
|
||||
// Module record/edit request parameters
|
||||
type ModuleRecordEdit struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
RecordID uint64 `json:",string"`
|
||||
Fields sqlxTypes.JSONText
|
||||
}
|
||||
|
||||
func NewModuleContentEdit() *ModuleContentEdit {
|
||||
return &ModuleContentEdit{}
|
||||
func NewModuleRecordEdit() *ModuleRecordEdit {
|
||||
return &ModuleRecordEdit{}
|
||||
}
|
||||
|
||||
func (m *ModuleContentEdit) Fill(r *http.Request) (err error) {
|
||||
func (m *ModuleRecordEdit) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(m)
|
||||
|
||||
@@ -510,7 +510,7 @@ func (m *ModuleContentEdit) Fill(r *http.Request) (err error) {
|
||||
}
|
||||
|
||||
m.ModuleID = parseUInt64(chi.URLParam(r, "moduleID"))
|
||||
m.ContentID = parseUInt64(chi.URLParam(r, "contentID"))
|
||||
m.RecordID = parseUInt64(chi.URLParam(r, "recordID"))
|
||||
if val, ok := post["fields"]; ok {
|
||||
|
||||
if m.Fields, err = parseJSONTextWithErr(val); err != nil {
|
||||
@@ -521,19 +521,19 @@ func (m *ModuleContentEdit) Fill(r *http.Request) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewModuleContentEdit()
|
||||
var _ RequestFiller = NewModuleRecordEdit()
|
||||
|
||||
// Module content/delete request parameters
|
||||
type ModuleContentDelete struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
ContentID uint64 `json:",string"`
|
||||
// Module record/delete request parameters
|
||||
type ModuleRecordDelete struct {
|
||||
ModuleID uint64 `json:",string"`
|
||||
RecordID uint64 `json:",string"`
|
||||
}
|
||||
|
||||
func NewModuleContentDelete() *ModuleContentDelete {
|
||||
return &ModuleContentDelete{}
|
||||
func NewModuleRecordDelete() *ModuleRecordDelete {
|
||||
return &ModuleRecordDelete{}
|
||||
}
|
||||
|
||||
func (m *ModuleContentDelete) Fill(r *http.Request) (err error) {
|
||||
func (m *ModuleRecordDelete) Fill(r *http.Request) (err error) {
|
||||
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
|
||||
err = json.NewDecoder(r.Body).Decode(m)
|
||||
|
||||
@@ -561,9 +561,9 @@ func (m *ModuleContentDelete) Fill(r *http.Request) (err error) {
|
||||
}
|
||||
|
||||
m.ModuleID = parseUInt64(chi.URLParam(r, "moduleID"))
|
||||
m.ContentID = parseUInt64(chi.URLParam(r, "contentID"))
|
||||
m.RecordID = parseUInt64(chi.URLParam(r, "recordID"))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
var _ RequestFiller = NewModuleContentDelete()
|
||||
var _ RequestFiller = NewModuleRecordDelete()
|
||||
|
||||
@@ -314,13 +314,13 @@ CRM module definitions
|
||||
| dimensions | string | GET | Dimensions (syntax: alias:field|modifier|modifier2;...) | N/A | YES |
|
||||
| moduleID | uint64 | PATH | Module ID | N/A | YES |
|
||||
|
||||
## List/read contents from module section
|
||||
## List/read records from module section
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/module/{moduleID}/content` | HTTP/S | GET | |
|
||||
| `/module/{moduleID}/record` | HTTP/S | GET | |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
@@ -332,66 +332,66 @@ CRM module definitions
|
||||
| sort | string | GET | Sort field (default id desc) | N/A | NO |
|
||||
| moduleID | uint64 | PATH | Module ID | N/A | YES |
|
||||
|
||||
## List/read contents from module section
|
||||
## Create record in module section
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/module/{moduleID}/content` | HTTP/S | POST | |
|
||||
| `/module/{moduleID}/record` | HTTP/S | POST | |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| moduleID | uint64 | PATH | Module ID | N/A | YES |
|
||||
| fields | sqlxTypes.JSONText | POST | Content JSON | N/A | YES |
|
||||
| fields | sqlxTypes.JSONText | POST | Record JSON | N/A | YES |
|
||||
|
||||
## Read contents by ID from module section
|
||||
## Read records by ID from module section
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/module/{moduleID}/content/{contentID}` | HTTP/S | GET | |
|
||||
| `/module/{moduleID}/record/{recordID}` | HTTP/S | GET | |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| moduleID | uint64 | PATH | Module ID | N/A | YES |
|
||||
| contentID | uint64 | PATH | Content ID | N/A | YES |
|
||||
| recordID | uint64 | PATH | Record ID | N/A | YES |
|
||||
|
||||
## Add/update contents in module section
|
||||
## Add/update records in module section
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/module/{moduleID}/content/{contentID}` | HTTP/S | POST | |
|
||||
| `/module/{moduleID}/record/{recordID}` | HTTP/S | POST | |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| moduleID | uint64 | PATH | Module ID | N/A | YES |
|
||||
| contentID | uint64 | PATH | Content ID | N/A | YES |
|
||||
| fields | sqlxTypes.JSONText | POST | Content JSON | N/A | YES |
|
||||
| recordID | uint64 | PATH | Record ID | N/A | YES |
|
||||
| fields | sqlxTypes.JSONText | POST | Record JSON | N/A | YES |
|
||||
|
||||
## Delete content row from module section
|
||||
## Delete record row from module section
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `/module/{moduleID}/content/{contentID}` | HTTP/S | DELETE | |
|
||||
| `/module/{moduleID}/record/{recordID}` | HTTP/S | DELETE | |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
| moduleID | uint64 | PATH | Module ID | N/A | YES |
|
||||
| contentID | uint64 | PATH | Content ID | N/A | YES |
|
||||
| recordID | uint64 | PATH | Record ID | N/A | YES |
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user