feat(API): 카드 거래 등록/수정/삭제 API 추가
- CardTransactionService: store, update, destroy 메서드 추가
- CardTransactionController: store, update, destroy 메서드 추가
- routes/api.php: POST, PUT/{id}, DELETE/{id} 라우트 추가
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -89,4 +89,51 @@ public function show(int $id): JsonResponse
|
||||
return $transaction;
|
||||
}, __('message.fetched'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 카드 거래 등록
|
||||
*/
|
||||
public function store(Request $request): JsonResponse
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request) {
|
||||
$validated = $request->validate([
|
||||
'card_id' => 'nullable|integer|exists:cards,id',
|
||||
'used_at' => 'required|date',
|
||||
'merchant_name' => 'required|string|max:100',
|
||||
'amount' => 'required|numeric|min:0',
|
||||
'description' => 'nullable|string|max:500',
|
||||
'account_code' => 'nullable|string|max:20',
|
||||
]);
|
||||
|
||||
return $this->service->store($validated);
|
||||
}, __('message.created'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 카드 거래 수정
|
||||
*/
|
||||
public function update(Request $request, int $id): JsonResponse
|
||||
{
|
||||
return ApiResponse::handle(function () use ($request, $id) {
|
||||
$validated = $request->validate([
|
||||
'used_at' => 'nullable|date',
|
||||
'merchant_name' => 'nullable|string|max:100',
|
||||
'amount' => 'nullable|numeric|min:0',
|
||||
'description' => 'nullable|string|max:500',
|
||||
'account_code' => 'nullable|string|max:20',
|
||||
]);
|
||||
|
||||
return $this->service->update($id, $validated);
|
||||
}, __('message.updated'));
|
||||
}
|
||||
|
||||
/**
|
||||
* 카드 거래 삭제
|
||||
*/
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
return ApiResponse::handle(function () use ($id) {
|
||||
return $this->service->destroy($id);
|
||||
}, __('message.deleted'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,4 +180,87 @@ public function show(int $id): ?Withdrawal
|
||||
->with(['card', 'card.assignedUser', 'creator'])
|
||||
->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 카드 거래 등록
|
||||
*/
|
||||
public function store(array $data): Withdrawal
|
||||
{
|
||||
$tenantId = $this->tenantId();
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
return DB::transaction(function () use ($data, $tenantId, $userId) {
|
||||
$withdrawal = new Withdrawal;
|
||||
$withdrawal->tenant_id = $tenantId;
|
||||
$withdrawal->card_id = $data['card_id'] ?? null;
|
||||
$withdrawal->used_at = $data['used_at'] ?? null;
|
||||
$withdrawal->withdrawal_date = isset($data['used_at']) ? date('Y-m-d', strtotime($data['used_at'])) : now()->toDateString();
|
||||
$withdrawal->merchant_name = $data['merchant_name'] ?? null;
|
||||
$withdrawal->amount = $data['amount'];
|
||||
$withdrawal->payment_method = 'card';
|
||||
$withdrawal->account_code = $data['account_code'] ?? null;
|
||||
$withdrawal->description = $data['description'] ?? null;
|
||||
$withdrawal->created_by = $userId;
|
||||
$withdrawal->updated_by = $userId;
|
||||
$withdrawal->save();
|
||||
|
||||
return $withdrawal->load(['card', 'card.assignedUser', 'creator']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 카드 거래 수정
|
||||
*/
|
||||
public function update(int $id, array $data): Withdrawal
|
||||
{
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
return DB::transaction(function () use ($id, $data, $userId) {
|
||||
$withdrawal = Withdrawal::query()
|
||||
->where('payment_method', 'card')
|
||||
->findOrFail($id);
|
||||
|
||||
if (isset($data['used_at'])) {
|
||||
$withdrawal->used_at = $data['used_at'];
|
||||
$withdrawal->withdrawal_date = date('Y-m-d', strtotime($data['used_at']));
|
||||
}
|
||||
if (array_key_exists('merchant_name', $data)) {
|
||||
$withdrawal->merchant_name = $data['merchant_name'];
|
||||
}
|
||||
if (isset($data['amount'])) {
|
||||
$withdrawal->amount = $data['amount'];
|
||||
}
|
||||
if (array_key_exists('account_code', $data)) {
|
||||
$withdrawal->account_code = $data['account_code'];
|
||||
}
|
||||
if (array_key_exists('description', $data)) {
|
||||
$withdrawal->description = $data['description'];
|
||||
}
|
||||
|
||||
$withdrawal->updated_by = $userId;
|
||||
$withdrawal->save();
|
||||
|
||||
return $withdrawal->fresh(['card', 'card.assignedUser', 'creator']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 카드 거래 삭제
|
||||
*/
|
||||
public function destroy(int $id): bool
|
||||
{
|
||||
$userId = $this->apiUserId();
|
||||
|
||||
return DB::transaction(function () use ($id, $userId) {
|
||||
$withdrawal = Withdrawal::query()
|
||||
->where('payment_method', 'card')
|
||||
->findOrFail($id);
|
||||
|
||||
$withdrawal->deleted_by = $userId;
|
||||
$withdrawal->save();
|
||||
$withdrawal->delete();
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -590,12 +590,15 @@
|
||||
Route::get('/{clientId}', [VendorLedgerController::class, 'show'])->whereNumber('clientId')->name('v1.vendor-ledger.show');
|
||||
});
|
||||
|
||||
// Card Transaction API (카드 거래 조회)
|
||||
// Card Transaction API (카드 거래)
|
||||
Route::prefix('card-transactions')->group(function () {
|
||||
Route::get('', [CardTransactionController::class, 'index'])->name('v1.card-transactions.index');
|
||||
Route::get('/summary', [CardTransactionController::class, 'summary'])->name('v1.card-transactions.summary');
|
||||
Route::post('', [CardTransactionController::class, 'store'])->name('v1.card-transactions.store');
|
||||
Route::put('/bulk-update-account', [CardTransactionController::class, 'bulkUpdateAccountCode'])->name('v1.card-transactions.bulk-update-account');
|
||||
Route::get('/{id}', [CardTransactionController::class, 'show'])->whereNumber('id')->name('v1.card-transactions.show');
|
||||
Route::put('/{id}', [CardTransactionController::class, 'update'])->whereNumber('id')->name('v1.card-transactions.update');
|
||||
Route::delete('/{id}', [CardTransactionController::class, 'destroy'])->whereNumber('id')->name('v1.card-transactions.destroy');
|
||||
});
|
||||
|
||||
// Bank Transaction API (은행 거래 조회)
|
||||
|
||||
Reference in New Issue
Block a user