Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Namespace serializers for consuming controller #538

Merged
merged 3 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions backend/app/controllers/api/v1/aws_ses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
class Api::V1::AwsSesController < ApplicationController
skip_authorize_resource only: [:mail_it, :notification]
skip_before_action :authenticate_user!, only: [:mail_it, :notification]
module Api
module V1
class AwsSesController < ApplicationController
skip_authorize_resource only: [:mail_it, :notification]
skip_before_action :authenticate_user!, only: [:mail_it, :notification]

def notification
message_type = request.headers["x-amz-sns-message-type"]
# sns_topic = request.headers['x-amz-sns-topic-arn']
raw_post = request.raw_post
def notification
message_type = request.headers["x-amz-sns-message-type"]
# sns_topic = request.headers['x-amz-sns-topic-arn']
raw_post = request.raw_post

if message_type.include? "Confirmation"
send_subscription_confirmation(raw_post)
elsif message_type.include? "Notification"
EmailRejectDispatcher.perform_async(raw_post)
end
if message_type.include? "Confirmation"
send_subscription_confirmation(raw_post)
elsif message_type.include? "Notification"
EmailRejectDispatcher.perform_async(raw_post)
end

render nothing: true, status: 200
end
render nothing: true, status: 200
end

def send_subscription_confirmation(raw_post)
json = JSON.parse(raw_post)
def send_subscription_confirmation(raw_post)
json = JSON.parse(raw_post)

open(json["SubscribeURL"])
open(json["SubscribeURL"])
end
end
end
end
10 changes: 7 additions & 3 deletions backend/app/controllers/api/v1/chart_lists_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class Api::V1::ChartListsController < ApplicationController
def show
render json: ChartListService.new(current_user: current_user).as_json
module Api
module V1
class ChartListsController < ApplicationController
def show
render json: ChartListService.new(current_user: current_user).as_json
end
end
end
end
46 changes: 25 additions & 21 deletions backend/app/controllers/api/v1/charts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
class Api::V1::ChartsController < ApplicationController
def show
chart = Chart.new(chart_params)
module Api
module V1
class ChartsController < ApplicationController
def show
chart = Chart.new(chart_params)

# FIXME
# rubocop:disable Style/SignalException
fail(ActiveRecord::RecordInvalid, chart) if chart.invalid?
# rubocop:enable Style/SignalException
# FIXME
# rubocop:disable Style/SignalException
fail(ActiveRecord::RecordInvalid, chart) if chart.invalid?
# rubocop:enable Style/SignalException

render json: chart
end
render json: chart
end

def chart_params
includes_params = {
tags: [],
foods: [],
symptoms: [],
conditions: [],
treatments: [],
weathersMeasures: [],
harveyBradshawIndices: []
}
def chart_params
includes_params = {
tags: [],
foods: [],
symptoms: [],
conditions: [],
treatments: [],
weathersMeasures: [],
harveyBradshawIndices: []
}

params.permit(:id, :start_at, :end_at, includes: includes_params).tap do |whitelist|
whitelist[:user] = current_user
params.permit(:id, :start_at, :end_at, includes: includes_params).tap do |whitelist|
whitelist[:user] = current_user
end
end
end
end
end
40 changes: 22 additions & 18 deletions backend/app/controllers/api/v1/charts_pattern_controller.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
class Api::V1::ChartsPatternController < ApplicationController
skip_before_action :authenticate_user!, only: [:index]
module Api
module V1
class ChartsPatternController < ApplicationController
skip_before_action :authenticate_user!, only: [:index]

def index
offset = charts_pattern_params[:offset].to_i
start_at = (charts_pattern_params[:start_at].to_date - offset.days).to_s
def index
offset = charts_pattern_params[:offset].to_i
start_at = (charts_pattern_params[:start_at].to_date - offset.days).to_s

end_date = charts_pattern_params[:end_at].to_date
end_at = (Time.current.to_date == end_date ? end_date : (end_date + offset.days)).to_s
end_date = charts_pattern_params[:end_at].to_date
end_at = (Time.current.to_date == end_date ? end_date : (end_date + offset.days)).to_s

@patterns = Pattern.where(id: {'$in': charts_pattern_params[:pattern_ids] || []})
@patterns = Pattern.where(id: {'$in': charts_pattern_params[:pattern_ids] || []})

@extended_patterns = @patterns.map do |pattern|
pattern.extend(PatternExtender).form_chart_data(start_at: start_at,
end_at: end_at,
pattern: pattern)
end
@extended_patterns = @patterns.map do |pattern|
pattern.extend(PatternExtender).form_chart_data(start_at: start_at,
end_at: end_at,
pattern: pattern)
end

render json: @extended_patterns, meta: {color_ids: Flaredown::Colorable::IDS}
end
render json: @extended_patterns, meta: {color_ids: Flaredown::Colorable::IDS}
end

private
private

def charts_pattern_params
params.permit(:start_at, :end_at, :offset, pattern_ids: [])
def charts_pattern_params
params.permit(:start_at, :end_at, :offset, pattern_ids: [])
end
end
end
end
50 changes: 27 additions & 23 deletions backend/app/controllers/api/v1/checkins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
class Api::V1::CheckinsController < ApplicationController
def index
date = params[:date]
module Api
module V1
class CheckinsController < ApplicationController
def index
date = params[:date]

if date.blank? && params.require(:page)
render json: current_user.checkins.where(:note.nin => [nil, ""]).order_by(date: :desc).page(params[:page]).per(10)
else
render json: current_user.checkins.where(date: Date.parse(date))
end
end
if date.blank? && params.require(:page)
render json: current_user.checkins.where(:note.nin => [nil, ""]).order_by(date: :desc).page(params[:page]).per(10)
else
render json: current_user.checkins.where(date: Date.parse(date))
end
end

def show
render json: Checkin.find(id)
end
def show
render json: Checkin.find(id)
end

def create
date = params.require(:checkin).require(:date)
checkin = Checkin::Creator.new(current_user.id, Date.parse(date)).create!
render json: checkin
end
def create
date = params.require(:checkin).require(:date)
checkin = Checkin::Creator.new(current_user.id, Date.parse(date)).create!
render json: checkin
end

def update
render json: Checkin::Updater.new(current_user, params).update!
end
def update
render json: Checkin::Updater.new(current_user, params).update!
end

private
private

def id
params.require(:id)
def id
params.require(:id)
end
end
end
end
64 changes: 34 additions & 30 deletions backend/app/controllers/api/v1/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
class Api::V1::CommentsController < ApplicationController
load_and_authorize_resource
skip_before_action :authenticate_user!, only: [:index]
module Api
module V1
class CommentsController < ApplicationController
load_and_authorize_resource
skip_before_action :authenticate_user!, only: [:index]

def index
render json: @comments.where(:id.in => params[:ids]).order_by(created_at: :asc)
end

def index
render json: @comments.where(:id.in => params[:ids]).order_by(created_at: :asc)
end
def show
render json: @comment
end

def show
render json: @comment
end
def create
@comment.encrypted_user_id = current_user.encrypted_id

if @comment.save
UpdatePostCountersJob.perform_async(parent_id: create_params[:post_id], parent_type: "Post")

def create
@comment.encrypted_user_id = current_user.encrypted_id
unless @comment.encrypted_user_id == @comment.post.encrypted_user_id
Notification.create(
kind: :comment,
notificateable: @comment,
encrypted_user_id: @comment.encrypted_user_id,
encrypted_notify_user_id: @comment.post.encrypted_user_id
)
end

if @comment.save
UpdatePostCountersJob.perform_async(parent_id: create_params[:post_id], parent_type: "Post")
DiscussionMention.perform_async(current_user.encrypted_id, @comment.id.to_s)

unless @comment.encrypted_user_id == @comment.post.encrypted_user_id
Notification.create(
kind: :comment,
notificateable: @comment,
encrypted_user_id: @comment.encrypted_user_id,
encrypted_notify_user_id: @comment.post.encrypted_user_id
)
render json: @comment, status: :created
else
render json: {errors: @comment.errors}, status: :unprocessable_entity
end
end

DiscussionMention.perform_async(current_user.encrypted_id, @comment.id.to_s)
private

render json: @comment, status: :created
else
render json: {errors: @comment.errors}, status: :unprocessable_entity
def create_params
params.require(:comment).permit(:body, :post_id)
end
end
end

private

def create_params
params.require(:comment).permit(:body, :post_id)
end
end
44 changes: 24 additions & 20 deletions backend/app/controllers/api/v1/conditions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
class Api::V1::ConditionsController < ApplicationController
load_and_authorize_resource
skip_before_action :authenticate_user!, only: [:show]
module Api
module V1
class ConditionsController < ApplicationController
load_and_authorize_resource
skip_before_action :authenticate_user!, only: [:show]

def index
@conditions = @conditions.includes(:translations)
@conditions = ids.present? ? @conditions.where(id: ids) : @conditions.order(:name).limit(50)
def index
@conditions = @conditions.includes(:translations)
@conditions = ids.present? ? @conditions.where(id: ids) : @conditions.order(:name).limit(50)

render json: @conditions
end
render json: @conditions
end

def show
render json: @condition
end
def show
render json: @condition
end

def create
render json: TrackableCreator.new(@condition, current_user).create!
end
def create
render json: TrackableCreator.new(@condition, current_user).create!
end

private
private

def create_params
params.require(:condition).permit(:name)
end
def create_params
params.require(:condition).permit(:name)
end

def ids
@ids ||= params[:ids] if params[:ids].is_a?(Array)
def ids
@ids ||= params[:ids] if params[:ids].is_a?(Array)
end
end
end
end
Loading