Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
AddOnsAdminController
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 yearlyRoleplay
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace App\Http\Controllers\v2\Admin;
4
5use App\Http\Controllers\Controller;
6use App\Http\Models\AddOns;
7use App\Http\Services\AddOnsService;
8use Illuminate\Http\JsonResponse;
9
10/**
11 * Admin add-on read endpoints for the Client Management Center. Currently
12 * exposes the list of yearly RolePlay addons that a Vengreso super admin can
13 * assign company-wide.
14 */
15class AddOnsAdminController extends Controller
16{
17    public function __construct(
18        private readonly AddOnsService $addOnsService,
19    ) {}
20
21    /**
22     * List all yearly RolePlay addons (excludes the freemium "beginner"
23     * identifier and any monthly variants). Sorted by price ascending.
24     *
25     * @response 200 {
26     *   "result": {
27     *     "status": "success",
28     *     "data": [
29     *       {
30     *         "id": "...",
31     *         "identifier": "roleplay-advanced-yearly",
32     *         "name": "Advanced",
33     *         "description": "RolePlay Advanced Yearly",
34     *         "price": 499.99,
35     *         "recurrency_type": "yearly",
36     *         "priority": 3,
37     *         "features": {"project_credits": 10, "monthly_total_time_credits": 5000, "monthly_roleplay_credits": 50}
38     *       }
39     *     ]
40     *   }
41     * }
42     */
43    public function yearlyRoleplay(): JsonResponse
44    {
45        $addons = $this->addOnsService
46            ->getYearlyForProduct('RolePlay', ['roleplay-beginner'])
47            ->map(fn (AddOns $a) => [
48                'id' => $a->id,
49                'identifier' => $a->identifier,
50                'name' => $a->name,
51                'description' => $a->description,
52                'price' => $a->price,
53                'recurrency_type' => $a->recurrency_type,
54                'priority' => $a->priority,
55                'features' => $a->features,
56            ])
57            ->values();
58
59        return response()->json([
60            'status' => 'success',
61            'data' => $addons,
62        ]);
63    }
64}