-
Notifications
You must be signed in to change notification settings - Fork 0
Badge #37
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
base: main
Are you sure you want to change the base?
Conversation
config/routes.rb
Outdated
|
|
||
| resources :tests do | ||
| patch :update_inline, on: :member | ||
| delete :destroy, on: :member |
There was a problem hiding this comment.
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 ] |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
а если категорий будет больше? Тем более это всего лишь запись в таблице. То надо будет писать отдельный класс и копипастить 95% кода?. Достаточно одного подобного класса. а название категории можно передавать параметрами.
так же напрашивается DRY
app/services/badge_award_service.rb
Outdated
| end | ||
|
|
||
| def call | ||
| Badge.where.not(id: @user.badge_ids).each do |badge| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
по ТЗ юзер может получить бадж еще раз, при условии, что он выполнит ЕЩЕ РАЗ! условие правила.
app/models/test_passage.rb
Outdated
| def passed | ||
| completed? && test_successful? | ||
| end | ||
| alias_method :passed?, :passed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
лучше сразу метод называть правильно и альяс не нужен будет. Тем более у тебя в названии нарушение соглашения предикатных методов.
app/models/feedback.rb
Outdated
| validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP } | ||
| validates :message, presence: true | ||
|
|
||
| belongs_to :author, class_name: "User", foreign_key: "user_id" |
There was a problem hiding this comment.
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
app/models/badge.rb
Outdated
| validates :title, :text, :rule, :image_url, presence: true | ||
|
|
||
| def self.available_rules | ||
| BadgeAwardService::RULE_CLASSES.keys.map(&:to_s) |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
если почта отвалится или кривой будет конфиг, то контроллер вылетит с ошибкой. На проде лучше использовать deliver_later
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.