Skip to content

Conversation

@PavelPo99
Copy link
Owner

Develop functionality that will allow users to receive badges (rewards) for successfully passing the tests.

Badges are presented as a Badge model
A user can receive the same badge more than once.
The badge must contain the following attributes:
Title
The name of the image file (You don't need to upload images. It can be a static image file that is manually added to the project. Or it can be any URL with a badge image)
Badges are issued automatically after the test is completed.
The badges are managed by the administrator
When creating a badge, the administrator also assigns a rule that determines the order in which the badge is issued. Examples of rules:
Issue a badge after successfully passing all the tests from the Backend category
Issue a badge after successfully passing the test on the first attempt
Issue a badge after successfully passing all the tests of a certain level
It is allowed that the criteria for the rules are set in advance, for example, at the level of the model attributes
The user can view a list of all existing and earned badges at any time.

config/routes.rb Outdated

resources :tests do
patch :update_inline, on: :member
delete :destroy, on: :member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

такой путь уже есть

config/routes.rb Outdated

devise_for :users, controllers: { sessions: "sessions" }, path: :gurus, path_names: { sign_in: :login, sign_out: :logout }

resources :badges, only: [ :index ]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resources :badges, only: [:index]
м/у скобками [] отступы не принято оставлять, в отличии от { }

.map(&:test)
.uniq
.count == tests_in_category.count
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

дублирующий код стоит вынести в абстрактный класс. DRY

@@ -0,0 +1,18 @@
module Badges
class AllFrontendTests

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а если категорий будет больше? Тем более это всего лишь запись в таблице. То надо будет писать отдельный класс и копипастить 95% кода?. Достаточно одного подобного класса. а название категории можно передавать параметрами.
так же напрашивается DRY

end

def call
Badge.where.not(id: @user.badge_ids).each do |badge|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

по ТЗ юзер может получить бадж еще раз, при условии, что он выполнит ЕЩЕ РАЗ! условие правила.

def passed
completed? && test_successful?
end
alias_method :passed?, :passed

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лучше сразу метод называть правильно и альяс не нужен будет. Тем более у тебя в названии нарушение соглашения предикатных методов.

validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }
validates :message, presence: true

belongs_to :author, class_name: "User", foreign_key: "user_id"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ассоциации объявляют до ассоциаций. Смотри https://github.com/rubocop/rails-style-guide#macro-style-methods

validates :title, :text, :rule, :image_url, presence: true

def self.available_rules
BadgeAwardService::RULE_CLASSES.keys.map(&:to_s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

модели не должны знать ни чего о бизнес процессах. Это всего-лишь сущность. Только контроллеры или другие сервисы могут вызывать сервисы. Иначе будет бардак в архитектуре. Мы это не поддерживаем.

@@ -0,0 +1,7 @@
class Feedback < ApplicationRecord

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

фидбек можно и не сохранять в бд.

@feedback.author = current_user

if @feedback.save
FeedbackMailer.feedback_email(@feedback).deliver_now

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

если почта отвалится или кривой будет конфиг, то контроллер вылетит с ошибкой. На проде лучше использовать deliver_later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants