feat: translation codes
This commit is contained in:
@@ -25,7 +25,7 @@ class ReviewIdentityVerification
|
||||
abort_if(
|
||||
$status === IdentityVerificationStatus::REJECTED && blank($rejectionReason),
|
||||
422,
|
||||
__('api.certification.rejection_reason_required'),
|
||||
'CERTIFICATION_REJECTION_REASON_REQUIRED',
|
||||
);
|
||||
|
||||
$reviewedRequest = DB::transaction(function () use (
|
||||
|
||||
@@ -25,7 +25,7 @@ class SubmitIdentityVerification
|
||||
$existingRequest = $user->identityVerificationRequest()->first();
|
||||
|
||||
if ($existingRequest?->status === IdentityVerificationStatus::PENDING) {
|
||||
throw new ConflictHttpException(__('api.certification.already_pending'));
|
||||
throw new ConflictHttpException('CERTIFICATION_ALREADY_PENDING');
|
||||
}
|
||||
|
||||
$disk = (string) config('billing.identity_verification.disk', 'identity_documents');
|
||||
|
||||
@@ -24,9 +24,9 @@ class DeviceTokenController extends Controller
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'message' => $deviceToken->wasRecentlyCreated
|
||||
? __('api.device_tokens.created')
|
||||
: __('api.device_tokens.updated'),
|
||||
'code' => $deviceToken->wasRecentlyCreated
|
||||
? 'DEVICE_TOKEN_CREATED'
|
||||
: 'DEVICE_TOKEN_UPDATED',
|
||||
'deviceToken' => [
|
||||
'id' => $deviceToken->id,
|
||||
'expoPushToken' => $deviceToken->expo_push_token,
|
||||
@@ -40,7 +40,7 @@ class DeviceTokenController extends Controller
|
||||
auth()->user()->notify(new TestNotification);
|
||||
|
||||
return response()->json([
|
||||
'message' => __('api.device_tokens.notification_sent'),
|
||||
'code' => 'TEST_NOTIFICATION_SENT',
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class FollowController extends Controller
|
||||
|
||||
if ($authUser->id === $user->id) {
|
||||
return response()->json([
|
||||
'message' => __('api.follows.cannot_follow_self'),
|
||||
'code' => 'CANNOT_FOLLOW_SELF',
|
||||
], 422);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class FollowController extends Controller
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => __('api.follows.followed'),
|
||||
'code' => 'USER_FOLLOWED',
|
||||
'status' => $status,
|
||||
]);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ class FollowController extends Controller
|
||||
$request->user()->following()->detach($user->id);
|
||||
|
||||
return response()->json([
|
||||
'message' => __('api.follows.unfollowed'),
|
||||
'code' => 'USER_UNFOLLOWED',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class FollowController extends Controller
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => $updated ? __('api.follows.accepted') : __('api.follows.not_found'),
|
||||
'code' => $updated ? 'FOLLOW_REQUEST_ACCEPTED' : 'FOLLOW_REQUEST_NOT_FOUND',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class FollowController extends Controller
|
||||
$detached = $request->user()->followers()->detach($user->id);
|
||||
|
||||
return response()->json([
|
||||
'message' => $detached ? __('api.follows.rejected') : __('api.follows.not_found'),
|
||||
'code' => $detached ? 'FOLLOW_REQUEST_REJECTED' : 'FOLLOW_REQUEST_NOT_FOUND',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class LegalDocumentController extends Controller
|
||||
{
|
||||
$document = LegalDocument::publicForSlug($slug);
|
||||
|
||||
abort_if(! $document, 404, __('api.legal_documents.not_found'));
|
||||
abort_if(! $document, 404, 'LEGAL_DOCUMENT_NOT_FOUND');
|
||||
|
||||
return new LegalDocumentResource($document);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class MealImageAnalysisController extends Controller
|
||||
|
||||
if (! $user->canAnalyzeMeals()) {
|
||||
return response()->json([
|
||||
'message' => __('api.meal_image_analysis.subscription_required'),
|
||||
'code' => 'MEAL_ANALYSIS_SUBSCRIPTION_REQUIRED',
|
||||
], 402);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ class MealImageAnalysisController extends Controller
|
||||
);
|
||||
|
||||
return response()->json([
|
||||
'message' => __('api.meal_image_analysis.failed'),
|
||||
'code' => 'MEAL_ANALYSIS_FAILED',
|
||||
], 502);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ class NotificationController extends Controller
|
||||
'data' => [
|
||||
'updated' => $updated,
|
||||
],
|
||||
'message' => __('api.notifications.all_read'),
|
||||
'code' => 'NOTIFICATIONS_MARKED_AS_READ',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ class NotificationPreferenceController extends Controller
|
||||
|
||||
return response()->json([
|
||||
'data' => $this->preferences($request),
|
||||
'message' => __('api.notifications.preferences_updated'),
|
||||
'code' => 'NOTIFICATION_PREFERENCES_UPDATED',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class PostReviewsController extends Controller
|
||||
->where('user_id', $userId)
|
||||
->exists(),
|
||||
409,
|
||||
__('api.post_reviews.already_exists')
|
||||
'MEAL_REVIEW_ALREADY_EXISTS'
|
||||
);
|
||||
|
||||
$postReview = PostReviews::create([
|
||||
|
||||
@@ -26,7 +26,7 @@ class ReportController extends Controller
|
||||
);
|
||||
|
||||
return (new ReportResource($report))
|
||||
->additional(['message' => __('api.reports.created')])
|
||||
->additional(['code' => 'REPORT_CREATED'])
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
@@ -44,7 +44,7 @@ class ReportController extends Controller
|
||||
);
|
||||
|
||||
return (new ReportResource($report))
|
||||
->additional(['message' => __('api.reports.created')])
|
||||
->additional(['code' => 'REPORT_CREATED'])
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class ReportController extends Controller
|
||||
);
|
||||
|
||||
return (new ReportResource($report))
|
||||
->additional(['message' => __('api.reports.created')])
|
||||
->additional(['code' => 'REPORT_CREATED'])
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
@@ -51,13 +51,13 @@ class StravaController extends Controller
|
||||
|
||||
if (! is_array($state) || $state['user_id'] !== $request->user()->getKey()) {
|
||||
return response()->json([
|
||||
'message' => __('api.strava.state_expired'),
|
||||
'code' => 'STRAVA_STATE_EXPIRED',
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (isset($data['error'])) {
|
||||
return response()->json([
|
||||
'message' => __('api.strava.refused'),
|
||||
'code' => 'STRAVA_AUTHORIZATION_REFUSED',
|
||||
], 422);
|
||||
}
|
||||
|
||||
@@ -115,14 +115,14 @@ class StravaController extends Controller
|
||||
report($exception);
|
||||
|
||||
return response()->json([
|
||||
'message' => __('api.strava.disconnect_failed'),
|
||||
'code' => 'STRAVA_DISCONNECT_FAILED',
|
||||
], 502);
|
||||
}
|
||||
} catch (ConnectionException $exception) {
|
||||
report($exception);
|
||||
|
||||
return response()->json([
|
||||
'message' => __('api.strava.disconnect_failed'),
|
||||
'code' => 'STRAVA_DISCONNECT_FAILED',
|
||||
], 502);
|
||||
}
|
||||
|
||||
@@ -137,13 +137,13 @@ class StravaController extends Controller
|
||||
|
||||
if (! $connection) {
|
||||
return response()->json([
|
||||
'message' => __('api.strava.missing_connection'),
|
||||
'code' => 'STRAVA_CONNECTION_MISSING',
|
||||
], 422);
|
||||
}
|
||||
|
||||
if (! $this->canReadActivities($connection->scopes ?? [])) {
|
||||
return response()->json([
|
||||
'message' => __('api.strava.missing_activity_scope'),
|
||||
'code' => 'STRAVA_ACTIVITY_SCOPE_MISSING',
|
||||
], 422);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,12 +27,12 @@ class UserBlockController extends Controller
|
||||
|
||||
public function store(Request $request, User $user, BlockUser $blockUser): JsonResponse
|
||||
{
|
||||
abort_if($request->user()->is($user), 422, __('api.blocks.cannot_block_self'));
|
||||
abort_if($request->user()->is($user), 422, 'CANNOT_BLOCK_SELF');
|
||||
|
||||
$blockUser->execute($request->user(), $user);
|
||||
|
||||
return response()->json([
|
||||
'message' => __('api.blocks.blocked'),
|
||||
'code' => 'USER_BLOCKED',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class EnsureAccountIsNotSuspended
|
||||
{
|
||||
if ($request->user()?->isSuspended()) {
|
||||
return response()->json([
|
||||
'message' => __('api.auth.suspended'),
|
||||
'code' => 'ACCOUNT_SUSPENDED',
|
||||
], 403);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class EnsureEmailIsVerified
|
||||
($request->user() instanceof MustVerifyEmail &&
|
||||
! $request->user()->hasVerifiedEmail())) {
|
||||
return $request->expectsJson()
|
||||
? abort(403, __('api.auth.email_not_verified'))
|
||||
? abort(403, 'EMAIL_NOT_VERIFIED')
|
||||
: Redirect::guest(URL::route($redirectToRoute ?: 'verification.notice'));
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ class LegalDocumentResource extends JsonResource
|
||||
'id' => $this->id,
|
||||
'slug' => $this->slug,
|
||||
'type' => $this->type?->value,
|
||||
'typeLabel' => $this->type?->getLabel(),
|
||||
'version' => $this->version,
|
||||
'title' => $this->title,
|
||||
'content' => $this->content,
|
||||
|
||||
@@ -17,10 +17,8 @@ class ReportResource extends JsonResource
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'reason' => $this->reason,
|
||||
'reasonLabel' => $this->reason?->getLabel(),
|
||||
'details' => $this->details,
|
||||
'status' => $this->status,
|
||||
'statusLabel' => $this->status?->getLabel(),
|
||||
'reportableType' => $this->reportableType(),
|
||||
'reportableId' => $this->reportable_id,
|
||||
'moderationCaseId' => $this->moderation_case_id,
|
||||
|
||||
@@ -43,7 +43,7 @@ class ContentModerationService
|
||||
$apiKey = trim((string) config('moderation.content.openai_key'));
|
||||
|
||||
if ($apiKey === '') {
|
||||
throw new HttpException(503, __('api.moderation.unavailable'));
|
||||
throw new HttpException(503, 'CONTENT_MODERATION_UNAVAILABLE');
|
||||
}
|
||||
|
||||
$input = [];
|
||||
@@ -80,7 +80,7 @@ class ContentModerationService
|
||||
} catch (Throwable $exception) {
|
||||
report($exception);
|
||||
|
||||
throw new HttpException(503, __('api.moderation.unavailable'), $exception);
|
||||
throw new HttpException(503, 'CONTENT_MODERATION_UNAVAILABLE', $exception);
|
||||
}
|
||||
|
||||
if (collect($response->json('results', []))->contains(
|
||||
@@ -107,7 +107,7 @@ class ContentModerationService
|
||||
$contents = file_get_contents($image->getRealPath());
|
||||
|
||||
if ($contents === false) {
|
||||
throw new HttpException(503, __('api.moderation.unavailable'));
|
||||
throw new HttpException(503, 'CONTENT_MODERATION_UNAVAILABLE');
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
@@ -126,7 +126,7 @@ class ContentModerationService
|
||||
private function rejectContent(): never
|
||||
{
|
||||
throw ValidationException::withMessages([
|
||||
'content' => [__('api.moderation.rejected')],
|
||||
'content' => ['CONTENT_MODERATION_REJECTED'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class ModerationReportService
|
||||
->where('reportable_id', $reportable->getKey())
|
||||
->exists(),
|
||||
409,
|
||||
__('api.reports.already_exists'),
|
||||
'REPORT_ALREADY_EXISTS',
|
||||
);
|
||||
|
||||
$report = Report::create([
|
||||
@@ -62,7 +62,7 @@ class ModerationReportService
|
||||
});
|
||||
} catch (QueryException $exception) {
|
||||
if ($this->isDuplicateReportException($exception)) {
|
||||
abort(409, __('api.reports.already_exists'));
|
||||
abort(409, 'REPORT_ALREADY_EXISTS');
|
||||
}
|
||||
|
||||
throw $exception;
|
||||
@@ -128,19 +128,19 @@ class ModerationReportService
|
||||
abort_if(
|
||||
$reportable instanceof User && $reportable->is($reporter),
|
||||
422,
|
||||
__('api.reports.cannot_report_self'),
|
||||
'CANNOT_REPORT_SELF',
|
||||
);
|
||||
|
||||
abort_if(
|
||||
$reportable instanceof MealPosts && $reportable->user_id === $reporter->getKey(),
|
||||
422,
|
||||
__('api.reports.cannot_report_own_meal'),
|
||||
'CANNOT_REPORT_OWN_MEAL',
|
||||
);
|
||||
|
||||
abort_if(
|
||||
$reportable instanceof PostReviews && $reportable->user_id === $reporter->getKey(),
|
||||
422,
|
||||
__('api.reports.cannot_report_own_review'),
|
||||
'CANNOT_REPORT_OWN_REVIEW',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user