Deploy Ladill Mini / deploy (push) Successful in 40s
Adds /api/v1/mini account (settings, profile, change-password), wallet (balance + ledger, Paystack top-up) and support (Afia chat) endpoints. Account/profile/ password/top-up proxy to the central identity API via a CallsIdentityApi trait; notifications, wallet balance and support chat are served locally. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
112 lines
3.8 KiB
PHP
112 lines
3.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\Mini;
|
|
|
|
use App\Http\Controllers\Api\Concerns\CallsIdentityApi;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\QrSetting;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class AccountController extends Controller
|
|
{
|
|
use CallsIdentityApi;
|
|
|
|
public function settings(): JsonResponse
|
|
{
|
|
$account = ladill_account();
|
|
$settings = $account->getOrCreateQrSetting();
|
|
|
|
return response()->json([
|
|
'data' => [
|
|
'profile' => [
|
|
'name' => $account->name,
|
|
'email' => $account->email,
|
|
],
|
|
'notifications' => [
|
|
'notify_email' => $settings->notify_email ?: $account->email,
|
|
'product_updates' => (bool) ($settings->product_updates ?? true),
|
|
'notify_registrations' => (bool) ($settings->notify_registrations ?? true),
|
|
'notify_payouts' => (bool) ($settings->notify_payouts ?? true),
|
|
],
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function updateSettings(Request $request): JsonResponse
|
|
{
|
|
$account = ladill_account();
|
|
|
|
$data = $request->validate([
|
|
'notify_email' => ['nullable', 'email', 'max:255'],
|
|
'product_updates' => ['sometimes', 'boolean'],
|
|
'notify_registrations' => ['sometimes', 'boolean'],
|
|
'notify_payouts' => ['sometimes', 'boolean'],
|
|
]);
|
|
|
|
$settings = QrSetting::updateOrCreate(
|
|
['user_id' => $account->id],
|
|
[
|
|
'notify_email' => $data['notify_email'] ?? $account->email,
|
|
'product_updates' => $request->boolean('product_updates'),
|
|
'notify_registrations' => $request->boolean('notify_registrations'),
|
|
'notify_payouts' => $request->boolean('notify_payouts'),
|
|
],
|
|
);
|
|
|
|
return response()->json([
|
|
'data' => [
|
|
'notify_email' => $settings->notify_email,
|
|
'product_updates' => (bool) $settings->product_updates,
|
|
'notify_registrations' => (bool) $settings->notify_registrations,
|
|
'notify_payouts' => (bool) $settings->notify_payouts,
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function updateProfile(Request $request): JsonResponse
|
|
{
|
|
$account = ladill_account();
|
|
|
|
$data = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'phone_cc' => ['nullable', 'string', 'max:8'],
|
|
'phone' => ['nullable', 'string', 'max:32'],
|
|
]);
|
|
|
|
$response = $this->identitySend('PUT', '/api/identity/profile', array_merge(
|
|
['user' => $account->public_id],
|
|
$data,
|
|
));
|
|
$this->rethrowValidation($response, 'name');
|
|
|
|
if ($response->successful()) {
|
|
$account->update(['name' => $data['name']]);
|
|
}
|
|
|
|
return response()->json([
|
|
'data' => ['name' => $account->fresh()->name, 'email' => $account->email],
|
|
]);
|
|
}
|
|
|
|
public function changePassword(Request $request): JsonResponse
|
|
{
|
|
$account = ladill_account();
|
|
|
|
$request->validate([
|
|
'current_password' => ['required', 'string'],
|
|
'password' => ['required', 'string', 'min:8', 'confirmed'],
|
|
]);
|
|
|
|
$response = $this->identitySend('POST', '/api/identity/auth/change-password', [
|
|
'user' => $account->public_id,
|
|
'current_password' => $request->string('current_password'),
|
|
'password' => $request->string('password'),
|
|
'password_confirmation' => $request->string('password_confirmation'),
|
|
]);
|
|
$this->rethrowValidation($response, 'current_password');
|
|
|
|
return response()->json(['data' => ['message' => 'Password updated.']]);
|
|
}
|
|
}
|