Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ coverage
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml

# IDE files
/.idea/*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Отлично!

3 changes: 3 additions & 0 deletions .sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ SECRET_KEY_BASE=
PGPASSWORD=postgres
[email protected]
INDEX_CONCURRENT_PROCESSES=

MONGO_HOST=mongo
MONGO_PORT=27017
Copy link
Collaborator

Choose a reason for hiding this comment

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

Отлично! Не забыли добавить переменные окружения в .sample.env (вы единственный кто это сделал )))

7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ gem 'puma', '>= 6.5.0'

# Базы данных
gem 'pg'
gem 'mongoid'

# Многопоточное выполнение
gem 'parallel'
Expand All @@ -14,6 +15,9 @@ gem 'activerecord-import'
gem 'sprockets-rails'
gem 'slim-rails'

# Serializers
gem 'jbuilder'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Традиционно выбрал бы вместо jbuilder, что-то по-шустрее: он когда разрастется и обрастет логикой, его потом трудно заменять. Но про это уже писал в первом задании


# Распаковка архивов
gem 'rubyzip', require: 'zip'

Expand All @@ -29,6 +33,9 @@ gem 'activeadmin'
gem 'activeadmin_addons'
gem 'devise'

# Паджинация
gem 'kaminari-mongoid'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Отлично!


group :development, :test do
gem 'bundler-audit'
gem 'capybara'
Expand Down
16 changes: 16 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ GEM
benchmark (0.4.0)
bigdecimal (3.1.8)
bindex (0.8.1)
bson (5.0.2)
builder (3.3.0)
bundler-audit (0.9.2)
bundler (>= 1.2.0, < 3)
Expand Down Expand Up @@ -193,6 +194,9 @@ GEM
irb (1.14.0)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jbuilder (2.13.0)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jquery-rails (4.6.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
Expand All @@ -210,6 +214,9 @@ GEM
activerecord
kaminari-core (= 1.2.2)
kaminari-core (1.2.2)
kaminari-mongoid (1.0.2)
kaminari-core (~> 1.0)
mongoid
language_server-protocol (3.17.0.3)
logger (1.6.0)
loofah (2.23.1)
Expand All @@ -226,6 +233,12 @@ GEM
mini_mime (1.1.5)
mini_portile2 (2.8.8)
minitest (5.25.1)
mongo (2.21.0)
bson (>= 4.14.1, < 6.0.0)
mongoid (9.0.6)
activemodel (>= 5.1, < 8.1, != 7.0.0)
concurrent-ruby (>= 1.0.5, < 2.0)
mongo (>= 2.18.0, < 3.0.0)
net-imap (0.5.6)
date
net-protocol
Expand Down Expand Up @@ -460,6 +473,9 @@ DEPENDENCIES
factory_bot_rails
fasterer
ffaker
jbuilder
kaminari-mongoid
mongoid
parallel
pg
pry-byebug
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/books_controller.rb
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
19 changes: 19 additions & 0 deletions app/models/mongo/book_mongo.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Mongo
class BookMongo
Copy link
Collaborator

@igorsimdyanov igorsimdyanov Mar 12, 2025

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

@igorsimdyanov igorsimdyanov Mar 12, 2025

Choose a reason for hiding this comment

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

Отлично! Скрупулезно перечислены атрибуты

end
end
1 change: 1 addition & 0 deletions app/views/books/index.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
json.array! @books, :id, :title
5 changes: 3 additions & 2 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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') { '' } %>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Тут явно опечатка, если потом захотите сменить пароль - будут проблемы. Писал об этом в первом мердж-реквесте, но понимаю, что не успели поправить (почти одновременно отправили).


development:
<<: *default
Expand All @@ -17,6 +17,7 @@ development:

test:
<<: *default
<<: *postgre
Copy link
Collaborator

Choose a reason for hiding this comment

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

Очень хорошо!

database: library_test

production:
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/kaminari_config.rb
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
25 changes: 25 additions & 0 deletions config/initializers/mongoid.rb
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
Loading