Skip to content

Commit

Permalink
#121 show all authors
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed May 12, 2020
1 parent f442e2e commit 368dc10
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ gem 'tacky', '0.3.5'
gem 'telepost', '>=0.3.2'
gem 'thin', '1.7.2'
gem 'threads', '>=0.3'
gem 'veils', '0.1.1'
gem 'veils', '0.2.0'
gem 'xcop', '0.6'
gem 'zache', '>=0.12.0'
gem 'zold-ruby-sdk', '0.2.3'
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ GEM
usagewatch (0.0.7)
usagewatch_ext (0.2.1)
usagewatch (~> 0.0.6)
veils (0.1.1)
veils (0.2.0)
virtus (1.0.5)
axiom-types (~> 0.1)
coercible (~> 1.0)
Expand Down Expand Up @@ -308,7 +308,7 @@ DEPENDENCIES
telepost (>= 0.3.2)
thin (= 1.7.2)
threads (>= 0.3)
veils (= 0.1.1)
veils (= 0.2.0)
xcop (= 0.6)
zache (>= 0.12.0)
zold-ruby-sdk (= 0.2.3)
Expand Down
1 change: 1 addition & 0 deletions codexia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def iri
require_relative 'front/front_login.rb'
require_relative 'front/front_helpers.rb'
require_relative 'front/front_author.rb'
require_relative 'front/front_authors.rb'
require_relative 'front/front_project.rb'
require_relative 'front/front_projects.rb'
require_relative 'front/front_karma.rb'
Expand Down
28 changes: 28 additions & 0 deletions front/front_authors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# Copyright (c) 2020 Yegor Bugayenko
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the 'Software'), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

get '/authors' do
haml :authors, layout: :layout, locals: merged(
title: '/authors',
list: the_authors.best
)
end
20 changes: 20 additions & 0 deletions objects/authors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

require 'loog'
require 'telepost'
require 'unpiercable'
require_relative 'xia'
require_relative 'author'

Expand All @@ -41,4 +42,23 @@ def named(login)
id = @pgsql.exec('SELECT id FROM author WHERE login=$1', [login])[0]['id'].to_i
Xia::Author.new(@pgsql, id, log: @log, telepost: @telepost)
end

def best(limit: 25)
@pgsql.exec(
[
'SELECT author.id, author.login, SUM(withdrawal.points) AS points FROM author',
'JOIN withdrawal ON author.id=withdrawal.author',
'GROUP BY author.id',
'ORDER BY points DESC',
'LIMIT $1'
].join(' '),
[limit]
).map do |r|
Unpiercable.new(
Xia::Author.new(@pgsql, r['id'].to_i, log: @log, telepost: @telepost),
login: r['login'],
points: r['points'].to_i
)
end
end
end
1 change: 1 addition & 0 deletions test/test_codexia.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def test_200_user_pages
'/payables?a=-test',
'/a/-test',
'/submit',
'/authors',
'/terms',
'/bots',
'/sql',
Expand Down
13 changes: 13 additions & 0 deletions views/authors.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
%table
%thead
%tr
%th Login
%th.right Earned
%tbody
- list.each do |a|
%tr
%td
= partial(:author, locals, a: a)
%td
= a.points

4 changes: 4 additions & 0 deletions views/layout.haml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
%li
%a{href: iri.cut('/submit'), title: 'Submit a new project'}
= '/submit'
- if defined?(author)
%li
%a{href: iri.cut('/authors'), title: 'Most active authors'}
= '/authors'
- if defined?(author)
%li
%a{href: iri.cut('/terms')}
Expand Down

0 comments on commit 368dc10

Please sign in to comment.