<commit_before><?php

namespace Rogue\Http\Controllers\Three;

use Rogue\Models\Post;
use Rogue\Repositories\Three\PostRepository;
use Rogue\Http\Requests\ReviewsApiRequest;
use Rogue\Http\Transformers\Three\PostTransformer;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Auth\Access\AuthorizationException;

class ReviewsController extends ApiController
{
    /**
     * The post service instance.
     *
     * @var Rogue\Repositories\ThreePostRepository
     */
    protected $post;

    /**
     * @var \Rogue\Http\Transformers\Three\PostTransformer
     */
    protected $transformer;

    /**
     * Create a controller instance.
     *
     * @param  PostContract $posts
     * @return void
     */
    public function __construct(PostRepository $post)
    {
        $this->middleware('api');

        $this->post = $post;
        $this->transformer = new PostTransformer;
    }

    /**
     * Update a post(s)'s status when reviewed.
     *
     * @param Rogue\Http\Requests\ReviewsApiRequest $request
     *
     * @return \Illuminate\Http\Response
     */
    public function reviews(ReviewsApiRequest $request)
    {
        $validatedRequest = $request->validate([
            'post_id' => 'required',
            'status' => 'in:pending,accepted,rejected',
            // 'admin_northstar_id' => 'nullable|integer',
        ]);

        // Only allow an admin to review the post.
        if (token()->role() === 'admin') {
            // $review = $request->all();
            $post = Post::where('id', $validatedRequest['post_id'])->first();
            $validatedRequest['signup_id'] = $post->signup_id;
            $validatedRequest['northstar_id'] = $post->northstar_id;
            $validatedRequest['old_status'] = $post->status;

            // Append admin's ID to the request for the "reviews" service.
            $validatedRequest['admin_northstar_id'] = auth()->id();
            $reviewedPost = $this->post->reviews($review);
            $reviewedPostCode = $this->code($reviewedPost);

            if (isset($reviewedPost)) {
                info('post_reviewed', [
                    'id' => $reviewedPost->id,
                    'admin_northstar_id' => $review['admin_northstar_id'],
                    'status' => $reviewedPost->status,
                ]);

                return $this->item($reviewedPost, $reviewedPostCode);<commit_msg>v3 reviews endpoint working<commit_after><?php

namespace Rogue\Http\Controllers\Three;

use Rogue\Models\Post;
use Illuminate\Http\Request;
use Rogue\Repositories\Three\PostRepository;
// use Rogue\Http\Requests\ReviewsApiRequest;
use Rogue\Http\Controllers\Api\ApiController;
use Rogue\Http\Transformers\Three\PostTransformer;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Auth\Access\AuthorizationException;

class ReviewsController extends ApiController
{
    /**
     * The post service instance.
     *
     * @var Rogue\Repositories\ThreePostRepository
     */
    protected $post;

    /**
     * @var \Rogue\Http\Transformers\Three\PostTransformer
     */
    protected $transformer;

    /**
     * Create a controller instance.
     *
     * @param  PostContract $posts
     * @return void
     */
    public function __construct(PostRepository $post)
    {
        $this->post = $post;
        $this->transformer = new PostTransformer;

        $this->middleware('auth:api');
    }

    /**
     * Update a post(s)'s status when reviewed.
     *
     * @param Request $request
     *
     * @return \Illuminate\Http\Response
     */
    public function reviews(Request $request)
    {
        $validatedRequest = $request->validate([
            'post_id' => 'required',
            'status' => 'in:pending,accepted,rejected',
        ]);

        // Only allow an admin to review the post.
        if (token()->role() === 'admin') {
            $post = Post::where('id', $validatedRequest['post_id'])->first();
            $validatedRequest['signup_id'] = $post->signup_id;
            $validatedRequest['northstar_id'] = $post->northstar_id;
            $validatedRequest['old_status'] = $post->status;

            // Append admin's ID to the request for the "reviews" service.
            $validatedRequest['admin_northstar_id'] = auth()->id();
            $reviewedPost = $this->post->reviews($validatedRequest);
            $reviewedPostCode = $this->code($reviewedPost);

            if (isset($reviewedPost)) {
                info('post_reviewed', [
                    'id' => $reviewedPost->id,
                    'admin_northstar_id' => $validatedRequest['admin_northstar_id'],
                    'status' => $reviewedPost->status,
                ]);

                return $this->item($reviewedPost, $reviewedPostCode);
{'fraction_non_alphanumeric': 0.13453478625314333, 'fraction_numerical': 0.00020955574182732607, 'mean_word_length': 2.4313443565780015, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, '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': '127395', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1358, 'n_words': 248}