<commit_before>class Api::V1::MatchesController < ApplicationController
    # before_action :current_user?
    
    def show
        user = User.find(params[:id])
        if user
            couple = user.couples.where.not(state: Couple::COUPLE_STATE_FINISH).first
            if couple
                response = {"state" => couple.state,
                            "result"=> couple.result,
                         "distance" => couple.distance,
                             "user" => {"state" => user.state},
                     "matched_user" => couple.matcher.to_hash}
                render json: response, statue: 200
            else
                response = {"user" => {"state" => user.state}}
                render json: response, status: 200
            end
        else
            render json: "", status: 404
        end
    end
    
    def update
        user = User.find(params[:id])
        if !user
            error = {"error_message" => I18n.t('user_not_exist')}
            render json: error, statue: 404
        end
        
        if user.update_attributes(location_params)
            render json: "", statue: 200
        else
            puts "#{Time.now}, error: #{user.errors.full_messages}"
            render json: user.errors.full_messages, statue: 500
        end
    end
    
    def match
        user = User.find(params[:id])
        if user
            case params[:match][:event].to_i
            when User::EVENT_STOP
                user.stop
                render json: "", statue: 200
            when User::EVENT_START_MATCHING
                if user.update_attribute(:match_distance, params[:match][:distance])
                    user.start_matching
                    render json: "", statue: 200
                else
                    puts "#{Time.now}, error: #{user.errors.full_messages}"
                    render json: "", statue: 500
                end
            when User::EVENT_ACCEPT
                matched_user = User.find(params[:match][:matched_user_id])
                if matched_user
                    user.accept(matched_user)
                    render json: "", statue: 200
                else
                    render json: "", statue: 404
                end
            when User::EVENT_REJECT
                matched_user = User.find(params[:match][:matched_user_id])<commit_msg>fix user login by wechat or weibo cannot update location<commit_after>class Api::V1::MatchesController < ApplicationController
    before_action :current_user?
    
    def show
        user = User.find(params[:id])
        if user
            couple = user.couples.where.not(state: Couple::COUPLE_STATE_FINISH).first
            if couple
                response = {"state" => couple.state,
                            "result"=> couple.result,
                         "distance" => couple.distance,
                             "user" => {"state" => user.state},
                     "matched_user" => couple.matcher.to_hash}
                render json: response, statue: 200
            else
                response = {"user" => {"state" => user.state}}
                render json: response, status: 200
            end
        else
            render json: "", status: 404
        end
    end
    
    def update
        user = User.find(params[:id])
        if !user
            error = {"error_message" => I18n.t('user_not_exist')}
            render json: error, statue: 404
        end
        
        if (user.update_attribute(:latitude, params[:location][:latitude]) \
            && user.update_attribute(:longitude, params[:location][:longitude]))
            render json: "", statue: 200
        else
            Rails.logger.debug { "#{Time.now}, error: #{user.errors.full_messages}" }
            render json: user.errors.full_messages, statue: 500
        end
    end
    
    def match
        user = User.find(params[:id])
        if user
            case params[:match][:event].to_i
            when User::EVENT_STOP
                user.stop
                render json: "", statue: 200
            when User::EVENT_START_MATCHING
                if user.update_attribute(:match_distance, params[:match][:distance])
                    user.start_matching
                    render json: "", statue: 200
                else
                    puts "#{Time.now}, error: #{user.errors.full_messages}"
                    render json: "", statue: 500
                end
            when User::EVENT_ACCEPT
                matched_user = User.find(params[:match][:matched_user_id])
                if matched_user
                    user.accept(matched_user)
                    render json: "", statue: 200
                else
                    render json: "", statue: 404
                end
            when User::EVENT_REJECT
                matched_user = User.find(params[:match][:matched_user_id])
{'fraction_non_alphanumeric': 0.10216150081566068, 'fraction_numerical': 0.01468189233278956, 'mean_word_length': 1.4451645064805583, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, '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': '7310495', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1207, 'n_words': 292}