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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ coverage
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
.idea
5 changes: 5 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 @@ -29,6 +30,10 @@ gem 'activeadmin'
gem 'activeadmin_addons'
gem 'devise'

gem 'alba'
gem 'kaminari'
gem 'kaminari-mongoid'

group :development, :test do
gem 'bundler-audit'
gem 'capybara'
Expand Down
20 changes: 18 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ GEM
uri (>= 0.13.1)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
alba (3.5.0)
ostruct (~> 0.6)
arbre (1.7.0)
activesupport (>= 3.0.0)
ruby2_keywords (>= 0.0.2)
Expand All @@ -104,6 +106,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 @@ -210,6 +213,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 +232,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 @@ -270,7 +282,7 @@ GEM
puma (6.5.0)
nio4r (~> 2.0)
racc (1.8.1)
rack (3.1.10)
rack (3.1.11)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand Down Expand Up @@ -416,7 +428,7 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
uri (1.0.2)
uri (1.0.3)
useragent (0.16.10)
warden (1.2.9)
rack (>= 2.0.9)
Expand Down Expand Up @@ -448,6 +460,7 @@ DEPENDENCIES
activeadmin
activeadmin_addons
activerecord-import
alba
bundler-audit
capybara
config
Expand All @@ -460,6 +473,9 @@ DEPENDENCIES
factory_bot_rails
fasterer
ffaker
kaminari
kaminari-mongoid
mongoid
parallel
pg
pry-byebug
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class BooksController < ApplicationController
def index
query = Mongo::Book.all.page(params[:page]).per(Settings.app.items_per_page)

render json: {
books: query,
pagination: {
page: query.current_page,
per_page: query.limit_value,
page_count: query.total_pages,
total: query.total_count
}
}
end
end
18 changes: 18 additions & 0 deletions app/controllers/concerns/pagination.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Pagination
extend ActiveSupport::Concern
include Pagy::Backend

def paginate_json(scope:, key:, serializer:)
pagy, records = pagy(scope)

{
key => serializer.new(records),
pagination: {
page: pagy.page,
per_page: pagy.limit,
page_count: pagy.pages,
total: pagy.count
}
}
end
end
11 changes: 11 additions & 0 deletions app/models/mongo/author.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Mongo
class Author
include Mongoid::Document

field :id, type: String
field :first_name, type: String
field :last_name, type: String
field :middle_name, type: String
field :original, type: String
end
end
23 changes: 23 additions & 0 deletions app/models/mongo/book.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Mongo
class Book
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: Integer
field :del, type: Boolean
field :ext, type: String
field :published_at, type: Date
field :insno, type: String
field :language, type: String

embeds_one :folder
embeds_many :authors
embeds_many :genres
embeds_many :keywords
end
end
8 changes: 8 additions & 0 deletions app/models/mongo/folder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Mongo
class Folder
include Mongoid::Document

field :id, type: String
field :name, type: String
end
end
9 changes: 9 additions & 0 deletions app/models/mongo/genre.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Mongo
class Genre
include Mongoid::Document

field :id, type: String
field :slug, type: String
field :name, type: String
end
end
8 changes: 8 additions & 0 deletions app/models/mongo/keyword.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Mongo
class Keyword
include Mongoid::Document

field :id, type: String
field :name, type: String
end
end
5 changes: 5 additions & 0 deletions app/serializers/author_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AuthorSerializer
include Alba::Resource

attributes :id, :first_name, :last_name, :middle_name, :original
end
15 changes: 15 additions & 0 deletions app/serializers/book_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class BookSerializer
include Alba::Resource

attributes :id, :title, :series, :serno, :libid, :size, :filename,
:del, :ext, :published_at, :insno

one :folder, resource: FolderSerializer
many :authors, resource: AuthorSerializer
many :genres, resource: GenreSerializer
many :keywords, resource: KeywordSerializer

attribute :language do |book|
book.language.slug
end
end
5 changes: 5 additions & 0 deletions app/serializers/folder_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class FolderSerializer
include Alba::Resource

attributes :id, :name
end
5 changes: 5 additions & 0 deletions app/serializers/genre_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class GenreSerializer
include Alba::Resource

attributes :id, :slug, :name
end
5 changes: 5 additions & 0 deletions app/serializers/keyword_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class KeywordSerializer
include Alba::Resource

attributes :id, :name
end
1 change: 1 addition & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ development:

test:
<<: *default
<<: *postgre
database: library_test

production:
Expand Down
5 changes: 5 additions & 0 deletions config/initializers/mongoid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# rubocop:todo all
Mongoid.configure do
target_version = "9.0"
config.load_defaults target_version
end
6 changes: 6 additions & 0 deletions config/mongoid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
development:
clients:
default:
database: library_development
hosts:
- <%= ENV.fetch('MONGO_HOST') { 'localhost:27017' } %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
# # delete 'logout', to: 'sessions#destroy'
# # end
# end
get 'books(/:page)', to: 'books#index', defaults: { page: 1 }, constraints: { page: /\d+/ }

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ services:
POSTGRES_PASSWORD: 'postgres'
volumes:
- db:/var/lib/postgresql/data
mongodb:
image: mongo:6.0
container_name: mongodb
restart: always
ports:
- "27017:27017"
volumes:
- mongodb_data:/data/db
web:
tty: true
stdin_open: true
Expand Down Expand Up @@ -33,5 +41,7 @@ services:
POSTGRES_HOST: 'db'
POSTGRES_USER: 'postgres'
POSTGRES_PASSWORD: 'postgres'
MONGO_HOST: 'mongodb:27017'
volumes:
db:
mongodb_data:
10 changes: 10 additions & 0 deletions docs/kafkatry-ruby/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# See https://git-scm.com/docs/gitattributes for more about git attribute files.

# Mark the database schema as having been generated.
db/schema.rb linguist-generated

# Mark the yarn lockfile as having been generated.
yarn.lock linguist-generated

# Mark any vendored files as having been vendored.
vendor/* linguist-vendored
31 changes: 31 additions & 0 deletions docs/kafkatry-ruby/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
#
# If you find yourself ignoring temporary files generated by your text editor
# or operating system, you probably want to add a global ignore instead:
# git config --global core.excludesfile '~/.gitignore_global'

# Ignore bundler config.
/.bundle
/.env

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

/public/assets
.byebug_history

# Ignore master key for decrypting credentials and more.
/config/master.key
/config/credentials.yml.enc

/.idea
*.local.yml
coverage
Loading