|
| 1 | +defmodule AlgoraWeb.API.BountyJSON do |
| 2 | + alias Algora.Bounties.Bounty |
| 3 | + |
| 4 | + def index(%{bounties: bounties}) do |
| 5 | + [ |
| 6 | + %{ |
| 7 | + result: %{ |
| 8 | + data: %{ |
| 9 | + json: %{ |
| 10 | + next_cursor: nil, |
| 11 | + items: for(bounty <- bounties, do: data(bounty)) |
| 12 | + } |
| 13 | + } |
| 14 | + } |
| 15 | + } |
| 16 | + ] |
| 17 | + end |
| 18 | + |
| 19 | + defp data(%{} = bounty) do |
| 20 | + %{ |
| 21 | + id: bounty.id, |
| 22 | + point_reward: nil, |
| 23 | + reward: %{ |
| 24 | + amount: Algora.MoneyUtils.to_minor_units(bounty.amount), |
| 25 | + currency: bounty.amount.currency |
| 26 | + }, |
| 27 | + reward_formatted: Money.to_string!(bounty.amount, no_fraction_if_integer: true), |
| 28 | + reward_tiers: [], |
| 29 | + tech: bounty.owner.tech_stack, |
| 30 | + status: bounty.status, |
| 31 | + is_external: false, |
| 32 | + org: org_data(bounty.owner), |
| 33 | + task: task_data(bounty), |
| 34 | + type: "standard", |
| 35 | + kind: "dev", |
| 36 | + reward_type: "cash", |
| 37 | + visibility: "public", |
| 38 | + bids: [], |
| 39 | + autopay_disabled: false, |
| 40 | + timeouts_disabled: false, |
| 41 | + manual_assignments: false, |
| 42 | + created_at: bounty.inserted_at, |
| 43 | + updated_at: bounty.inserted_at |
| 44 | + } |
| 45 | + end |
| 46 | + |
| 47 | + defp task_data(bounty) do |
| 48 | + %{ |
| 49 | + id: bounty.ticket.id, |
| 50 | + forge: "github", |
| 51 | + repo_owner: bounty.repository.owner.provider_login, |
| 52 | + repo_name: bounty.repository.name, |
| 53 | + number: bounty.ticket.number, |
| 54 | + source: %{ |
| 55 | + type: "github", |
| 56 | + data: %{ |
| 57 | + id: bounty.ticket.id, |
| 58 | + html_url: bounty.ticket.url, |
| 59 | + title: bounty.ticket.title, |
| 60 | + body: "", |
| 61 | + user: %{ |
| 62 | + id: 0, |
| 63 | + login: "", |
| 64 | + avatar_url: "", |
| 65 | + html_url: "", |
| 66 | + name: "", |
| 67 | + company: "", |
| 68 | + location: "", |
| 69 | + twitter_username: "" |
| 70 | + } |
| 71 | + } |
| 72 | + }, |
| 73 | + status: "open", |
| 74 | + title: bounty.ticket.title, |
| 75 | + url: bounty.ticket.url, |
| 76 | + body: "", |
| 77 | + type: "issue", |
| 78 | + hash: Bounty.path(bounty), |
| 79 | + tech: [] |
| 80 | + } |
| 81 | + end |
| 82 | + |
| 83 | + defp org_data(nil), do: nil |
| 84 | + |
| 85 | + defp org_data(org) do |
| 86 | + %{ |
| 87 | + id: org.id, |
| 88 | + created_at: org.inserted_at, |
| 89 | + handle: org.handle, |
| 90 | + name: org.name, |
| 91 | + display_name: org.name, |
| 92 | + description: "", |
| 93 | + avatar_url: org.avatar_url, |
| 94 | + website_url: "", |
| 95 | + twitter_url: "", |
| 96 | + youtube_url: "", |
| 97 | + discord_url: "", |
| 98 | + slack_url: "", |
| 99 | + stargazers_count: 0, |
| 100 | + tech: org.tech_stack, |
| 101 | + accepts_sponsorships: false, |
| 102 | + members: members_data(org), |
| 103 | + enabled_expert_recs: false, |
| 104 | + enabled_private_bounties: false, |
| 105 | + days_until_timeout: nil, |
| 106 | + github_handle: org.provider_login |
| 107 | + } |
| 108 | + end |
| 109 | + |
| 110 | + defp members_data(_org) do |
| 111 | + [] |
| 112 | + end |
| 113 | +end |
0 commit comments