Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
FoseFx committed May 21, 2024
1 parent 510b103 commit 7a2565d
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ import (
"hwutil"
)

type PropertiesQueryRow interface {
GetRuleID() uuid.UUID
GetPropertyID() uuid.UUID
GetDontAlwaysInclude() bool
GetSpecificity() int32
}

type PropertyMatchers interface {
hwutil.MapAble
// FindExactRuleId queries (presumably the projection) for the one rule that has these matchers
// MUST return (nil, nil) if no such rule exists
FindExactRuleId(context.Context) (*uuid.UUID, error)

// QueryProperties queries (presumably the projection) for all properties relevant for the user using the rules
// MUST be ordered in descending order by specificity
QueryProperties(context.Context) ([]PropertiesQueryRow, error)
}

type PropertyViewRule struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@ func (m TaskPropertyMatchers) FindExactRuleId(ctx context.Context) (*uuid.UUID,
})
}

type queryPropertiesRow struct {
task_views_repo.GetTaskPropertiesUsingMatchersRow
}

func (r queryPropertiesRow) GetRuleID() uuid.UUID {
return r.RuleID
}

func (r queryPropertiesRow) GetPropertyID() uuid.UUID {
return r.PropertyID
}

func (r queryPropertiesRow) GetDontAlwaysInclude() bool {
return r.DontAlwaysInclude
}

func (r queryPropertiesRow) GetSpecificity() int32 {
return r.Specificity
}

func (m TaskPropertyMatchers) QueryProperties(ctx context.Context) ([]PropertiesQueryRow, error) {
taskViews := task_views_repo.New(hwdb.GetDB())

rows, err := taskViews.GetTaskPropertiesUsingMatchers(ctx, task_views_repo.GetTaskPropertiesUsingMatchersParams{
WardID: m.WardID,
TaskID: m.TaskID,
})

cast := func(row task_views_repo.GetTaskPropertiesUsingMatchersRow) PropertiesQueryRow {
return queryPropertiesRow{row}
}

return hwutil.Map(rows, cast), err
}

func (m TaskPropertyMatchers) ToMap() map[string]interface{} {
mp := make(map[string]interface{})
if m.WardID.Valid {
Expand Down
17 changes: 17 additions & 0 deletions services/property-svc/internal/property-view/queries/v1/views.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v1

Check failure on line 1 in services/property-svc/internal/property-view/queries/v1/views.go

View workflow job for this annotation

GitHub Actions / cicd-go (property-svc) / lint

: # property-svc/internal/property-view/queries/v1

import (
"context"
"property-svc/internal/property-view/models"
)

func GetPropertiesByMatcher(ctx context.Context, matcher models.PropertyMatchers) error {
rows, err := matcher.QueryProperties(ctx)
if err != nil {
return err
}

for _, row := range rows {

}
}
14 changes: 14 additions & 0 deletions services/property-svc/repos/task_views_repo.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,17 @@ SELECT
WHERE
(rules.ward_id = sqlc.narg('ward_id') OR (rules.ward_id IS NULL AND sqlc.narg('ward_id') IS NULL))
AND ((rules.task_id = sqlc.narg('task_id')) OR (rules.task_id IS NULL AND sqlc.narg('task_id') IS NULL));


-- name: GetTaskPropertiesUsingMatchers :many
SELECT
rules.rule_id,
list_items.property_id,
list_items.dont_always_include,
calc_rule_specificity(rules.task_id IS NOT NULL, rules.ward_id IS NOT NULL) as specificity
FROM task_property_view_rules as rules
JOIN property_view_filter_always_include_items as list_items ON list_items.rule_id = rules.rule_id
WHERE
(rules.ward_id = @ward_id OR rules.ward_id IS NULL)
AND (rules.task_id = @task_id OR rules.task_id IS NULL)
ORDER BY specificity DESC;
51 changes: 51 additions & 0 deletions services/property-svc/repos/task_views_repo/task_views_repo.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a2565d

Please sign in to comment.