Skip to content

Commit

Permalink
NOISSUE - Limit listing based on domain (#41)
Browse files Browse the repository at this point in the history
* add domain_id as a page metadata

Signed-off-by: ianmuchyri <ianmuchiri8@gmail.com>

* add missing created_by

Signed-off-by: ianmuchyri <ianmuchiri8@gmail.com>

---------

Signed-off-by: ianmuchyri <ianmuchiri8@gmail.com>
  • Loading branch information
ianmuchyri authored Jan 14, 2025
1 parent 17e59d2 commit 96158cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion re/postgres/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
INSERT INTO rules (id, name, domain_id, metadata, input_channel, input_topic, logic_type, logic_value,
output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, created_by, updated_at, updated_by, status)
VALUES (:id, :name, :domain_id, :metadata, :input_channel, :input_topic, :logic_type, :logic_value,
:output_channel, :output_topic, :recurring_time, :recurring_type, :recurring_period, :created_at, :updated_at, :updated_by, :status)
:output_channel, :output_topic, :recurring_time, :recurring_type, :recurring_period, :created_at, :created_by, :updated_at, :updated_by, :status)
RETURNING id, name, domain_id, metadata, input_channel, input_topic, logic_type, logic_value,
output_channel, output_topic, recurring_time, recurring_type, recurring_period, created_at, created_by, updated_at, updated_by, status;
`
Expand Down Expand Up @@ -229,6 +229,10 @@ func pageQuery(pm re.PageMeta) string {
query = append(query, "r.status = :status")
}

if pm.Domain != "" {
query = append(query, "r.domain_id = :domain_id")
}

var q string
if len(query) > 0 {
q = fmt.Sprintf("WHERE %s", strings.Join(query, " AND "))
Expand Down
2 changes: 2 additions & 0 deletions re/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type PageMeta struct {
InputChannel string `json:"input_channel,omitempty" db:"input_channel"`
OutputChannel string `json:"output_channel,omitempty" db:"output_channel"`
Status Status `json:"status,omitempty" db:"status"`
Domain string `json:"domain_id,omitempty" db:"domain_id"`
}

type Page struct {
Expand Down Expand Up @@ -135,6 +136,7 @@ func (re *re) UpdateRule(ctx context.Context, session authn.Session, r Rule) (Ru
}

func (re *re) ListRules(ctx context.Context, session authn.Session, pm PageMeta) (Page, error) {
pm.Domain = session.DomainID
return re.repo.ListRules(ctx, pm)
}

Expand Down

0 comments on commit 96158cd

Please sign in to comment.