Skip to content

Commit

Permalink
rename model Feedback to User::Feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
kortirso committed Oct 21, 2024
1 parent 8b6594d commit 052461c
Show file tree
Hide file tree
Showing 16 changed files with 50 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

class AddFeedbackCommand < BaseCommand
class AddUserFeedbackCommand < BaseCommand
use_contract do
params do
required(:user).filled(type?: User)
Expand All @@ -17,7 +17,7 @@ def do_prepare(input)
end

def do_persist(input)
feedback = Feedback.create!(input)
feedback = User::Feedback.create!(input)

AdminDelivery.with(id: feedback.id).feedback_created.deliver_later

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/feedbacks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def index; end
private

def find_feedbacks
@pagy, @feedbacks = pagy(Feedback.order(id: :desc), limit: PER_PAGE)
@pagy, @feedbacks = pagy(User::Feedback.order(id: :desc), limit: PER_PAGE)
end
end
end
21 changes: 0 additions & 21 deletions app/controllers/frontend/feedbacks_controller.rb

This file was deleted.

22 changes: 22 additions & 0 deletions app/controllers/frontend/users/feedbacks_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Frontend
module Users
class FeedbacksController < Frontend::BaseController
include Deps[add_user_feedback: 'commands.add_user_feedback']

def create
case add_user_feedback.call(user_feedback_params.merge(user: current_user))
in { errors: errors } then render json: { errors: errors }, status: :ok
else render json: { status: 'ok' }, status: :created
end
end

private

def user_feedback_params
params.require(:feedback).permit(:title, :description, :email, :answerable).to_h
end
end
end
end
1 change: 0 additions & 1 deletion app/controllers/frontend/users/vacations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class VacationsController < Frontend::BaseController
before_action :find_user_vacation, only: %i[destroy]

def create
# commento: vacations.start_time, vacations.end_time
case add_user_vacation.call(user_vacation_params.merge(user: current_user))
in { errors: errors } then render json: { errors: errors }, status: :ok
in { result: result }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { apiRequest, csrfToken } from '../../../../helpers';

export const createFeedbackRequest = async (payload) => {
return await apiRequest({
url: '/frontend/feedback.json',
url: '/frontend/users/feedback.json',
options: {
method: 'POST',
headers: {
Expand Down
7 changes: 0 additions & 7 deletions app/models/feedback.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class User < ApplicationRecord
has_many :subscriptions, class_name: 'User::Subscription', foreign_key: :user_id, dependent: :destroy
has_many :vacations, class_name: 'User::Vacation', foreign_key: :user_id, dependent: :destroy

has_many :feedbacks, dependent: :destroy
has_many :feedbacks, class_name: 'User::Feedback', dependent: :destroy

has_many :api_access_tokens, dependent: :destroy

Expand Down
11 changes: 11 additions & 0 deletions app/models/user/feedback.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class User
class Feedback < ApplicationRecord
self.table_name = :feedbacks

encrypts :email

belongs_to :user
end
end
2 changes: 1 addition & 1 deletion app/notifiers/admin_telegram_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def feedback_created
private

def feedback_created_payload(id)
feedback = Feedback.find_by(id: id)
feedback = User::Feedback.find_by(id: id)
return '' unless feedback

"User - #{feedback.user_id}\nFeedback created - #{feedback.title}\n#{feedback.description}"
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def register(key)
register('commands.associate_entities_with_identity') { AssociateEntitiesWithIdentityCommand.new }
register('commands.add_repository') { AddRepositoryCommand.new }
register('commands.add_webhook') { AddWebhookCommand.new }
register('commands.add_feedback') { AddFeedbackCommand.new }
register('commands.add_user_feedback') { AddUserFeedbackCommand.new }
register('commands.add_notification') { AddNotificationCommand.new }
register('commands.add_invite') { AddInviteCommand.new }
register('commands.add_subscriber') { AddSubscriberCommand.new }
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
resources :notifications, only: %i[create destroy]
resources :ignores, only: %i[create]
resources :invites, only: %i[create]
resource :feedback, only: %i[create]
resources :ignores, only: %i[destroy]
resources :webhooks, only: %i[create destroy]
namespace :excludes do
Expand All @@ -65,6 +64,7 @@
resources :api_access_tokens, only: %i[create destroy]
namespace :users do
resources :vacations, only: %i[create destroy]
resource :feedback, only: %i[create]
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe AddFeedbackCommand do
describe AddUserFeedbackCommand do
subject(:command) { instance.call(params.merge(user: user)) }

let!(:instance) { described_class.new }
Expand All @@ -10,7 +10,7 @@
let(:params) { { description: '', email: 'email@gmail.com' } }

it 'does not create feedback', :aggregate_failures do
expect { command }.not_to change(Feedback, :count)
expect { command }.not_to change(User::Feedback, :count)
expect(command[:errors]).not_to be_blank
end
end
Expand All @@ -20,7 +20,7 @@

it 'creates feedback', :aggregate_failures do
expect { command }.to change(user.feedbacks, :count).by(1)
expect(Feedback.last.email).to be_nil
expect(User::Feedback.last.email).to be_nil
expect(command[:errors]).to be_nil
end

Expand All @@ -29,7 +29,7 @@

it 'creates feedback', :aggregate_failures do
expect { command }.to change(user.feedbacks, :count).by(1)
expect(Feedback.last.email).to eq 'email@gmail.com'
expect(User::Feedback.last.email).to eq 'email@gmail.com'
expect(command[:errors]).to be_nil
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe Frontend::FeedbacksController do
describe Frontend::Users::FeedbacksController do
describe 'POST#create' do
let(:delivery_service) { double }

Expand All @@ -19,7 +19,7 @@
let(:request) { post :create, params: { feedback: { title: '', description: '' }, pullmetry_access_token: access_token } }

it 'does not create feedback', :aggregate_failures do
expect { request }.not_to change(Feedback, :count)
expect { request }.not_to change(User::Feedback, :count)
expect(response).to have_http_status :ok
expect(response.parsed_body.dig('errors', 0)).to eq 'Description must be filled'
end
Expand All @@ -32,7 +32,7 @@

it 'creates feedback', :aggregate_failures do
expect { request }.to change(user.feedbacks, :count).by(1)
expect(response).to have_http_status :ok
expect(response).to have_http_status :created
expect(response.parsed_body['errors']).to be_nil
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

FactoryBot.define do
factory :feedback do
factory :feedback, class: 'User::Feedback' do
title { 'Title' }
description { 'Text' }
user
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

describe Feedback do
describe User::Feedback do
it 'factory should be valid' do
feedback = build :feedback

Expand Down

0 comments on commit 052461c

Please sign in to comment.