-
Notifications
You must be signed in to change notification settings - Fork 16
Домашнее задание 2 #34
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: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,6 @@ SECRET_KEY_BASE= | |
| PGPASSWORD=postgres | ||
| [email protected] | ||
| INDEX_CONCURRENT_PROCESSES= | ||
|
|
||
| MONGO_HOST=mongo | ||
| MONGO_PORT=27017 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отлично! Не забыли добавить переменные окружения в .sample.env (вы единственный кто это сделал ))) |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ gem 'puma', '>= 6.5.0' | |
|
|
||
| # Базы данных | ||
| gem 'pg' | ||
| gem 'mongoid' | ||
|
|
||
| # Многопоточное выполнение | ||
| gem 'parallel' | ||
|
|
@@ -14,6 +15,9 @@ gem 'activerecord-import' | |
| gem 'sprockets-rails' | ||
| gem 'slim-rails' | ||
|
|
||
| # Serializers | ||
| gem 'jbuilder' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Традиционно выбрал бы вместо jbuilder, что-то по-шустрее: он когда разрастется и обрастет логикой, его потом трудно заменять. Но про это уже писал в первом задании |
||
|
|
||
| # Распаковка архивов | ||
| gem 'rubyzip', require: 'zip' | ||
|
|
||
|
|
@@ -29,6 +33,9 @@ gem 'activeadmin' | |
| gem 'activeadmin_addons' | ||
| gem 'devise' | ||
|
|
||
| # Паджинация | ||
| gem 'kaminari-mongoid' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отлично! |
||
|
|
||
| group :development, :test do | ||
| gem 'bundler-audit' | ||
| gem 'capybara' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class BooksController < ApplicationController | ||
| def index | ||
| page = params[:page].to_i.positive? ? params[:page].to_i : 1 | ||
|
|
||
| @books = Mongo::BookMongo.all.page(page) | ||
|
|
||
| render formats: :json | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| module Mongo | ||
| class BookMongo | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Если модель вызывать где-то в коде, то получается не очень красиво: Mongo::BookMongo - два раза Mongo. И вообще лучше как-то переименовать, чтобы в названии не было отсылки к MongoDB. Вдруг потом захотим сменить базу данных на ElasticSearch а название уже расползется по всему проекту. Это конечно, не большая проблема с современными IDE, но все-равно лучше какое-нибудь бизнесовое название BookSource или Documents::Book. Потом копипастой эта Mongo расползется по всем моделям, и каждая модель будет "кричать" что она от MongoDB, вместо того, чтобы "кричать" о своем бизнес-назначении или домене. Это не проблема в маленьком приложении, но если моделей 100 и все они говорят, что они работают с MongoDB - это утомляет, хочется узнать, а чем эти 100 моделей друг от друга отличаются. |
||
| include Mongoid::Document | ||
| include Mongoid::Timestamps | ||
|
|
||
| field :title, type: String | ||
| field :series, type: String | ||
| field :serno, type: String | ||
| field :libid, type: Integer | ||
| field :size, type: Integer | ||
| field :filename, type: String | ||
| field :del, type: Boolean | ||
| field :ext, type: String | ||
| field :published_at, type: Date | ||
| field :insno, type: String | ||
| field :folder_id, type: String | ||
| field :language_id, type: String | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Отлично! Скрупулезно перечислены атрибуты |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| json.array! @books, :id, :title |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,8 @@ default: &default | |
| postgre: &postgre | ||
| host: <%= ENV.fetch('POSTGRES_HOST', 'localhost') %> | ||
| port: <%= ENV.fetch('POSTGRES_PORT', '5432') %> | ||
| username: <%= ENV.fetch('POSTGRES_USER') { 'igorsimdyanov' } %> | ||
| password: <%= ENV.fetch('POSTGRES_PASSWORD') { '' } %> | ||
| username: <%= ENV.fetch('POSTGRES_USER') { 'postgres' } %> | ||
| password: <%= ENV.fetch('postgres') { '' } %> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут явно опечатка, если потом захотите сменить пароль - будут проблемы. Писал об этом в первом мердж-реквесте, но понимаю, что не успели поправить (почти одновременно отправили). |
||
|
|
||
| development: | ||
| <<: *default | ||
|
|
@@ -17,6 +17,7 @@ development: | |
|
|
||
| test: | ||
| <<: *default | ||
| <<: *postgre | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Очень хорошо! |
||
| database: library_test | ||
|
|
||
| production: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Kaminari.configure do |config| | ||
| config.default_per_page = Settings.app.items_per_page | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # rubocop:todo all | ||
| Mongoid.configure do | ||
| target_version = "9.0" | ||
|
|
||
| # Load Mongoid behavior defaults. This automatically sets | ||
| # features flags (refer to documentation) | ||
| config.load_defaults target_version | ||
|
|
||
| # It is recommended to use config/mongoid.yml for most Mongoid-related | ||
| # configuration, whenever possible, but if you prefer, you can set | ||
| # configuration values here, instead: | ||
| # | ||
| # config.log_level = :debug | ||
| # | ||
| # Note that the settings in config/mongoid.yml always take precedence, | ||
| # whatever else is set here. | ||
| end | ||
|
|
||
| # Enable Mongo driver query cache for Rack | ||
| # Rails.application.config.middleware.use(Mongo::QueryCache::Middleware) | ||
|
|
||
| # Enable Mongo driver query cache for ActiveJob | ||
| # ActiveSupport.on_load(:active_job) do | ||
| # include Mongo::QueryCache::Middleware::ActiveJob | ||
| # 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.
Отлично!