-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from mattrent/improvements
Improvements
- Loading branch information
Showing
28 changed files
with
735 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2024 Giuseppe De Palma, Matteo Trentin | ||
# | ||
# 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. | ||
|
||
defmodule Core.FunctionsMetadata do | ||
@moduledoc """ | ||
The FunctionsMetadata context. | ||
""" | ||
|
||
import Ecto.Query, warn: false | ||
alias Core.Repo | ||
|
||
alias Core.Schemas.FunctionMetadata | ||
|
||
@doc """ | ||
Creates a function_metadata. | ||
## Examples | ||
iex> create_function_metadata(%{field: value}) | ||
{:ok, %FunctionMetadata{}} | ||
iex> create_function_metadata(%{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def create_function_metadata(attrs \\ %{}) do | ||
%FunctionMetadata{} | ||
|> FunctionMetadata.changeset(attrs) | ||
|> Repo.insert() | ||
end | ||
|
||
@doc """ | ||
Updates a function_metadata. | ||
## Examples | ||
iex> update_function_metadata(function_metadata, %{field: new_value}) | ||
{:ok, %FunctionMetadata{}} | ||
iex> update_function_metadata(function_metadata, %{field: bad_value}) | ||
{:error, %Ecto.Changeset{}} | ||
""" | ||
def update_function_metadata(%FunctionMetadata{} = function_metadata, attrs) do | ||
function_metadata | ||
|> FunctionMetadata.changeset(attrs) | ||
|> Repo.update() | ||
end | ||
|
||
@doc """ | ||
Gets function metadata from a function's ID. | ||
Returns `{:ok, %FunctionMetadata}` if the metadata is found, | ||
`{:error, :not_found}` otherwise. | ||
""" | ||
def get_function_metadata_by_function_id(function_id) do | ||
case Repo.get_by(FunctionMetadata, function_id: function_id) do | ||
nil -> {:error, :not_found} | ||
m -> {:ok, m} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2024 Giuseppe De Palma, Matteo Trentin | ||
# | ||
# 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. | ||
|
||
defmodule Core.Schemas.FunctionMetadata do | ||
@moduledoc """ | ||
The FunctionMetadata schema. | ||
""" | ||
use Ecto.Schema | ||
import Ecto.Changeset | ||
|
||
schema "function_metadata" do | ||
field(:capacity, :integer) | ||
field(:tag, :string) | ||
|
||
timestamps() | ||
belongs_to(:function, Core.Schemas.Function, foreign_key: :function_id) | ||
end | ||
|
||
@doc false | ||
def changeset(function_metadata, attrs) do | ||
function_metadata | ||
|> cast(attrs, [:tag, :capacity, :function_id]) | ||
|> validate_required([:function_id]) | ||
|> unique_constraint(:function_id) | ||
|> foreign_key_constraint(:function_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.