<commit_before><?php
namespace Stakes\Controllers;

use Input;
use Stakes\Models\Account;
use Stakes\Models\Transaction;
use Stakes\Transformers\AccountTransformer;

class AccountsController extends ApiController {

    /**
	 * Display a listing of the resource.
	 * GET /accounts
	 *
	 * @return Response
	 */
    public function index() {
        $users = Account::get();
        return $this->respondWithCollection($users, new AccountTransformer);
    }

    /**
	 * Store a newly created resource in storage.
	 * POST /accounts
	 *
	 * @return Response
	 */
    public function store() {
        $account = new Account();
        $data    = Input::all();
        $account->fill($data);
        // attempt validation
        if ($account->isValid()) {
            $account->save();
            return $this->respondWithItem($account, new AccountTransformer);
        }

        return $this->errorWrongArgs();
    }

    /**
	 * Display the specified resource.
	 * GET /accounts/{account_id}
	 *
	 * @param int     $account_id
	 * @return Response
	 */
    public function show($account_id) {
        $account = Account::where('account_id', '=', $account_id)->first();
        if (is_null($account)) {
            return $this->errorNotFound();
        }
        return $this->respondWithItem($account, new AccountTransformer);
    }

    /**
	 * Update the specified resource in storage.
	 * PUT /accounts/{account_id}
	 *
	 * @param int     $account_id
	 * @return Response
	 */
    public function update($account_id) {
        //
    }

    /**
	 * Update the specified resource in storage.
	 * PUT /accounts/{account_id}/fund
	 *
	 * @param int     $account_id
	 * @return Response
	 */
    public function fund($account_id) {
        $account = Account::where('account_id', '=', $account_id)->first();
        if (is_null($account)) {
            return $this->errorNotFound();
        }
        $amount = Input::get('amount');
        if (is_null($amount) || !is_integer($amount) || $amount <= 0) {
            return $this->errorWrongArgs();
        }
        $account->balance += $amount;
        $account->save();
        Transaction::create([
                'account_id' => $account_id,
                'amount'     => $amount,
                'type'       => '+'
            ]);
        return $this->respondWithItem($account, new AccountTransformer);
    }

    /**
	 * Remove the specified resource from storage.
	 * DELETE /accounts/{account_id}
	 *
	 * @param int     $account_id<commit_msg>use the correct id<commit_after><?php
namespace Stakes\Controllers;

use Input;
use Stakes\Models\Account;
use Stakes\Models\Transaction;
use Stakes\Transformers\AccountTransformer;

class AccountsController extends ApiController {

    /**
	 * Display a listing of the resource.
	 * GET /accounts
	 *
	 * @return Response
	 */
    public function index() {
        $users = Account::get();
        return $this->respondWithCollection($users, new AccountTransformer);
    }

    /**
	 * Store a newly created resource in storage.
	 * POST /accounts
	 *
	 * @return Response
	 */
    public function store() {
        $account = new Account();
        $data    = Input::all();
        $account->fill($data);
        // attempt validation
        if ($account->isValid()) {
            $account->save();
            return $this->respondWithItem($account, new AccountTransformer);
        }

        return $this->errorWrongArgs();
    }

    /**
	 * Display the specified resource.
	 * GET /accounts/{account_id}
	 *
	 * @param int     $account_id
	 * @return Response
	 */
    public function show($account_id) {
        $account = Account::where('account_id', '=', $account_id)->first();
        if (is_null($account)) {
            return $this->errorNotFound();
        }
        return $this->respondWithItem($account, new AccountTransformer);
    }

    /**
	 * Update the specified resource in storage.
	 * PUT /accounts/{account_id}
	 *
	 * @param int     $account_id
	 * @return Response
	 */
    public function update($account_id) {
        //
    }

    /**
	 * Update the specified resource in storage.
	 * PUT /accounts/{account_id}/fund
	 *
	 * @param int     $account_id
	 * @return Response
	 */
    public function fund($account_id) {
        $account = Account::where('account_id', '=', $account_id)->first();
        if (is_null($account)) {
            return $this->errorNotFound();
        }
        $amount = Input::get('amount');
        if (is_null($amount) || !is_integer($amount) || $amount <= 0) {
            return $this->errorWrongArgs();
        }
        $account->balance += $amount;
        $account->save();
        Transaction::create([
                'account_id' => $account->id,
                'amount'     => $amount,
                'type'       => '+'
            ]);
        return $this->respondWithItem($account, new AccountTransformer);
    }

    /**
	 * Remove the specified resource from storage.
	 * DELETE /accounts/{account_id}
	 *
	 * @param int     $account_id
{'fraction_non_alphanumeric': 0.14081145584725538, 'fraction_numerical': 0.0003977724741447892, 'mean_word_length': 2.2592352559948155, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, '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': '3950256', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1379, 'n_words': 326}