-
Hi, i am working on a new kemal + avram project which follow RESTful. When deal with new/edit user page, both of them share same form. so, i want to pass a user object to both new/edit page. edit page is easy, i can retrieve exists user record use UserQuery.find But, how to create a new not persisted user record? User.new is not work. Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
In Avram you can't have an empty model because this breaks the Lucky convention of type-safety first, and the representation that a model is just a read-only container of data. How you would do this would be to use a get "/users/new" do |env|
operation = SaveUser.new
end
post "/users" do |env|
# I'm not totally sure how to write params from Kemal
params = Avram::Params.new(env.params)
SaveUser.create(params) do |op, user|
end
end
get "/users/:user_id/edit" do |env|
user = UserQuery.find(user_id)
operation = SaveUser.new(user)
end
patch "/users/:user_id" do |env|
params = Avram::Params.new(env.params)
user = UserQuery.find(user_id)
SaveUser.update(user, params) do |op, u|
end
end
delete "/users/:user_id" do |env|
user = UserQuery.find(user_id)
DeleteUser.delete(user) do |op, u|
end
end Hope that helps. |
Beta Was this translation helpful? Give feedback.
In Avram you can't have an empty model because this breaks the Lucky convention of type-safety first, and the representation that a model is just a read-only container of data. How you would do this would be to use a
SaveOperation
.