Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit aed1d57

Browse files
committed
feat: add more social info to users
1 parent 14ff5b5 commit aed1d57

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

lib/mastani_server/accounts/delegates/profile.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ defmodule MastaniServer.Accounts.Delegate.Profile do
115115
defp create_user(profile, :github) do
116116
attrs = %{
117117
nickname: profile["login"],
118+
github: "https://github.com/#{profile["login"]}",
118119
avatar: profile["avatar_url"],
119120
bio: profile["bio"],
120121
location: profile["location"],

lib/mastani_server/accounts/user.ex

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ defmodule MastaniServer.Accounts.User do
2121
alias MastaniServer.CMS
2222

2323
@required_fields ~w(nickname avatar)a
24-
@optional_fields ~w(nickname bio sex location email qq weichat weibo)a
24+
@optional_fields ~w(nickname bio sex location douban dribble email facebook github huaban qq weibo weichat twitter zhihu)a
2525

2626
@type t :: %User{}
2727
schema "users" do
@@ -33,14 +33,22 @@ defmodule MastaniServer.Accounts.User do
3333
field(:location, :string)
3434

3535
# TODO
36-
# field(:twitter, :string)
37-
# field(:facebook, :string)
3836
embeds_many(:education_backgrounds, EducationBackground)
3937
embeds_many(:work_backgrounds, WorkBackground)
4038

39+
# social info
40+
field(:github, :string)
41+
field(:twitter, :string)
42+
field(:facebook, :string)
43+
field(:zhihu, :string)
44+
field(:dribble, :string)
45+
field(:huaban, :string)
46+
field(:douban, :string)
47+
4148
field(:qq, :string)
4249
field(:weibo, :string)
4350
field(:weichat, :string)
51+
4452
field(:from_github, :boolean)
4553
has_one(:achievement, Achievement)
4654
has_one(:github_profile, GithubUser)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule MastaniServer.Repo.Migrations.AddMoreSocialInfoToUsers do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:users) do
6+
add(:github, :string)
7+
add(:twitter, :string)
8+
add(:facebook, :string)
9+
add(:zhihu, :string)
10+
add(:dribble, :string)
11+
add(:huaban, :string)
12+
add(:douban, :string)
13+
end
14+
end
15+
end

test/mastani_server/accounts/accounts_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ defmodule MastaniServer.Test.Accounts do
8989
describe "[github login]" do
9090
alias Accounts.{GithubUser, User}
9191

92+
@tag :wip
9293
test "register a valid github user with non-exist in db" do
9394
assert {:error, _} =
9495
ORM.find_by(GithubUser, github_id: to_string(@valid_github_profile["id"]))
@@ -104,6 +105,7 @@ defmodule MastaniServer.Test.Accounts do
104105
assert created_user.nickname == @valid_github_profile["login"]
105106
assert created_user.avatar == @valid_github_profile["avatar_url"]
106107
assert created_user.bio == @valid_github_profile["bio"]
108+
assert created_user.github == "https://github.com/#{@valid_github_profile["login"]}"
107109

108110
assert created_user.email == @valid_github_profile["email"]
109111

test/support/factory.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ defmodule MastaniServer.Factory do
187187

188188
%{
189189
id: "#{Faker.Name.first_name()} #{unique_num}",
190-
login: "#{Faker.Name.first_name()} #{unique_num}",
190+
login: "#{Faker.Name.first_name()}#{unique_num}",
191191
github_id: "#{unique_num + 1000}",
192192
node_id: "#{unique_num + 2000}",
193193
access_token: "#{unique_num + 3000}",

0 commit comments

Comments
 (0)