Rename RecordFilter's Filter to Query for consistency

This commit is contained in:
Denis Arh
2020-04-30 07:30:25 +02:00
parent 7f1c3903c4
commit f291613516
11 changed files with 67 additions and 20 deletions
+7 -1
View File
@@ -734,11 +734,17 @@
"path": "/",
"parameters": {
"get": [
{
"name": "query",
"type": "string",
"required": false,
"title": "Record filtering query"
},
{
"name": "filter",
"type": "string",
"required": false,
"title": "Filtering condition"
"title": "Filtering condition (same as query, deprecated)"
},
{"type": "uint", "name": "limit", "title": "Limit"},
{"type": "uint", "name": "offset", "title": "Offset"},
+7 -1
View File
@@ -64,10 +64,16 @@
"Path": "/",
"Parameters": {
"get": [
{
"name": "query",
"required": false,
"title": "Record filtering query",
"type": "string"
},
{
"name": "filter",
"required": false,
"title": "Filtering condition",
"title": "Filtering condition (same as query, deprecated)",
"type": "string"
},
{
+2 -2
View File
@@ -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
+1 -1
View File
@@ -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"},
+18 -8
View File
@@ -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
+25
View File
@@ -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
+2 -2
View File
@@ -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)))
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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
+2 -1
View File
@@ -870,7 +870,8 @@ Compose records
| Parameter | Type | Method | Description | Default | Required? |
| --------- | ---- | ------ | ----------- | ------- | --------- |
| filter | string | GET | Filtering condition | N/A | NO |
| query | string | GET | Record filtering query | N/A | NO |
| filter | string | GET | Filtering condition (same as query, deprecated) | N/A | NO |
| limit | uint | GET | Limit | N/A | NO |
| offset | uint | GET | Offset | N/A | NO |
| page | uint | GET | Page number (1-based) | N/A | NO |
-1
View File
@@ -75,7 +75,6 @@ func New() *gomail.Message {
// Sends message with SMTP dialer
func Send(message *gomail.Message, dd ...Dialer) (err error) {
for _, d := range append(dd, defaultDialer) {
if d == nil {
continue