<commit_before>require 'doorkeeper/grape/helpers'

module API
  module V1
    class Customers < Grape::API
      helpers Doorkeeper::Grape::Helpers

      helpers do

        def current_customer
          @current_customer ||=
            Customer.find(doorkeeper_token.resource_owner_id)
        end
      end
      include API::V1::Defaults

      before do
        doorkeeper_authorize! :customer
      end

      # before_action -> { doorkeeper_authorize! :customer }, only: :index
      # before_action only: [:create, :update, :destroy] do
      #   doorkeeper_authorize! :admin
      # end

      resource :customers do

        get 'me' do
          current_customer
        end

        post 'me' do
          current_customer
        end

        desc "Get all customer's discount cards with barcodes"
        post 'full_info' do
          current_customer.as_json(include:
            { discount_cards: { include: :barcode } }).to_json
        end
      end

      private

      def current_customer
        @current_customer ||= Customer.find(doorkeeper_token.resource_owner_id)<commit_msg>Add customer update API method<commit_after>require 'doorkeeper/grape/helpers'

module API
  module V1
    class Customers < Grape::API
      helpers Doorkeeper::Grape::Helpers

      helpers do

        def current_customer
          @current_customer ||=
            Customer.find(doorkeeper_token.resource_owner_id)
        end
      end
      include API::V1::Defaults

      before do
        doorkeeper_authorize! :customer
      end

      # before_action -> { doorkeeper_authorize! :customer }, only: :index
      # before_action only: [:create, :update, :destroy] do
      #   doorkeeper_authorize! :admin
      # end

      resource :customers do

        get 'me' do
          current_customer
        end

        post 'me' do
          current_customer
        end

        desc "Get all customer's discount cards with barcodes"
        post 'full_info' do
          current_customer.as_json(include:
            { discount_cards: { include: :barcode } }).to_json
        end

        desc "Update current customer's info"
        put 'update' do
          current_customer.first_name ||= params[:first_name]
          current_customer.last_name ||= params[:last_name]
          current_customer.country ||= params[:country]
          current_customer.city ||= params[:city]
          current_customer.phone_number ||= params[:phone_number]
          current_customer.password ||= params[:password]
          current_customer.save!
        end
      end

      private

      def current_customer
        @current_customer ||= Customer.find(doorkeeper_token.resource_owner_id)
{'fraction_non_alphanumeric': 0.07835128109914594, 'fraction_numerical': 0.0014853323431117712, 'mean_word_length': 2.2109654350417163, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5089767', 'n_tokens_mistral': 753, 'n_tokens_neox': 723, 'n_words': 177}