Rename RecordFilter's Filter to Query for consistency
This commit is contained in:
@@ -173,7 +173,7 @@ func (r record) buildQuery(module *types.Module, f types.RecordFilter) (query sq
|
||||
}
|
||||
|
||||
// Parse filters.
|
||||
if f.Filter != "" {
|
||||
if f.Query != "" {
|
||||
var (
|
||||
// Filter parser
|
||||
fp = ql.NewParser()
|
||||
@@ -206,7 +206,7 @@ func (r record) buildQuery(module *types.Module, f types.RecordFilter) (query sq
|
||||
return i, nil
|
||||
}
|
||||
|
||||
if fn, err = fp.ParseExpression(f.Filter); err != nil {
|
||||
if fn, err = fp.ParseExpression(f.Query); err != nil {
|
||||
return
|
||||
} else if filterSql, filterArgs, err := fn.ToSql(); err != nil {
|
||||
return query, err
|
||||
|
||||
@@ -31,7 +31,7 @@ func TestRecordFinder(t *testing.T) {
|
||||
match: []string{"SELECT r.id, r.module_id, r.rel_namespace, r.owned_by, r.created_at, r.created_by, r.updated_at, r.updated_by, r.deleted_at, r.deleted_by FROM compose_record AS r WHERE r.deleted_at IS NULL AND r.module_id = ? AND r.rel_namespace = ?"},
|
||||
},
|
||||
{
|
||||
f: types.RecordFilter{Filter: "id = 5 AND foo = 7"},
|
||||
f: types.RecordFilter{Query: "id = 5 AND foo = 7"},
|
||||
match: []string{
|
||||
"r.id = 5",
|
||||
"rv_foo.value = 7"},
|
||||
|
||||
@@ -76,20 +76,30 @@ func (ctrl *Record) List(ctx context.Context, r *request.RecordList) (interface{
|
||||
var (
|
||||
m *types.Module
|
||||
err error
|
||||
|
||||
rf = types.RecordFilter{
|
||||
NamespaceID: r.NamespaceID,
|
||||
ModuleID: r.ModuleID,
|
||||
Sort: r.Sort,
|
||||
|
||||
PageFilter: rh.Paging(r),
|
||||
}
|
||||
)
|
||||
|
||||
if m, err = ctrl.module.With(ctx).FindByID(r.NamespaceID, r.ModuleID); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rr, filter, err := ctrl.record.With(ctx).Find(types.RecordFilter{
|
||||
NamespaceID: r.NamespaceID,
|
||||
ModuleID: r.ModuleID,
|
||||
Filter: r.Filter,
|
||||
Sort: r.Sort,
|
||||
if r.Query != "" {
|
||||
// Query param takes preference
|
||||
rf.Query = r.Query
|
||||
} else if r.Filter != "" {
|
||||
// Backward compatibility
|
||||
// Filter param is deprecated
|
||||
rf.Query = r.Filter
|
||||
}
|
||||
|
||||
PageFilter: rh.Paging(r),
|
||||
})
|
||||
rr, filter, err := ctrl.record.With(ctx).Find(rf)
|
||||
|
||||
return ctrl.makeFilterPayload(ctx, m, rr, filter, err)
|
||||
}
|
||||
@@ -329,7 +339,7 @@ func (ctrl *Record) Export(ctx context.Context, r *request.RecordExport) (interf
|
||||
f = types.RecordFilter{
|
||||
NamespaceID: r.NamespaceID,
|
||||
ModuleID: r.ModuleID,
|
||||
Filter: r.Filter,
|
||||
Query: r.Filter,
|
||||
}
|
||||
|
||||
contentType string
|
||||
|
||||
@@ -130,6 +130,10 @@ var _ RequestFiller = NewRecordReport()
|
||||
|
||||
// RecordList request parameters
|
||||
type RecordList struct {
|
||||
hasQuery bool
|
||||
rawQuery string
|
||||
Query string
|
||||
|
||||
hasFilter bool
|
||||
rawFilter string
|
||||
Filter string
|
||||
@@ -172,6 +176,7 @@ func NewRecordList() *RecordList {
|
||||
func (r RecordList) Auditable() map[string]interface{} {
|
||||
var out = map[string]interface{}{}
|
||||
|
||||
out["query"] = r.Query
|
||||
out["filter"] = r.Filter
|
||||
out["limit"] = r.Limit
|
||||
out["offset"] = r.Offset
|
||||
@@ -212,6 +217,11 @@ func (r *RecordList) Fill(req *http.Request) (err error) {
|
||||
post[name] = string(param[0])
|
||||
}
|
||||
|
||||
if val, ok := get["query"]; ok {
|
||||
r.hasQuery = true
|
||||
r.rawQuery = val
|
||||
r.Query = val
|
||||
}
|
||||
if val, ok := get["filter"]; ok {
|
||||
r.hasFilter = true
|
||||
r.rawFilter = val
|
||||
@@ -1408,6 +1418,21 @@ func (r *RecordReport) GetModuleID() uint64 {
|
||||
return r.ModuleID
|
||||
}
|
||||
|
||||
// HasQuery returns true if query was set
|
||||
func (r *RecordList) HasQuery() bool {
|
||||
return r.hasQuery
|
||||
}
|
||||
|
||||
// RawQuery returns raw value of query parameter
|
||||
func (r *RecordList) RawQuery() string {
|
||||
return r.rawQuery
|
||||
}
|
||||
|
||||
// GetQuery returns casted value of query parameter
|
||||
func (r *RecordList) GetQuery() string {
|
||||
return r.Query
|
||||
}
|
||||
|
||||
// HasFilter returns true if filter was set
|
||||
func (r *RecordList) HasFilter() bool {
|
||||
return r.hasFilter
|
||||
|
||||
@@ -823,8 +823,8 @@ func (svc record) Organize(namespaceID, moduleID, recordID uint64, posField, pos
|
||||
// the place we're moving our record to.
|
||||
// and sort the set with sorting field
|
||||
set, _, err = svc.recordRepo.Find(module, types.RecordFilter{
|
||||
Filter: fmt.Sprintf("%s(%s >= %d)", filter, posField, recordOrderPlace),
|
||||
Sort: posField,
|
||||
Query: fmt.Sprintf("%s(%s >= %d)", filter, posField, recordOrderPlace),
|
||||
Sort: posField,
|
||||
})
|
||||
|
||||
log.Info("reordering other records", zap.Int("count", len(set)))
|
||||
|
||||
@@ -169,8 +169,8 @@ func RegisterIteratorProviders() {
|
||||
"compose:record",
|
||||
func(ctx context.Context, f map[string]string, h eventbus.HandlerFn, action string) error {
|
||||
rf := types.RecordFilter{
|
||||
Filter: f["query"],
|
||||
Sort: f["sort"],
|
||||
Query: f["query"],
|
||||
Sort: f["sort"],
|
||||
}
|
||||
|
||||
rf.ParsePagination(f)
|
||||
|
||||
@@ -30,7 +30,7 @@ type (
|
||||
RecordFilter struct {
|
||||
ModuleID uint64 `json:"moduleID,string"`
|
||||
NamespaceID uint64 `json:"namespaceID,string"`
|
||||
Filter string `json:"query"`
|
||||
Query string `json:"query"`
|
||||
Sort string `json:"sort"`
|
||||
|
||||
// Standard paging fields & helpers
|
||||
|
||||
Reference in New Issue
Block a user