app/controllers/api/v2/remote_edit_controller.rb
# POST #update_relay_swimmer
#     { u: <user.email>, t: <auth_token>,
#       mrr: <MRR_id>, o: <relay_order>, s: <swimmer_id>,
#       time: <incremental_timing_text>, r: <reaction_timing_text> }
#
# Creates or updates a specific row of meeting_relay_swimmers, 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.
#
# === Minimun/Required Parameters:
# - "mrr" => MeetingRelayResult ID (key#1, used for MeetingRelaySwimmer.find_or_create_by)
# - "o"   => lap/step ordering in relay (key#2, used for MeetingRelaySwimmer.find_or_create_by)
# - "s"   => Swimmer.id (when not set, allows to clear the row)
#
# === Additional Parameters:
# - "time" => incremental timing value as text (e.g.: "1'15\"00")
# - "r"    => reaction_time as text (e.g.: "0\"65")
# - "l"    => Request href/document.location
#
# === Returns:
#
# A JSON response (either :success or :error).
#


Creates or updates a specific row of meeting_relay_swimmers, 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 meeting_relay_swimmers 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_relay_swimmer
    mrr         = MeetingRelayResult.find_by_id( params['mrr'].to_i )
    relay_order = params['o'].to_i
    swimmer_id  = params['s'].to_i
    timing_text   = params['time'].to_s
    reaction_text = params['r'].to_s
    req_url       = params['l'].to_s
    unless mrr && (relay_order > 0)                 
      render( status: 400, json: { result: "error", message: I18n.t("api.errors.invalid_request") } ) and return
      return
    end
    updater = RelaySwimmerUpdater.new( current_user )
    result  = updater.process!( mrr, relay_order, swimmer_id, timing_text, reaction_text )
    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.relay_athlete').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_relay_swimmer mrr = MeetingRelayResult . find_by_id ( params [ 'mrr' ] . to_i ) relay_order = params [ 'o' ] . to_i swimmer_id = params [ 's' ] . to_i timing_text = params [ 'time' ] . to_s reaction_text = params [ 'r' ] . to_s req_url = params [ 'l' ] . to_s unless mrr && ( relay_order > 0 ) render ( status : 400 , json : { result : "error" , message : I18n . t ( "api.errors.invalid_request" ) } ) and return return end updater = RelaySwimmerUpdater . new ( current_user ) result = updater . process! ( mrr , relay_order , swimmer_id , timing_text , reaction_text ) 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.relay_athlete' ) . 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_relay_swimmer
{ u: <user.email>, t: <auth_token>,
mrr: <MRR_id>, o: <relay_order>, s: <swimmer_id>,
time: <incremental_timing_text>, r: <reaction_timing_text> }
POST #update_relay_swimmer { u : <user . email > t : <auth_token > mrr : <MRR_id > o : <relay_order > s : <swimmer_id > time : <incremental_timing_text > r : <reaction_timing_text > }
# 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)