After 'mix phx.gen.json Items Item items name:string description:string info:string amount:integer factor:float type:string --no-context --no-schema'.

This commit is contained in:
2026-04-21 13:56:18 +02:00
parent 851665ef60
commit 6076654aa4
6 changed files with 224 additions and 3 deletions

View File

@ -0,0 +1,29 @@
defmodule GenericRestServerWeb.ItemJSON do
alias GenericRestServer.Items.Item
@doc """
Renders a list of items.
"""
def index(%{items: items}) do
%{data: for(item <- items, do: data(item))}
end
@doc """
Renders a single item.
"""
def show(%{item: item}) do
%{data: data(item)}
end
defp data(%Item{} = item) do
%{
id: item.id,
name: item.name,
description: item.description,
info: item.info,
amount: item.amount,
factor: item.factor,
type: item.type
}
end
end