Refactor app in to its own slice
This commit is contained in:
33
slices/main/actions/workouts/create.rb
Normal file
33
slices/main/actions/workouts/create.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module Main
|
||||
module Actions
|
||||
module Workouts
|
||||
class Create < Action
|
||||
include Deps["geo.gpx_parser", "commands.workouts.create"]
|
||||
|
||||
def handle(req, res)
|
||||
tempfile = Tempfile.new(%w[path .gpx])
|
||||
|
||||
if !req.params.to_h.dig(:file, :tempfile).nil?
|
||||
tempfile.write req.params[:file][:tempfile].read
|
||||
else
|
||||
tempfile.write req.params[:file]
|
||||
end
|
||||
|
||||
tempfile.rewind
|
||||
|
||||
gpxfile = gpx_parser.call(path: tempfile.path)
|
||||
|
||||
if gpxfile.success?
|
||||
create.call(**gpxfile.value!)
|
||||
res.status = 201
|
||||
else
|
||||
res.status = 500
|
||||
end
|
||||
ensure
|
||||
tempfile.close
|
||||
tempfile.unlink
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
slices/main/actions/workouts/index.rb
Normal file
13
slices/main/actions/workouts/index.rb
Normal file
@@ -0,0 +1,13 @@
|
||||
module Main
|
||||
module Actions
|
||||
module Workouts
|
||||
class Index < Action
|
||||
include Deps["views.workouts.index"]
|
||||
|
||||
def handle(req, res)
|
||||
res.render index
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user