Skip to content

Commit

Permalink
Merge pull request #969 from Hibe7/castLongintegerValues
Browse files Browse the repository at this point in the history
AppEngine: handle type casting for `longinteger` inputs
  • Loading branch information
rbino authored Jul 9, 2024
2 parents af9afaa + 3d84f4e commit 738a0f1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- [astarte_trigger_engine] Always treat event TTL for trigger policies in seconds,
not milliseconds.
- [astarte_trigger_engine] ack messages even with unreachable target (see https://github.com/astarte-platform/astarte/issues/936)
- [astarte_appengine_api] Handle type casting for `longinteger` inputs

## [1.1.1] - 2023-11-15
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,34 @@ defmodule Astarte.AppEngine.API.Device do
end
end

defp cast_value(:longinteger, string_value) when is_binary(string_value) do
case Integer.parse(string_value) do
{int_value, ""} ->
{:ok, int_value}

_ ->
{:error, :unexpected_value_type, expected: :longinteger}
end
end

defp cast_value(:longinteger, int_value) when is_integer(int_value) do
{:ok, int_value}
end

defp cast_value(:longinteger, _value) do
{:error, :unexpected_value_type, expected: :longinteger}
end

defp cast_value(:longintegerarray, values) do
case map_while_ok(values, &cast_value(:longinteger, &1)) do
{:ok, mapped_values} ->
{:ok, mapped_values}

_ ->
{:error, :unexpected_value_type, expected: :longintegerarray}
end
end

defp cast_value(_anytype, anyvalue) do
{:ok, anyvalue}
end
Expand Down

0 comments on commit 738a0f1

Please sign in to comment.