-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
TAN-2224 Co-sponsors
- Loading branch information
Showing
127 changed files
with
1,129 additions
and
154 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
35 changes: 35 additions & 0 deletions
35
back/app/controllers/web_api/v1/cosponsorships_controller.rb
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,35 @@ | ||
# frozen_string_literal: true | ||
|
||
class WebApi::V1::CosponsorshipsController < ApplicationController | ||
before_action :set_cosponsorship, except: %i[index] | ||
skip_before_action :authenticate_user, only: %i[index] | ||
|
||
def index | ||
cosponsorships = policy_scope(Cosponsorship) | ||
|
||
# Filter by idea id param | ||
if params[:idea_id] | ||
cosponsorships = cosponsorships.where(idea_id: params[:idea_id]) | ||
end | ||
|
||
paginated_cosponsorships = paginate cosponsorships | ||
render json: linked_json(paginated_cosponsorships, WebApi::V1::CosponsorshipSerializer, params: jsonapi_serializer_params) | ||
end | ||
|
||
def accept | ||
if @cosponsorship.status == 'pending' | ||
@cosponsorship.update(status: 'accepted') | ||
# SideFxAcceptedCosponsorshipService.new.after_accept(@cosponsorship, current_user) | ||
render json: WebApi::V1::CosponsorshipSerializer.new(@cosponsorship, params: jsonapi_serializer_params).serializable_hash | ||
else | ||
render json: { errors: @cosponsorship.errors.details }, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_cosponsorship | ||
@cosponsorship = Cosponsorship.find(params[:id]) | ||
authorize @cosponsorship | ||
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
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,34 @@ | ||
# frozen_string_literal: true | ||
|
||
# == Schema Information | ||
# | ||
# Table name: cosponsorships | ||
# | ||
# id :uuid not null, primary key | ||
# status :string default("pending"), not null | ||
# user_id :uuid not null | ||
# idea_id :uuid not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_cosponsorships_on_idea_id (idea_id) | ||
# index_cosponsorships_on_user_id (user_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (idea_id => ideas.id) | ||
# fk_rails_... (user_id => users.id) | ||
# | ||
class Cosponsorship < ApplicationRecord | ||
STATUSES = %w[pending accepted].freeze | ||
|
||
belongs_to :user | ||
belongs_to :idea | ||
|
||
has_many :notifications, dependent: :nullify | ||
|
||
validates :user, :idea, presence: true | ||
validates :status, inclusion: { in: STATUSES } | ||
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
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
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
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,20 @@ | ||
# frozen_string_literal: true | ||
|
||
class CosponsorshipPolicy < ApplicationPolicy | ||
class Scope | ||
attr_reader :user, :scope | ||
|
||
def initialize(user, scope) | ||
@user = user | ||
@scope = scope | ||
end | ||
|
||
def resolve | ||
scope.where(idea_id: Pundit.policy_scope(user, Idea)) | ||
end | ||
end | ||
|
||
def accept? | ||
user.id == record.user_id | ||
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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
class WebApi::V1::CosponsorshipSerializer < WebApi::V1::BaseSerializer | ||
attributes :status | ||
|
||
belongs_to :idea | ||
belongs_to :user | ||
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
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
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
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
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
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
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
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
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
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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateCosponsorships < ActiveRecord::Migration[7.0] | ||
def change | ||
create_table :cosponsorships, id: :uuid do |t| | ||
t.string :status, default: 'pending', null: false | ||
t.references :user, foreign_key: true, type: :uuid, index: true, null: false | ||
t.references :idea, foreign_key: true, type: :uuid, index: true, null: false | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Oops, something went wrong.