<commit_before>module Api
  module V1
    class NeedsController < JSONAPI::ResourceController
    	before_action :authenticate_user!, except: [:show, :index, :feed]
      def index
        if current_user.admin?
          needs = Need.all
        else
          needs = Need.where(user_id: current_user.id)
        end
        resources = needs.map { |need| NeedResource.new(need, nil) }
        json = JSONAPI::ResourceSerializer.new(NeedResource).serialize_to_hash(resources)
        render json: json
      end

      def create
        sparams = params['data']['attributes']
        start_time = sparams['start-time']
        end_time = sparams['end-time']
        user_id = current_user.id

        need = Need.create!(start_time: start_time, end_time: end_time, user_id: user_id)<commit_msg>moved index needs cogic to ngo_index<commit_after>module Api
  module V1
    class NeedsController < JSONAPI::ResourceController
    	before_action :authenticate_user!, except: [:show, :index, :feed]

      def ngo_index
        if current_user && current_user.admin?
          needs = Need.all
        else
          needs = Need.where(user_id: current_user.id)
        end
        resources = needs.map { |need| NeedResource.new(need, nil) }
        json = JSONAPI::ResourceSerializer.new(NeedResource).serialize_to_hash(resources)
        render json: json
      end


      def create
        sparams = params['data']['attributes']
        start_time = sparams['start-time']
        end_time = sparams['end-time']
        user_id = current_user.id

        need = Need.create!(start_time: start_time, end_time: end_time, user_id: user_id)
{'fraction_non_alphanumeric': 0.09884075655887736, 'fraction_numerical': 0.0012202562538133007, 'mean_word_length': 2.7442922374429224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '1072237', 'n_tokens_mistral': 499, 'n_tokens_neox': 489, 'n_words': 109}