refactor: refactor controllers, services, validation and introduce DTOs, FormRequests and domain exceptions
This commit is contained in:
@@ -36,12 +36,12 @@ class UserService implements UserServiceInterface
|
||||
public function sendThankcards(User $sender, string $receiverMsnv, int $amount): void
|
||||
{
|
||||
if ($sender->flag_send == config('constants.FLAG_SEND_DISABLED')) {
|
||||
throw new \RuntimeException(__('messages.error.no_send_permission'));
|
||||
throw new \App\Exceptions\ThankCardException(__('messages.error.no_send_permission'));
|
||||
}
|
||||
|
||||
$receiver = User::where('msnv', $receiverMsnv)->first();
|
||||
if (!$receiver || $receiver->status != config('constants.STATUS_ACTIVE')) {
|
||||
throw new \RuntimeException(__('messages.error.receiver_invalid'));
|
||||
throw new \App\Exceptions\ThankCardException(__('messages.error.receiver_invalid'));
|
||||
}
|
||||
|
||||
$startOfMonth = Carbon::now()->startOfMonth();
|
||||
@@ -53,7 +53,7 @@ class UserService implements UserServiceInterface
|
||||
->sum('sent');
|
||||
|
||||
if ($cardsSentToThisUserThisMonth + $amount > Administration::MAX_SEND_CARD_PER_MONTH) {
|
||||
throw new \RuntimeException(
|
||||
throw new \App\Exceptions\ThankCardException(
|
||||
__('messages.error.max_send_limit_template', [
|
||||
'max' => Administration::MAX_SEND_CARD_PER_MONTH,
|
||||
'sent' => $cardsSentToThisUserThisMonth
|
||||
@@ -62,7 +62,7 @@ class UserService implements UserServiceInterface
|
||||
}
|
||||
|
||||
if ($sender->card < $amount) {
|
||||
throw new \RuntimeException(__('messages.error.not_enough_cards'));
|
||||
throw new \App\Exceptions\ThankCardException(__('messages.error.not_enough_cards'));
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($sender, $receiverMsnv, $amount) {
|
||||
@@ -213,4 +213,19 @@ class UserService implements UserServiceInterface
|
||||
'currentUserRankItem' => $currentUserRankItem
|
||||
];
|
||||
}
|
||||
|
||||
public function updateProfile(User $user, ?\Illuminate\Http\UploadedFile $avatarFile, ?string $newPassword): void
|
||||
{
|
||||
if ($avatarFile) {
|
||||
$path = $avatarFile->store('avatars', 'public');
|
||||
$user->avatar = 'storage/' . $path;
|
||||
}
|
||||
|
||||
if ($newPassword) {
|
||||
$user->pass = md5($newPassword);
|
||||
$user->first_login = config('constants.FIRST_LOGIN_FALSE');
|
||||
}
|
||||
|
||||
$user->save();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user