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:
2026-01-22 20:49:29 +09:00
parent 57229b3cc6
commit f85e070913
3 changed files with 134 additions and 1 deletions

View File

@@ -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;
});
}
}