Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upload file multiple support, fix more problem about route scope. #1121

Closed
wants to merge 1 commit into from

Conversation

wndfly
Copy link

@wndfly wndfly commented Jul 10, 2019

Description of the Change

Alternate Designs

Benefits

Possible Drawbacks

drujensen
drujensen previously approved these changes Jul 10, 2019
Copy link
Member

@drujensen drujensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Couple minor requests.

src/amber/router/params.cr Outdated Show resolved Hide resolved
filename = upload.filename
if filename.is_a?(String) && !filename.empty?
files[upload.name] = Amber::Router::File.new(upload: upload)
if files.has_key? upload.name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm struggling to follow this logic. Can you refactor this down into smaller methods?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we can separate these?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll trying to refactor it. Thank you.

Copy link
Contributor

@alex-lairan alex-lairan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to review because you added some noises.

Please add a description of the scope error, without the multifile.

Maybe another pull request will help for comprehension.

@@ -12,4 +12,10 @@ module Amber::DSL::Server
end
{% end %}
end

macro namespace(scoped_namespace, value = :web)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@wndfly wndfly Jul 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swapped them because I want used it like this.

namespace "/foo" do
  namespace "/bar" do
  end
end
namespace "/foo1", :web do
  namespace "/bar" do
  end
end

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And what happen for

routes :web do
  namespace "/foo", :api do
    get "/bar" ...
  end
end

This is inconsistant and allow developpers to do crappy things.

@@ -1,9 +1,9 @@
module Amber
module Router
class Scope
@stack = [] of String
property :stack
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why leak the internal into the external world ?

No one should know Scope use an Array

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I change it back.

src/amber/router/scope.cr Outdated Show resolved Hide resolved
@@ -25,13 +24,11 @@ module Amber

# This registers all the routes for the application
def draw(valve : Symbol)
with DSL::Router.new(self, valve, scope) yield
with DSL::Router.new(self, valve, Scope.new) yield
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using Scope.new, you lose all benefits of nested scopes.

scope.push(namespace)
with DSL::Router.new(self, valve, scope) yield
scope.pop
with DSL::Router.new(self, valve, Scope.new([namespace])) yield
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use the current scope ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I used amber, I discovered a problem at the method with route match which doesn't add scope, so I modified more about scope.
Maybe I should modify it here, But I think keep scope in every route might be better.

.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
src/amber/pipes/static.cr Outdated Show resolved Hide resolved
src/amber/pipes/static.cr Show resolved Hide resolved
src/amber/router/scope.cr Outdated Show resolved Hide resolved
…aram name consistent with others.

add ignore.

fix a bug at route scope.

fix a bug about static file with route scope.

fix namespce route config.
@@ -28,7 +28,6 @@ module Amber::DSL
macro namespace(scoped_namespace)
scope.push({{scoped_namespace}})
{{yield}}
scope.pop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You push but not pop, this will add more and more namespaces.

@eliasjpr
Copy link
Contributor

eliasjpr commented Aug 6, 2019

@wndfly can you add the description to the PR and follow the template this helps the team evaluate the changes and intentions behind the changes. For instance I am not sure I understand the benefits of having then namespace

namespace "/foo" do
  # ... routes here
  namespace "/bar" do
  # ... routes here
  end
end

versus repeating scopes

scope "/foo", :web do
# ... routes here
end

scope "/foo/bar", :web do
# ... routes here
end

namespace might remove duplication, but it is also more verbose IMO and harder to read and understand when there is multiple nested namespaces

Having the ability to upload multiple files is 💯 good with me, it would be great to have them on a separate PR (the files part would have already been merged by now).

@drujensen
Copy link
Member

I'm going to close this PR. The file upload part would be nice as a separate PR. Mixing the routing change to the namespace is killing this PR.

@drujensen drujensen closed this Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants