Skip to content

Commit

Permalink
Port Device Groups to Ash
Browse files Browse the repository at this point in the history
Signed-off-by: Riccardo Binetti <[email protected]>
  • Loading branch information
rbino committed Apr 3, 2024
1 parent 1b4a1d0 commit 2542430
Show file tree
Hide file tree
Showing 16 changed files with 751 additions and 821 deletions.
1 change: 1 addition & 0 deletions backend/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ config :edgehog, Edgehog.PromEx,
config :edgehog, :ash_apis, [
Edgehog.Astarte,
Edgehog.Devices,
Edgehog.Groups,
Edgehog.Labeling,
Edgehog.Tenants
]
Expand Down
179 changes: 0 additions & 179 deletions backend/lib/edgehog/groups.ex

This file was deleted.

61 changes: 0 additions & 61 deletions backend/lib/edgehog/groups/device_group.ex

This file was deleted.

48 changes: 48 additions & 0 deletions backend/lib/edgehog/groups/device_group/calculations/filter.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# This file is part of Edgehog.
#
# Copyright 2024 SECO Mind Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

defmodule Edgehog.Groups.DeviceGroup.Calculations.Filter do
use Ash.Calculation

alias Edgehog.Selector

@impl true
def load(_query, _opts, _context) do
[:selector]
end

@impl true
def calculate(groups, _opts, _context) do
Enum.map(groups, fn group ->
case Selector.to_ash_expr(group.selector) do
{:ok, result} ->
result

# We validate this during creation, so we raise here if we fail
{:error, error} ->
raise """
Cannot parse selector: #{group.selector}
Error: #{inspect(error)}
"""
end
end)
end
end
Loading

0 comments on commit 2542430

Please sign in to comment.