Skip to content

Commit d2fc579

Browse files
Update collectibles.ex
1 parent b22dc98 commit d2fc579

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

lib/cadet/accounts/collectibles.ex

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@ defmodule Cadet.Collectibles do
22
import Ecto.Query
33
alias Cadet.Accounts.User
44
alias Ecto.Multi
5-
5+
import Cadet.Repo
6+
import Ecto.Repo
7+
8+
# simply return the collectibles of the user, within a single map
69
def user_collectibles(user) do
7-
# simply return the collectibles of the user, within a single map
810
user.collectibles
911
end
1012

11-
'''
12-
@spec update_collectibles(
13-
string(),
14-
string(),
15-
%User{}
16-
) ::
17-
{:ok, nil}
18-
| {:error, {:unauthorized | :bad_request | :internal_server_error, String.t()}}
19-
'''
20-
21-
def update_grading_info(pic_nickname, pic_name, user) do
13+
def update_collectibles(pic_nickname, pic_name, user) do
14+
changeset =
15+
Ecto.Changeset.cast(user, %{collectibles: Map.put(user_collectibles(user), pic_nickname, pic_name)},[:collectibles])
16+
Cadet.Repo.update!(changeset)
17+
end
2218

19+
# should be idle since we are not going to delete students' collectibles
20+
# but provide the function delete_collectibles here for future extension
21+
def delete_all_collectibles(user) do
22+
changeset =
23+
Ecto.Changeset.cast(user, %{collectibles: %{}},[:collectibles])
24+
Cadet.Repo.update!(changeset)
2325
end
2426
end

0 commit comments

Comments
 (0)