module Api module V1 class WebIdCardsController < ApplicationController def member_card pb_entity_key = params[:id] layout = params[:layout] member = Member.find_by(pb_entity_key: pb_entity_key) if member.present? member_card = IdCardPrinterService::CardsGenerator.new(member.member_key, layout).call send_data member_card.to_pdf, filename: "#{member.name.gsub(", ", "_")}_digital_card_#{Date.today}.pdf", type: "application/pdf", disposition: 'inline' else render json: { error: "Member not found" }, status: :not_found end end def employer_cards pl_plan_key = params[:id] employer = Employer.find_by(pl_plan_key: pl_plan_key) if employer.present? employer_cards = IdCardPrinterService::CardsGenerator.new(employer.employer_member_keys, "FullPageCard", true).call employer_cards.rewind send_data employer_cards.sysread, filename: "#{employer.name.parameterize(separator: "_")}_full_page_cards_#{Date.today}.zip", type: 'application/zip', disposition: 'inline' else render json: { error: "Employer not found" }, status: :not_found end end end end end