Skip to content

Commit 78a824c

Browse files
committed
Add GithubIssue controller and fix validation of body
1 parent 437d20b commit 78a824c

File tree

7 files changed

+214
-145
lines changed

7 files changed

+214
-145
lines changed

lib/code_corps/github/event/issue_comment.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ defmodule CodeCorps.GitHub.Event.IssueComment do
6666
end
6767

6868
@spec operational_multi(map) :: Multi.t
69-
defp operational_multi(%{"action" => action, "issue" => issue_payload, "comment" => comment_payload} = payload) when action in ~w(created edited) do
69+
defp operational_multi(%{"action" => action, "issue" => _, "comment" => _} = payload) when action in ~w(created edited) do
7070
Multi.new
7171
|> Multi.run(:repo, fn _ -> RepoFinder.find_repo(payload) end)
7272
|> Multi.run(:github_issue, fn %{repo: github_repo} -> github_repo |> link_issue(payload) end)

lib/code_corps/model/github_issue.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
defmodule CodeCorps.GithubIssue do
22
use Ecto.Schema
33
import Ecto.Changeset
4-
alias CodeCorps.GithubIssue
54

65
schema "github_issues" do
76
field :body, :string
@@ -28,7 +27,7 @@ defmodule CodeCorps.GithubIssue do
2827
def changeset(struct, params) do
2928
struct
3029
|> cast(params, [:body, :closed_at, :comments_url, :events_url, :github_created_at, :github_id, :github_updated_at, :html_url, :labels_url, :locked, :number, :state, :title, :url])
31-
|> validate_required([:body, :comments_url, :events_url, :github_created_at, :github_id, :github_updated_at, :html_url, :labels_url, :locked, :number, :state, :title, :url])
30+
|> validate_required([:comments_url, :events_url, :github_created_at, :github_id, :github_updated_at, :html_url, :labels_url, :locked, :number, :state, :title, :url])
3231
end
3332

3433
def create_changeset(struct, params) do
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
defmodule CodeCorpsWeb.GithubIssueController do
2+
use CodeCorpsWeb, :controller
3+
4+
alias CodeCorps.{GithubIssue, Helpers.Query}
5+
6+
action_fallback CodeCorpsWeb.FallbackController
7+
plug CodeCorpsWeb.Plug.DataToAttributes
8+
plug CodeCorpsWeb.Plug.IdsToIntegers
9+
10+
@spec index(Conn.t, map) :: Conn.t
11+
def index(%Conn{} = conn, %{} = params) do
12+
with github_repos <- GithubIssue |> Query.id_filter(params) |> Repo.all do
13+
conn |> render("index.json-api", data: github_repos)
14+
end
15+
end
16+
17+
@spec show(Conn.t, map) :: Conn.t
18+
def show(%Conn{} = conn, %{"id" => id}) do
19+
with %GithubIssue{} = github_repo <- GithubIssue |> Repo.get(id) do
20+
conn |> render("show.json-api", data: github_repo)
21+
end
22+
end
23+
end

lib/code_corps_web/router.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ defmodule CodeCorpsWeb.Router do
107107
resources "/comments", CommentController, only: [:index, :show]
108108
resources "/donation-goals", DonationGoalController, only: [:index, :show]
109109
resources "/github-app-installations", GithubAppInstallationController, only: [:index, :show]
110+
resources "/github-issues", GithubIssueController, only: [:index, :show]
110111
resources "/github-repos", GithubRepoController, only: [:index, :show]
111112
resources "/organization-github-app-installations", OrganizationGithubAppInstallationController, only: [:index, :show]
112113
resources "/organizations", OrganizationController, only: [:index, :show]

0 commit comments

Comments
 (0)