Closed tsimica closed 4 years ago
I had a look just now at https://github.com/uoft-tapp/tapp/pull/218/files. It's less idiomatic than master. I am not too what the intention was here.
Most of these items look good. Two comments: (a) we decided on 4 spaces over 2. This is a calculated deviation; (b) we decided that the API would aways return 200, unless there was an uncaught rails error. The returned JSON should include {status: "error", ...}
if there was an error that was caught. (I'm not sure if this is what you were referring to, but how can this result in stale data?)
We are also deviating from traditional rails REST in a few key ways: we only use GET and POST, we always return JSON with status 200, and we have upsert instead of insert and update (the rule being if the ID is included, it is an update, otherwise an insert)
Understood. Thanks for clarifying.
For the stale data part, consider the following:
I think we'll need to talk about this in person. There is something I am not understanding about this situation.
I assume this was handled by the rewrite.
As discussed with @reidka, the Rails codebase needs to be refactored to adhere to best Rails practices. Some of the work would include (but not limited to):
General
Rails Specific
config/routes.rb
app/controllers/concerns/Response.rb
render json: {...}, status: :bad_request
should be used inrender_error
app/controllers/api/v1/applications_controller.rb
before_action
anywhere.invalid_id(Session, :session_id)
,Application.find(params[:id])
appear twice. These should be refactored.model.destroy!
after a save is invalid raises serious concerns -- is this something that is explicitly needed? The database and model validations should enforce constraints.all_applications
andapplication_data
should be refactored into the model. If you're trying to include an associated model, consider using.includes
then.to_json(includes: X)
applications_by_session
should also use ActiveRecord methods instead of Ruby methods.exists?
at all when.find
can be used -- you get the object for free and can use the methods on itControllers not mentioned fall into some issue mentioned above, or they are yet to be posted here.
app/mailers/action_mailer.rb
app/models/session.rb
validates_uniqueness_of :name
should be constrained by the database to avoid race conditions