-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from nickel/more-redesigning
More redesigning
- Loading branch information
Showing
11 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
class Tag::FindAll < CommandHandler::Command | ||
BY_VISIBILITY_FILTERS = Note::FindAll::BY_VISIBILITY_FILTERS | ||
|
||
class Form | ||
include CommandHandler::Form | ||
|
||
attribute :by_visibility, :string, default: "public" | ||
|
||
validates :by_visibility, inclusion: { in: BY_VISIBILITY_FILTERS } | ||
end | ||
|
||
delegate(*Form.new.attributes.keys, to: :form) | ||
|
||
def call | ||
Response.success(find_all) | ||
end | ||
|
||
private | ||
|
||
def find_all | ||
notes = Note.select(:tags) | ||
notes = by_visibility == "private" ? notes : Note.where(private: false) | ||
|
||
notes | ||
.map(&:tags) | ||
.flatten | ||
.tally | ||
.sort_by { |_, count| -count } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<%= form_for @note_form, url: note_path(@note.id), method: :put, html: { class: "max-w-sm mx-auto mt-20" } do |form| %> | ||
<%= render "form", note: @note_form, form: form %> | ||
|
||
<div> | ||
<%= form.submit "Edit note" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
<%= form_for @note_form, url: notes_path, html: { class: "max-w-sm mx-auto mt-20" } do |form| %> | ||
<%= render "form", note: @note_form, form: form %> | ||
|
||
<div> | ||
<%= form.submit "Create note" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class Tag::FindAllTest < ActiveSupport::TestCase | ||
test "tags are grouped" do | ||
3.times { Factory.generate_note(private: false, tags: "foo, bar") } | ||
|
||
response = Tag::FindAll.call | ||
|
||
assert response.success? | ||
assert_equal 2, response.value.length | ||
|
||
response.value.to_h.each_value do |count| | ||
assert_equal 3, count | ||
end | ||
end | ||
end |