-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from inaka/cabol.109538988.users_model
Added users and repositories models.
- Loading branch information
Showing
6 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule CredoServer.Repo.Migrations.CreateUser do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:users) do | ||
add :name, :string | ||
add :username, :string | ||
add :github_token, :string | ||
add :email, :string | ||
add :email_code, :string | ||
add :auth_token, :string | ||
add :auth_expires, :datetime | ||
add :synced_at, :datetime | ||
|
||
timestamps | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule CredoServer.Repo.Migrations.CreateRepo do | ||
use Ecto.Migration | ||
|
||
def change do | ||
create table(:repositories) do | ||
add :user_id, references(:users) | ||
add :github_id, :integer | ||
add :name, :string | ||
add :full_name, :string | ||
add :html_url, :string | ||
add :private, :boolean, default: false | ||
add :status, :string | ||
|
||
timestamps | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule CredoServer.RepoTest do | ||
use CredoServer.ModelCase | ||
|
||
alias CredoServer.Repository | ||
|
||
@valid_attrs %{full_name: "some content", github_id: 42, html_url: "some content", name: "some content", private: true, status: "some content"} | ||
@invalid_attrs %{} | ||
|
||
test "changeset with valid attributes" do | ||
changeset = Repository.changeset(%Repository{}, @valid_attrs) | ||
assert changeset.valid? | ||
end | ||
|
||
test "changeset with invalid attributes" do | ||
changeset = Repository.changeset(%Repository{}, @invalid_attrs) | ||
refute changeset.valid? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule CredoServer.UserTest do | ||
use CredoServer.ModelCase | ||
|
||
alias CredoServer.User | ||
|
||
@valid_attrs %{auth_expires: "2010-04-17 14:00:00", auth_token: "some content", email: "some content", email_code: "some content", github_token: "some content", name: "some content", synced_at: "2010-04-17 14:00:00", username: "some content"} | ||
@invalid_attrs %{} | ||
|
||
test "changeset with valid attributes" do | ||
changeset = User.changeset(%User{}, @valid_attrs) | ||
assert changeset.valid? | ||
end | ||
|
||
test "changeset with invalid attributes" do | ||
changeset = User.changeset(%User{}, @invalid_attrs) | ||
refute changeset.valid? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule CredoServer.Repository do | ||
use CredoServer.Web, :model | ||
|
||
schema "repositories" do | ||
belongs_to :user_id, CredoServer.User | ||
field :github_id, :integer | ||
field :name, :string | ||
field :full_name, :string | ||
field :html_url, :string | ||
field :private, :boolean, default: false | ||
field :status, :string | ||
|
||
timestamps | ||
end | ||
|
||
@required_fields ~w(github_id name full_name html_url private status) | ||
@optional_fields ~w() | ||
|
||
@doc """ | ||
Creates a changeset based on the `model` and `params`. | ||
If no params are provided, an invalid changeset is returned | ||
with no validation performed. | ||
""" | ||
def changeset(model, params \\ :empty) do | ||
model | ||
|> cast(params, @required_fields, @optional_fields) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
defmodule CredoServer.User do | ||
use CredoServer.Web, :model | ||
|
||
schema "users" do | ||
field :name, :string | ||
field :username, :string | ||
field :github_token, :string | ||
field :email, :string | ||
field :email_code, :string | ||
field :auth_token, :string | ||
field :auth_expires, Ecto.DateTime | ||
field :synced_at, Ecto.DateTime | ||
|
||
timestamps | ||
end | ||
|
||
@required_fields ~w(name username github_token email email_code auth_token auth_expires synced_at) | ||
@optional_fields ~w() | ||
|
||
@doc """ | ||
Creates a changeset based on the `model` and `params`. | ||
If no params are provided, an invalid changeset is returned | ||
with no validation performed. | ||
""" | ||
def changeset(model, params \\ :empty) do | ||
model | ||
|> cast(params, @required_fields, @optional_fields) | ||
end | ||
end |