register rfid tag with chip id

This commit is contained in:
Christophe Robillard 2026-01-28 16:37:17 +01:00
parent 71aaa32d15
commit 7fbc41d332

View file

@ -1,9 +1,10 @@
class RfidTagsController < ApplicationController
skip_forgery_protection
allow_unauthenticated_access
def create
identifier = params.expect(:identifier)
rfid_tag = RfidTag.find_or_initialize_by(identifier:)
rfid_tag_params = params.expect(rfid_tag: [ :chip_id, :identifier ])
rfid_tag = RfidTag.find_or_initialize_by(chip_id: rfid_tag_params[:chip_id], identifier: rfid_tag_params[:identifier])
if rfid_tag.new_record?
register rfid_tag
return
@ -15,6 +16,7 @@ class RfidTagsController < ApplicationController
private
def register(rfid_tag)
rfid_tag.user = RfidTag.where(chip_id: rfid_tag.chip_id).first&.user
rfid_tag.save!
head :created, code: :registered
end