<commit_before>get '/users' do
  validate_admin_privileges
  User.find(:all).to_json
end

get '/users/:id' do
  validate_admin_privileges
  id = params.delete("id")
  user = User.find_by_id(id)
  if user
    user.to_json
  else
    halt 404, [].to_json
  end
end

post '/users' do
  validate_admin_privileges
  id = params.delete("id")
  validate_user_params
  user = create_user_from_params
  user.to_json
end

put '/users/:id' do
  validate_admin_privileges
  id = params.delete("id")
  validate_user_params
  user = User.find_by_id(id)
  if user
    user = User.update(id, params)
  else
    params["_id"] = id
    user = create_user_from_params
  end
  user.to_json
end

delete '/users/:id' do
  validate_admin_privileges
  id = params.delete("id")
  user = User.find(id)
  user.destroy
  { "_id" => id }.to_json
end
<commit_msg>I prefer 'error' over 'halt' in this case.<commit_after>get '/users' do
  validate_admin_privileges
  User.find(:all).to_json
end

get '/users/:id' do
  validate_admin_privileges
  id = params.delete("id")
  user = User.find_by_id(id)
  if user
    user.to_json
  else
    error 404, [].to_json
  end
end

post '/users' do
  validate_admin_privileges
  id = params.delete("id")
  validate_user_params
  user = create_user_from_params
  user.to_json
end

put '/users/:id' do
  validate_admin_privileges
  id = params.delete("id")
  validate_user_params
  user = User.find_by_id(id)
  if user
    user = User.update(id, params)
  else
    params["_id"] = id
    user = create_user_from_params
  end
  user.to_json
end

delete '/users/:id' do
  validate_admin_privileges
  id = params.delete("id")
  user = User.find(id)
  user.destroy
  { "_id" => id }.to_json
end

{'fraction_non_alphanumeric': 0.11143867924528301, 'fraction_numerical': 0.003537735849056604, 'mean_word_length': 3.549597855227882, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2716417', 'n_tokens_mistral': 654, 'n_tokens_neox': 653, 'n_words': 145}