dto postfix
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class Api::ImagesController < ApplicationController
|
||||
def show
|
||||
image = ImageService.new.show(ImageShowInput.new(id: params[:id]))
|
||||
image = ImageService.new.show(ImageShowInputDTO.new(id: params[:id]))
|
||||
send_file image.file_path, type: image.content_type, disposition: "inline"
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render plain: "Not Found", status: :not_found
|
||||
|
||||
@@ -2,7 +2,7 @@ class FilesController < ApplicationController
|
||||
skip_forgery_protection
|
||||
|
||||
def show
|
||||
result = FileService.new.show(FileShowInput.new(path: params[:path]))
|
||||
result = FileService.new.show(FileShowInputDTO.new(path: params[:path]))
|
||||
case result.type
|
||||
when :redirect then redirect_to result.url, status: :moved_permanently
|
||||
when :file
|
||||
|
||||
@@ -3,7 +3,7 @@ class UpdateController < ApiController
|
||||
return render plain: "Unauthorized", status: :unauthorized unless authorized?
|
||||
return render plain: "Version not provided", status: :bad_request if params[:version].blank?
|
||||
|
||||
input = UpdateInput.new(
|
||||
input = UpdateInputDTO.new(
|
||||
platform: params[:platform],
|
||||
name: params[:name],
|
||||
version: params[:version]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class FileResult
|
||||
class FileResultDTO
|
||||
attr_reader :type, :path, :url
|
||||
|
||||
def initialize(type:, path: nil, url: nil)
|
||||
|
||||
@@ -1 +1 @@
|
||||
FileShowInput = Struct.new(:path, keyword_init: true)
|
||||
FileShowInputDTO = Struct.new(:path, keyword_init: true)
|
||||
|
||||
@@ -1 +1 @@
|
||||
ImageShowInput = Struct.new(:id, keyword_init: true)
|
||||
ImageShowInputDTO = Struct.new(:id, keyword_init: true)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
UpdateInput = Struct.new(:platform, :name, :version, keyword_init: true) do
|
||||
UpdateInputDTO = Struct.new(:platform, :name, :version, keyword_init: true) do
|
||||
def initialize(platform:, name:, version: nil)
|
||||
super
|
||||
end
|
||||
|
||||
@@ -6,14 +6,14 @@ class FileService
|
||||
|
||||
if File.directory?(full_path)
|
||||
index_path = full_path.join("index.html")
|
||||
return FileResult.not_found unless File.file?(index_path)
|
||||
return FileResult.redirect("/file/#{input.path.to_s.chomp("/")}/index.html")
|
||||
return FileResultDTO.not_found unless File.file?(index_path)
|
||||
return FileResultDTO.redirect("/file/#{input.path.to_s.chomp("/")}/index.html")
|
||||
end
|
||||
|
||||
if File.file?(full_path)
|
||||
FileResult.file(full_path)
|
||||
FileResultDTO.file(full_path)
|
||||
else
|
||||
FileResult.not_found
|
||||
FileResultDTO.not_found
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user