Skip to content

Commit

Permalink
🚑 Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNotAVirus committed Aug 29, 2024
1 parent 373b745 commit 98a7798
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ defmodule ChannelService.LobbyActions do

require Logger

alias ElvenDatabase.Players.Characters
alias ElvenGard.Network.Socket
alias ElvenDatabase.Players.{Account, Characters}
alias ElvenPackets.Views.LobbyViews

## Public API
Expand All @@ -26,19 +26,18 @@ defmodule ChannelService.LobbyActions do
@spec select_character(String.t(), map, Socket.t()) :: {:cont, Socket.t()}
def select_character("select", %{slot: slot}, socket) do
account = socket.assigns.account
%Account{id: account_id} = account

new_socket =
case Characters.get_by_account_and_slot(account_id, slot) do
nil ->
Logger.warning("Invalid character slot", socket_id: socket.id)
socket

character ->
case Characters.get_by_account_and_slot(account, slot) do
{:ok, character} ->
Socket.send(socket, LobbyViews.render(:ok))

# Temporary store the character (deleted when you enter in game)
Socket.assign(socket, character_id: character.id, character: character)

{:error, :not_found} ->
Logger.warning("Invalid character slot", socket_id: socket.id)
socket
end

{:cont, new_socket}
Expand Down
12 changes: 0 additions & 12 deletions apps/elven_database/lib/elven_database/players/character.ex
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,6 @@ defmodule ElvenDatabase.Players.Character do
changeset(character, attrs, List.delete(@required_fields, :account_id))
end

# FIXME: Refacto soft deletion
@spec disabled_changeset(t(), map()) :: Ecto.Changeset.t()
def disabled_changeset(%Character{} = character, attrs) do
character
|> cast(attrs, @fields)
|> validate_required(@required_fields)
|> validate_length(:name, min: 4, max: 32)
|> assoc_constraint(:account)
|> unique_constraint(:name)
|> unique_constraint(:slot, name: :account_slot)
end

## Private functions

defp changeset(character, attrs, required_fields) do
Expand Down

0 comments on commit 98a7798

Please sign in to comment.