Commit 26712257
Changed files (7)
app
controllers
models
services
app/controllers/application_controller.rb
@@ -18,9 +18,6 @@ class ApplicationController < ActionController::Base
end
def load_categories
- #@categories = Rails.cache.fetch("categories-#{Category.count}") do
- #Category.all
- #end
@categories = Category.all
end
app/controllers/favorites_controller.rb
@@ -22,6 +22,7 @@ class FavoritesController < ApplicationController
end
private
+
def find_creation
@creation = Creation.find(params[:creation_id])
raise ActiveRecord::RecordNotFound unless @creation
app/models/category.rb
@@ -1,6 +1,5 @@
class Category < ActiveRecord::Base
has_and_belongs_to_many :creations, :join_table => 'creations_categories'
- #attr_accessible :name, :slug
default_scope -> { order(:name) }
def to_param
app/models/creation.rb
@@ -8,7 +8,6 @@ class Creation < ActiveRecord::Base
default_scope -> { order("created_at DESC") }
- # to be removed and moved to the DisplayCreationDTO
def to_param
"#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}"
end
app/services/dto/display_creation_dto.rb
@@ -1,9 +0,0 @@
-class DisplayCreationDTO
- attr_accessor :id, :name, :story, :primary_image, :thumb_url, :user, :favorites
- def self.model_name
- ActiveModel::Name.new(self, nil, 'Creation')
- end
- def to_param
- "#{id}-#{name.gsub(/[^a-z0-9]+/i, '-')}"
- end
-end
app/services/mappers/creation_to_display_creation_dto_mapper.rb
@@ -1,13 +0,0 @@
-class CreationToDisplayCreationDTOMapper
- def map_from(creation)
- dto = DisplayCreationDTO.new
- dto.id = creation.id
- dto.name = creation.name
- dto.story = creation.story
- dto.primary_image = creation.primary_image
- dto.thumb_url = creation.primary_image.image.thumb.url
- dto.user = creation.user
- dto.favorites = creation.favorites
- dto
- end
-end
app/services/queries/find_all_creations_query.rb
@@ -1,6 +1,6 @@
class FindAllCreationsQuery
- def initialize(mapper = CreationToDisplayCreationDTOMapper.new)
- @mapper = mapper
+ def initialize(repository = Creation.where(nil))
+ @repository = repository
end
def fetch(params)
@@ -10,6 +10,10 @@ class FindAllCreationsQuery
private
def find_creations
- Creation.includes(:user, :photos).where(:is_restricted => false).where('photos_count > 0').uniq
+ @repository
+ .includes(:user, :photos)
+ .where(:is_restricted => false)
+ .where('photos_count > 0')
+ .uniq
end
end