Skip to content

Commit

Permalink
add :hex to user schema for face wall sorting #222 #221 #219
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jan 19, 2025
1 parent b2bd894 commit 785ee20
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
22 changes: 18 additions & 4 deletions lib/app/repository.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,25 @@ defmodule App.Repository do

@doc false
def changeset(repository, attrs) do
attrs = %{attrs | topics: Enum.join(attrs.topics, ", ")}

repository
|> cast(attrs, [:id, :name, :full_name, :language, :owner_id, :description,
:fork, :forks_count, :watchers_count, :stargazers_count, :topics,
:open_issues_count, :created_at, :pushed_at])
|> cast(attrs, [
:created_at,
:id,
:description,
:fork,
:forks_count,
:full_name,
:language,
:name,
:open_issues_count,
:owner_id,
:pushed_at,
:stargazers_count,
:topics,
:watchers_count
])
|> validate_required([:name, :full_name])
end

Expand All @@ -47,7 +62,6 @@ defmodule App.Repository do
def get_org_repos(org) do
App.GitHub.org_repos(org)
|> Enum.map(fn repo ->
dbg(repo)
create(repo)
end)
end
Expand Down
6 changes: 4 additions & 2 deletions lib/app/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule App.User do
field :email, :string
field :followers, :integer
field :following, :integer
field :hex, :string
field :hireable, :boolean, default: false
field :location, :string
field :login, :string
Expand All @@ -27,7 +28,7 @@ defmodule App.User do
@doc false
def changeset(user, attrs) do
user
|> cast(attrs, [:id, :login, :avatar_url, :name, :company, :bio, :blog, :location, :email, :created_at, :hireable, :two_factor_authentication, :public_repos, :followers, :following])
|> cast(attrs, [:id, :login, :avatar_url, :name, :company, :bio, :blog, :location, :email, :created_at, :hex, :hireable, :two_factor_authentication, :public_repos, :followers, :following])
|> validate_required([:id, :login, :avatar_url])
end

Expand All @@ -54,6 +55,7 @@ defmodule App.User do
else
{:ok, user} =
map_github_user_fields_to_table(data)
|> Map.put(:hex, App.Img.get_avatar_color(data.avatar_url))
|> create()

user
Expand Down Expand Up @@ -108,7 +110,7 @@ defmodule App.User do
def list_users_avatars do
from(u in User, select: %{id: u.id})
# |> limit(20)
|> order_by(desc: :inserted_at)
|> order_by(:hex)
# |> distinct(true)
|> Repo.all()
# return a list of urls not a list of maps
Expand Down
1 change: 1 addition & 0 deletions priv/repo/migrations/20221005213110_create_users.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ defmodule App.Repo.Migrations.CreateUsers do
add :followers, :integer
add :following, :integer
add :hireable, :boolean, default: false
add :hex, :string
add :location, :string
add :login, :string
add :name, :string
Expand Down
4 changes: 1 addition & 3 deletions test/app/repository_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,14 @@ defmodule App.RepositoryTest do
open_issues_count: 98,
pushed_at: "2022-08-10T07:41:05Z",
stargazers_count: 1604,
topics: Enum.join(["beginner", "beginner-friendly", "how-to", "howto", "learn",
"starter-kit"], ","),
topics: ["beginner", "beginner-friendly", "how-to", "learn"],
watchers_count: 1604
}
assert {:ok, inserted_repo} = App.Repository.create(repo)
assert inserted_repo.name == repo.name
end

test "App.Repository.get_org_repos/1" do

App.Repository.get_org_repos("ideaq") # |> dbg
# assert inserted_repo.name == repo.name
end
Expand Down

0 comments on commit 785ee20

Please sign in to comment.