Skip to content

Commit

Permalink
feat: Private api endpoints for funder
Browse files Browse the repository at this point in the history
  • Loading branch information
martintomas committed Dec 31, 2024
1 parent 97e7660 commit e57da54
Show file tree
Hide file tree
Showing 17 changed files with 571 additions and 67 deletions.
9 changes: 9 additions & 0 deletions backend/app/controllers/api/v1/members/base_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module API
module V1
module Members
class BaseController < API::V1::BaseController
before_action :authenticate!
end
end
end
end
77 changes: 77 additions & 0 deletions backend/app/controllers/api/v1/members/funders_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module API
module V1
module Members
class FundersController < BaseController
skip_before_action :require_json!, only: %i[update]

load_and_authorize_resource

def show
render json: FunderSerializer.new(
current_member.funder,
include: included_relationships,
fields: sparse_fieldset,
params: {current_member: current_member, current_ability: current_ability}
).serializable_hash
end

def update
if current_member.funder.update(funder_params)
render json: FunderSerializer.new(
current_member.funder,
include: included_relationships,
fields: sparse_fieldset,
params: {current_member: current_member, current_ability: current_ability}
).serializable_hash
else
raise API::UnprocessableEntityError, current_member.funder.errors.full_messages.to_sentence
end
end

private

def funder_params
p = params.fetch(:funder_params, {}).permit(
:name,
:description,
:logo,
:primary_office_address,
:primary_office_city,
:primary_office_state_id,
:primary_office_country_id,
:primary_contact_first_name,
:primary_contact_last_name,
:primary_contact_email,
:show_primary_email,
:primary_contact_phone,
:primary_contact_location,
:primary_contact_role,
:secondary_email_which_can_be_shared,
:website,
:date_joined_fora,
:funder_type,
:funder_type_other,
:capital_acceptances_other,
:leadership_demographics_other,
:number_staff_employees,
:application_status,
:funder_legal_status,
:funder_legal_status_other,
:new_to_regenerative_ag,
:networks,
:capital_types_other,
:spend_down_strategy,
:areas_other,
:demographics_other,
capital_acceptances: [],
leadership_demographics: [],
capital_types: [],
areas: [],
demographics: []
)
p.merge published: true
end
end
end
end
end
8 changes: 4 additions & 4 deletions backend/app/controllers/api/v1/members_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module V1
class MembersController < BaseController
load_and_authorize_resource except: :sign_in

def me
def show
render json: API::V1::MemberSerializer.new(
current_member,
include: included_relationships,
Expand All @@ -13,15 +13,15 @@ def me
end

def update
if @member.update(member_params)
if current_member.update(member_params)
render json: API::V1::MemberSerializer.new(
@member,
current_member,
include: included_relationships,
fields: sparse_fieldset,
params: {current_member: current_member, current_ability: current_ability}
).serializable_hash
else
raise API::UnprocessableEntityError, @member.errors.full_messages.to_sentence
raise API::UnprocessableEntityError, current_member.errors.full_messages.to_sentence
end
end

Expand Down
3 changes: 2 additions & 1 deletion backend/app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def admin_rights
end

def member_rights
can %i[me update], Member, id: @member.id
can %i[show update], Member, id: @member.id
can %i[show update], Funder, id: @member.funder_id
end

def default_rights
Expand Down
1 change: 1 addition & 0 deletions backend/app/models/funder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Funder < ApplicationRecord
belongs_to :primary_office_state, class_name: "Subgeographic", optional: true
belongs_to :primary_office_country, class_name: "Subgeographic", optional: true

has_one :member, dependent: :restrict_with_exception
has_many :investments, dependent: :destroy
has_many :projects, -> { distinct }, through: :investments
has_many :funder_subgeographics, dependent: :destroy
Expand Down
7 changes: 5 additions & 2 deletions backend/config/routes/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
get :download
end
end
resources :members, only: %i[update] do
resource :member, only: %i[show update] do
collection do
get :me
post :sign_in
end
end
resource :reset_password, only: [:create, :update]

namespace :members do
resource :funder, only: %i[show update]
end
end
end
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"data": {
"id": "284482a5-7e3b-4c85-a339-306b5b635297",
"id": "f5f720f9-2896-4583-b63a-d61bb98e5e96",
"type": "member",
"attributes": {
"first_name": "Dawna"
},
"relationships": {
"funder": {
"data": {
"id": "42bafc40-e1d1-4547-b5f0-fc084c314e3b",
"id": "8ff19280-2af6-4a2c-be00-ba5fbea69263",
"type": "funder"
}
}
}
},
"included": [
{
"id": "42bafc40-e1d1-4547-b5f0-fc084c314e3b",
"id": "8ff19280-2af6-4a2c-be00-ba5fbea69263",
"type": "funder",
"attributes": {
"name": "Otha Kemmer",
Expand Down Expand Up @@ -58,21 +58,21 @@
"demographics_other": "Enim repellat pariatur est.",
"contact_email": "[email protected]",
"logo": {
"small": "http://localhost:4000/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWt4TVRrMFl6TmlaQzB6Wmpjd0xUUTRPREV0WWpJM1pDMWtNV00yTW1JME1qTmpaak1HT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--e07e810222ab916c357c81f15aaadfd91d37f4a3/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2QzNKbGMybDZaVWtpRERJd01IZ3lNREFHT3daVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--8673702c2d856505736727890dcac6a632977811/picture.jpg",
"medium": "http://localhost:4000/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWt4TVRrMFl6TmlaQzB6Wmpjd0xUUTRPREV0WWpJM1pDMWtNV00yTW1JME1qTmpaak1HT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--e07e810222ab916c357c81f15aaadfd91d37f4a3/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2QzNKbGMybDZaVWtpRERnd01IZzRNREFHT3daVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--e82a96c0eabd93d914de4ef37febd98c36e0e275/picture.jpg",
"original": "http://localhost:4000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWt4TVRrMFl6TmlaQzB6Wmpjd0xUUTRPREV0WWpJM1pDMWtNV00yTW1JME1qTmpaak1HT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--e07e810222ab916c357c81f15aaadfd91d37f4a3/picture.jpg"
"small": "http://localhost:4000/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWxrWTJNMVpUZzFOaTFtTm1NNExUUTROMlV0T1RrNU5TMWtaVEl4WkdKaE0ySTJPV0VHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--6ebae4c6f2260e3a7353702f52289ee02cc113ad/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2QzNKbGMybDZaVWtpRERJd01IZ3lNREFHT3daVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--8673702c2d856505736727890dcac6a632977811/picture.jpg",
"medium": "http://localhost:4000/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWxrWTJNMVpUZzFOaTFtTm1NNExUUTROMlV0T1RrNU5TMWtaVEl4WkdKaE0ySTJPV0VHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--6ebae4c6f2260e3a7353702f52289ee02cc113ad/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2QzNKbGMybDZaVWtpRERnd01IZzRNREFHT3daVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--e82a96c0eabd93d914de4ef37febd98c36e0e275/picture.jpg",
"original": "http://localhost:4000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWxrWTJNMVpUZzFOaTFtTm1NNExUUTROMlV0T1RrNU5TMWtaVEl4WkdKaE0ySTJPV0VHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--6ebae4c6f2260e3a7353702f52289ee02cc113ad/picture.jpg"
}
},
"relationships": {
"primary_office_state": {
"data": {
"id": "5e0a16f2-669d-4edd-802b-727294069bee",
"id": "8382f3a9-e384-4716-8675-a428592c41f8",
"type": "subgeographic"
}
},
"primary_office_country": {
"data": {
"id": "c9d602e6-c5c8-4488-b834-5acc1d5300f3",
"id": "7c156964-9f67-4333-8160-3b9728840bd5",
"type": "subgeographic"
}
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"data": {
"id": "2f2605b9-f43c-4c91-b09a-090aef968712",
"id": "c0843a5d-8672-4a7f-9692-f92dbc9fc5c6",
"type": "member",
"attributes": {
"first_name": "Dawna",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"data": {
"id": "242e574b-ea06-4a1d-b925-b77147214bd9",
"id": "40e66665-d429-44db-b1b7-e59bedd968fd",
"type": "member",
"attributes": {
"id": "242e574b-ea06-4a1d-b925-b77147214bd9",
"id": "40e66665-d429-44db-b1b7-e59bedd968fd",
"email": "[email protected]",
"first_name": "Dawna",
"last_name": "Block",
"created_at": "2024-12-31T11:21:25.233Z",
"updated_at": "2024-12-31T11:21:25.233Z"
"created_at": "2024-12-31T12:30:07.642Z",
"updated_at": "2024-12-31T12:30:07.642Z"
},
"relationships": {
"funder": {
"data": {
"id": "44a070ab-5bf7-476a-b552-e8868bb23c7a",
"id": "48b5de22-d450-4e58-985c-aba167f82920",
"type": "funder"
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"data": {
"id": "fa9efb5e-e30a-4e41-b877-9d8d6884e088",
"type": "funder",
"attributes": {
"name": "Otha Kemmer"
},
"relationships": {
"primary_office_country": {
"data": {
"id": "6f0bcd78-a484-451b-87a1-531cd7aed386",
"type": "subgeographic"
}
}
}
},
"included": [
{
"id": "6f0bcd78-a484-451b-87a1-531cd7aed386",
"type": "subgeographic",
"attributes": {
"name": "Papua New Guinea",
"code": "NPL",
"geographic": "countries",
"abbreviation": "C-NPL",
"created_at": "2024-12-31T11:53:23.489Z",
"updated_at": "2024-12-31T11:53:23.489Z"
},
"relationships": {
"parent": {
"data": null
},
"subgeographics": {
"data": [

]
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data": {
"id": "01448ed1-3dae-43d4-a6ed-625f69ab7f78",
"type": "funder",
"attributes": {
"name": "Otha Kemmer",
"description": "Enim repellat pariatur. Earum modi eos. Libero tempora exercitationem. Qui dolorem quo."
},
"relationships": {
}
}
}
80 changes: 80 additions & 0 deletions backend/spec/fixtures/snapshots/api/v1/members/get-funder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"data": {
"id": "a76e97ea-5a98-4d8f-adb5-d62b47d8a2a8",
"type": "funder",
"attributes": {
"name": "Otha Kemmer",
"description": "Enim repellat pariatur. Earum modi eos. Libero tempora exercitationem. Qui dolorem quo.",
"primary_office_city": "South Moises",
"website": "http://kutch-spencer.com/moises",
"date_joined_fora": "2021-11-27T00:00:00.000Z",
"funder_type": "funder_collaborative_or_network",
"funder_type_other": "Enim repellat pariatur est.",
"capital_acceptances": [
"other",
"investments_accepted"
],
"capital_acceptances_other": "Enim repellat pariatur est.",
"leadership_demographics": [
"hispanic_or_latinx",
"other"
],
"leadership_demographics_other": "Enim repellat pariatur est.",
"application_status": "invitation_only",
"funder_legal_status": "other",
"funder_legal_status_other": "Enim repellat pariatur est.",
"networks": "Enim repellat pariatur. Earum modi eos. Libero tempora exercitationem. Qui dolorem quo.",
"capital_types": [
"re_grants",
"pris"
],
"capital_types_other": "Enim repellat pariatur est.",
"spend_down_strategy": true,
"areas": [
"land_asset_financing",
"capacity_building"
],
"areas_other": "Enim repellat pariatur est.",
"demographics": [
"hispanic_or_latinx",
"other"
],
"demographics_other": "Enim repellat pariatur est.",
"contact_email": "[email protected]",
"logo": {
"small": "http://localhost:4000/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWt6WlRjd09EQmlaQzB3TW1SbExUUmhPRFV0WVRSaVlpMHlOV05tTlRZM09UTXpZaklHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--0a6421a4d48a2cb819c50eaabc7173b3b13eb6ed/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2QzNKbGMybDZaVWtpRERJd01IZ3lNREFHT3daVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--8673702c2d856505736727890dcac6a632977811/picture.jpg",
"medium": "http://localhost:4000/rails/active_storage/representations/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWt6WlRjd09EQmlaQzB3TW1SbExUUmhPRFV0WVRSaVlpMHlOV05tTlRZM09UTXpZaklHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--0a6421a4d48a2cb819c50eaabc7173b3b13eb6ed/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCem9MWm05eWJXRjBTU0lJYW5CbkJqb0dSVlE2QzNKbGMybDZaVWtpRERnd01IZzRNREFHT3daVSIsImV4cCI6bnVsbCwicHVyIjoidmFyaWF0aW9uIn19--e82a96c0eabd93d914de4ef37febd98c36e0e275/picture.jpg",
"original": "http://localhost:4000/rails/active_storage/blobs/redirect/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaEpJaWt6WlRjd09EQmlaQzB3TW1SbExUUmhPRFV0WVRSaVlpMHlOV05tTlRZM09UTXpZaklHT2daRlZBPT0iLCJleHAiOm51bGwsInB1ciI6ImJsb2JfaWQifX0=--0a6421a4d48a2cb819c50eaabc7173b3b13eb6ed/picture.jpg"
}
},
"relationships": {
"primary_office_state": {
"data": {
"id": "82ecb6e8-d4e1-4b38-b0a3-93218f43de66",
"type": "subgeographic"
}
},
"primary_office_country": {
"data": {
"id": "76a7f382-aab9-429b-a553-168b8f2aa83b",
"type": "subgeographic"
}
},
"subgeographics": {
"data": [

]
},
"subgeographic_ancestors": {
"data": [

]
},
"projects": {
"data": [

]
}
}
}
}
Loading

0 comments on commit e57da54

Please sign in to comment.