app/controllers/api/v2/remote_edit_controller.rb
# POST #update_passage
#     { u: <user.email>, t: <auth_token>,
#       p: <passage.id>
#       mpg: <meeting_program_id>, pt: <passage_type_id>, s: <swimmer_id>, te: <team_id>,
#       time: <incremental_timing_text>, r: <reaction_timing_text>, mir: <MIR.id> }
#
# Creates or updates a specific row of passages, storing the resulting SQL
# text as a serialized DB-diff into the dedicated row (free_text_1) of AppParameter.
# The actual row ID for the serialization of the DB-diff SQL text depends upon
# the current_user.id (100_000 + user.id).
#
# At the end of the update process, a SendDbDiffJob will be invoked to be run after
# a few minutes.
# The delay in minutes should be chosen as "enough" to collect multiple DB updates
# at once, in order to avoid sending too many DB-diff files to the same SysOp e-mail.
#
# === Parameters:
# - "p"    => Passage.id, required only for edits
# - "time" => incremental timing value as text (e.g.: "1'15\"00");
#             when missing and the Passage.id is present, the Passage row is deleted
# - "r"    => reaction_time as text (e.g.: "0\"65")
# - "mpg"  => MeetingProgram ID
# - "pt"   => PassageType.id
# - "s"    => Swimmer.id
# - "te"   => Team.id
# - "mir"  => MeetingIndividualResult ID (when available)
# - "l"    => Request href/document.location
#
# === Returns:
#
# A JSON response (either :success or :error).
#


Creates or updates a specific row of passages, storing the resulting SQL
text as a serialized DB-diff into the dedicated row (free_text_1) of AppParameter.
The actual row ID for the serialization of the DB-diff SQL text depends upon
the current_user.id (100_000 + user.id).

At the end of the update process, a SendDbDiffJob will be invoked to be run after
a few minutes.
The delay in minutes should be chosen as "enough" to collect multiple DB updates
at once, in order to avoid sending too many DB-diff files to the same SysOp e-mail.





A JSON response (either :success or :error).
Creates or updates a specific row of passages storing the resulting SQL text as a serialized DB - diff into the dedicated row ( free_text_1 ) of AppParameter . The actual row ID for the serialization of the DB - diff SQL text depends upon the current_user . id ( 100_000 + user . id ) . At the end of the update process a SendDbDiffJob will be invoked to be run after a few minutes . The delay in minutes should be chosen as " enough " to collect multiple DB updates at once in order to avoid sending too many DB - diff files to the same SysOp e - mail . A JSON response ( either : success or : error ) .
def update_passage
    passage         = Passage.find_by_id( params['p'].to_i )
    timing_text     = params['time'].to_s
    reaction_text   = params['r'].to_s
    mpg_id          = params['mpg']
    passage_type_id = params['pt']
    swimmer_id      = params['s']
    team_id         = params['te']
    mir_id          = params['mir']
    req_url         = params['l'].to_s
    if passage.nil? && !timing_text.present?        
      render( status: 400, json: { result: "error", message: I18n.t("api.errors.invalid_request") } ) and return
      return
    end
    updater = PassageUpdater.new( current_user )
    result  = updater.process!( passage, timing_text, passage_type_id, mir_id,
                                reaction_text, swimmer_id, team_id, mpg_id )
    if result.nil?                                  
      render( status: 400, json: { result: "error", message: I18n.t("api.errors.unable_to_find_or_create_data_row") } ) and return
    elsif result                                    
      serialize_into_app_parameters!( updater, I18n.t('passages.index_title').upcase, req_url )
      SendDbDiffJob.set( queue: :edit, wait: WAIT_MINS_BEFORE_JOB_CREATE ).perform_later
    end
    render status: 200, json: { result: "ok" }
  end
def update_passage passage = Passage . find_by_id ( params [ 'p' ] . to_i ) timing_text = params [ 'time' ] . to_s reaction_text = params [ 'r' ] . to_s mpg_id = params [ 'mpg' ] passage_type_id = params [ 'pt' ] swimmer_id = params [ 's' ] team_id = params [ 'te' ] mir_id = params [ 'mir' ] req_url = params [ 'l' ] . to_s if passage . nil? && ! timing_text . present? render ( status : 400 , json : { result : "error" , message : I18n . t ( "api.errors.invalid_request" ) } ) and return return end updater = PassageUpdater . new ( current_user ) result = updater . process! ( passage , timing_text , passage_type_id , mir_id , reaction_text , swimmer_id , team_id , mpg_id ) if result . nil? render ( status : 400 , json : { result : "error" , message : I18n . t ( "api.errors.unable_to_find_or_create_data_row" ) } ) and return elsif result serialize_into_app_parameters! ( updater , I18n . t ( 'passages.index_title' ) . upcase , req_url ) SendDbDiffJob . set ( queue : :edit , wait : WAIT_MINS_BEFORE_JOB_CREATE ) . perform_later end render status : 200 , json : { result : "ok" } end
POST #update_passage
{ u: <user.email>, t: <auth_token>,
p: <passage.id>
mpg: <meeting_program_id>, pt: <passage_type_id>, s: <swimmer_id>, te: <team_id>,
time: <incremental_timing_text>, r: <reaction_timing_text>, mir: <MIR.id> }
POST #update_passage { u : <user . email > t : <auth_token > p : <passage . id > mpg : <meeting_program_id > pt : <passage_type_id > s : <swimmer_id > te : <team_id > time : <incremental_timing_text > r : <reaction_timing_text > mir : <MIR . id > }
# DEBUG #    puts "\r\n--- #update_passage: ---\r\nPARAMS: #{ params.inspect }" # Fetch params # Nothing to do, bail out: # --- ERROR during CREATE/UPDATE --- # --- CREATE / UPDATE / DELETE performed --- # Add SQL text to AppParameter: # Launch delayed Job to send the DB-diff to the SysOp using the remote-editing # dedicated named queue ('edit'): #    else # (no operations for result false => DELETE skipped => no SQL edits)