<commit_before>%%%-------------------------------------------------------------------
%%% File    : app_controller.erl
%%% Author  : <NAME>
%%% Description : 
%%%
%%% Created :  Fri Nov 13 11:43:43 PST 2009
%%%-------------------------------------------------------------------

-module (apps_controller).
-include ("beehive.hrl").
-include ("http.hrl").
-export ([get/1, post/2, put/2, delete/2]).

get([]) -> 
  All = apps:all(),
  {struct, [{
    "apps",
    lists:map(fun(A) ->
      Details = compile_app_details(A),
      {struct, ?BINIFY(Details)}
    end, All)
  }]}.

post(["new"], Data) ->
  case auth_utils:get_authorized_user(Data) of
    false -> 
      {struct, [{"error", misc_utils:to_bin("No user defined or invalid token")}]};
    ReqUser ->
      case apps:create(Data) of
        {ok, App} when is_record(App, app) -> 
          user_apps:create(ReqUser, App),
          {struct, ?BINIFY([{"app", misc_utils:to_bin(App#app.name)}])};
        _ -> "There was an error adding bee\n"
      end
  end;<commit_msg>Added endpoint route in apps/Name<commit_after>%%%-------------------------------------------------------------------
%%% File    : app_controller.erl
%%% Author  : <NAME>
%%% Description : 
%%%
%%% Created :  Fri Nov 13 11:43:43 PST 2009
%%%-------------------------------------------------------------------

-module (apps_controller).
-include ("beehive.hrl").
-include ("http.hrl").
-export ([get/1, post/2, put/2, delete/2]).


get([Name]) ->
  case apps:find_by_name(Name) of
    [] -> {struct, [{"error", ?BINIFY("App not found")}]};
    App ->
      {struct, [{
        Name, ?BINIFY([
          {"name", App#app.name},
          {"url", App#app.url},
          {"routing_param", App#app.routing_param},
          {"owners", lists:map(fun(Owner) -> Owner#user.email end, user_apps:get_owners(App))},
          {"updated_at", App#app.updated_at},
          {"bee_picker", App#app.bee_picker},
          {"min_instances", App#app.min_instances},
          {"max_instances", App#app.max_instances},
          {"timeout", App#app.timeout},
          {"sticky", App#app.sticky},
          {"latest_sha", App#app.sha}
        ])
      }]}
  end;
get(_) -> 
  All = apps:all(),
  {struct, [{
    "apps",
    lists:map(fun(A) ->
      Details = compile_app_details(A),
      {struct, ?BINIFY(Details)}
    end, All)
  }]}.

post(["new"], Data) ->
  case auth_utils:get_authorized_user(Data) of
    false -> 
      {struct, [{"error", misc_utils:to_bin("No user defined or invalid token")}]};
    ReqUser ->
      case apps:create(Data) of
        {ok, App} when is_record(App, app) -> 
          user_apps:create(ReqUser, App),
          {struct, ?BINIFY([{"app", misc_utils:to_bin(App#app.name)}])};
        _ -> "There was an error adding bee\n"
      end
  end;
{'fraction_non_alphanumeric': 0.27354099534550663, 'fraction_numerical': 0.011457214464733263, 'mean_word_length': 1.9755058572949946, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '3830501', 'n_tokens_mistral': 949, 'n_tokens_neox': 901, 'n_words': 186}