Create player table, track player updates, fix match processing tracking

This commit is contained in:
2024-05-03 00:28:55 +02:00
parent f9271a5287
commit dafadcbddd
12 changed files with 128 additions and 22 deletions
@@ -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