GameApp.Accounts.Player (game_app v0.1.0)
Provides the schema and changesets for player accounts within the GameApp
.
Summary
Types
Type representing the player struct with fields id, name, email, score, inserted_at, and updated_at.
Functions
Defines the Ecto schema for the players
table in the database.
Creates a changeset for a new player with validations for required fields, email format, and score.
Returns the default score value for a player.
Creates a changeset for updating an existing player with validations for score not decreasing.
Types
@type t() :: %GameApp.Accounts.Player{ __meta__: term(), email: String.t(), id: integer(), inserted_at: NaiveDateTime.t(), name: String.t(), score: integer(), updated_at: NaiveDateTime.t() }
Type representing the player struct with fields id, name, email, score, inserted_at, and updated_at.
Functions
Defines the Ecto schema for the players
table in the database.
Schema fields
:name
- The player's name (String).:email
- The player's email address (String).:score
- The player's game score (Integer), defaults to 0.timestamps
- Automatically managed fields for created_at and updated_at.
create_changeset(attrs)
@spec create_changeset(map()) :: Ecto.Changeset.t()
Creates a changeset for a new player with validations for required fields, email format, and score.
Parameters
attrs
: Map of attributes for the new player.
Returns
- A
Ecto.Changeset
struct ready for insertion.
default_score()
@spec default_score() :: integer()
Returns the default score value for a player.
Examples
iex> GameApp.Accounts.Player.default_score()
0
update_changeset(player, attrs \\ %{})
@spec update_changeset(t(), map()) :: Ecto.Changeset.t()
Creates a changeset for updating an existing player with validations for score not decreasing.
Parameters
player
: The existing player record.attrs
: (Optional) Map of attributes to update.
Returns
- A
Ecto.Changeset
struct ready for updating.