Create player table, track player updates, fix match processing tracking
This commit is contained in:
+5
@@ -3,6 +3,11 @@ defmodule LolAnalytics.Match.MatchRepo do
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
def list_matches do
|
||||
query = from m in MatchSchema, order_by: [desc: m.match_id]
|
||||
LoLAnalytics.Repo.all(query)
|
||||
end
|
||||
|
||||
@spec get_match(String.t()) :: %LolAnalytics.Match.MatchSchema{}
|
||||
def get_match(match_id) do
|
||||
query = from m in MatchSchema, where: m.match_id == ^match_id
|
||||
@@ -0,0 +1,27 @@
|
||||
defmodule LolAnalytics.Player.PlayerRepo do
|
||||
alias LolAnalytics.Player.PlayerSchema
|
||||
|
||||
import Ecto.Query
|
||||
|
||||
def list_players do
|
||||
query = from(p in PlayerSchema)
|
||||
LoLAnalytics.Repo.all(query)
|
||||
end
|
||||
|
||||
def get_player(puuid) do
|
||||
query = from p in PlayerSchema, where: p.puuid == ^puuid
|
||||
LoLAnalytics.Repo.one(query)
|
||||
end
|
||||
|
||||
def insert_player(puuid) do
|
||||
%PlayerSchema{}
|
||||
|> PlayerSchema.changeset(%{puuid: puuid, region: "EUW"})
|
||||
|> LoLAnalytics.Repo.insert()
|
||||
end
|
||||
|
||||
def update_player(player, attrs) do
|
||||
player
|
||||
|> PlayerSchema.changeset(attrs)
|
||||
|> LoLAnalytics.Repo.update()
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
defmodule LolAnalytics.Player.PlayerSchema do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "player" do
|
||||
field :puuid, :string
|
||||
field :region, :string
|
||||
|
||||
field :last_processed_at, :utc_datetime,
|
||||
default: DateTime.utc_now() |> DateTime.truncate(:second)
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
||||
@spec changeset(%__MODULE__{}) ::
|
||||
Ecto.Changeset.t()
|
||||
def changeset(player = %__MODULE__{}, params \\ %{}) do
|
||||
player
|
||||
|> cast(params, [:puuid, :region, :last_processed_at])
|
||||
|> validate_required([:puuid, :region, :last_processed_at])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
defmodule LoLAnalytics.Repo.Migrations.Player do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table("player") do
|
||||
add :puuid, :string
|
||||
add :region, :string
|
||||
add :last_processed_at, :utc_datetime
|
||||
timestamps()
|
||||
end
|
||||
|
||||
create index(:player, [:puuid])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user