feat: translation codes
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user