forked from shibao/cannery
		
	typespec out models
This commit is contained in:
		| @@ -8,7 +8,9 @@ defmodule Cannery.Ammo.AmmoGroup do | ||||
|  | ||||
|   use Ecto.Schema | ||||
|   import Ecto.Changeset | ||||
|   alias Cannery.{Accounts, Ammo, Containers, Tags} | ||||
|   alias Cannery.Ammo.{AmmoGroup, AmmoType} | ||||
|   alias Cannery.{Accounts.User, Containers.Container, Tags.Tag} | ||||
|   alias Ecto.{Changeset, UUID} | ||||
|  | ||||
|   @primary_key {:id, :binary_id, autogenerate: true} | ||||
|   @foreign_key_type :binary_id | ||||
| @@ -17,15 +19,35 @@ defmodule Cannery.Ammo.AmmoGroup do | ||||
|     field :notes, :string | ||||
|     field :price_paid, :float | ||||
|  | ||||
|     belongs_to :tag, Tags.Tag | ||||
|     belongs_to :ammo_type, Ammo.AmmoType | ||||
|     belongs_to :container, Containers.Container | ||||
|     belongs_to :user, Accounts.User | ||||
|     belongs_to :tag, Tag | ||||
|     belongs_to :ammo_type, AmmoType | ||||
|     belongs_to :container, Container | ||||
|     belongs_to :user, User | ||||
|  | ||||
|     timestamps() | ||||
|   end | ||||
|  | ||||
|   @type t :: %AmmoGroup{ | ||||
|           id: id(), | ||||
|           count: integer, | ||||
|           notes: String.t(), | ||||
|           price_paid: float(), | ||||
|           tag: Tag.t(), | ||||
|           tag_id: Tag.id(), | ||||
|           ammo_type: AmmoType.t(), | ||||
|           ammo_type_id: AmmoType.id(), | ||||
|           container: Container.t(), | ||||
|           container_id: Container.id(), | ||||
|           user: User.t(), | ||||
|           user_id: User.id(), | ||||
|           inserted_at: NaiveDateTime.t(), | ||||
|           updated_at: NaiveDateTime.t() | ||||
|         } | ||||
|   @type new_ammo_group :: %AmmoGroup{} | ||||
|   @type id :: UUID.t() | ||||
|  | ||||
|   @doc false | ||||
|   @spec changeset(t() | new_ammo_group(), attrs :: map()) :: Changeset.t() | ||||
|   def changeset(ammo_group, attrs) do | ||||
|     ammo_group | ||||
|     |> cast(attrs, [:count, :price_paid, :notes, :tag_id, :ammo_type_id, :container_id, :user_id]) | ||||
|   | ||||
| @@ -7,6 +7,8 @@ defmodule Cannery.Ammo.AmmoType do | ||||
|  | ||||
|   use Ecto.Schema | ||||
|   import Ecto.Changeset | ||||
|   alias Cannery.Ammo.AmmoType | ||||
|   alias Ecto.{Changeset, UUID} | ||||
|  | ||||
|   @primary_key {:id, :binary_id, autogenerate: true} | ||||
|   @foreign_key_type :binary_id | ||||
| @@ -21,7 +23,22 @@ defmodule Cannery.Ammo.AmmoType do | ||||
|     timestamps() | ||||
|   end | ||||
|  | ||||
|   @type t :: %AmmoType{ | ||||
|           id: id(), | ||||
|           bullet_type: String.t(), | ||||
|           case_material: String.t(), | ||||
|           desc: String.t(), | ||||
|           manufacturer: String.t(), | ||||
|           name: String.t(), | ||||
|           weight: float(), | ||||
|           inserted_at: NaiveDateTime.t(), | ||||
|           updated_at: NaiveDateTime.t() | ||||
|         } | ||||
|   @type new_ammo_type :: %AmmoType{} | ||||
|   @type id :: UUID.t() | ||||
|  | ||||
|   @doc false | ||||
|   @spec changeset(t() | new_ammo_type(), attrs :: map()) :: Changeset.t() | ||||
|   def changeset(ammo_type, attrs) do | ||||
|     ammo_type | ||||
|     |> cast(attrs, [:name, :desc, :case_material, :bullet_type, :weight, :manufacturer]) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user