feat: 前端分離+功能api化

1. 新增資產管理CRUD、googleOAuth登入
2. 更改原記帳controller
This commit is contained in:
2026-06-25 14:19:07 +08:00
parent 7bb931c97b
commit 85972f950c
70 changed files with 4754 additions and 1520 deletions

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\CategoryRule;
use Illuminate\Http\Request;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class CategoryRuleController extends Controller
{
use AuthorizesRequests;
/**
* 新增自動分類規則
* POST /api/category-rules
*/
public function store(Request $request)
{
$validated = $request->validate([
'keyword' => 'required|string|max:255',
'category_id' => 'required|exists:categories,id',
]);
$rule = CategoryRule::create([
...$validated,
'user_id' => $request->user()->id,
]);
// 🟢 核心優化:必須預先載入 category 關聯,否則前端拿到這筆規則物件時,會無法渲染它的分類標籤
$rule->load('category');
return response()->json($rule, 201);
}
/**
* 刪除自動分類規則
* DELETE /api/category-rules/{categoryRule}
*/
public function destroy(CategoryRule $categoryRule)
{
if ($categoryRule->user_id !== $request->user()->id) {
return response()->json(['error' => '未經授權'], 403);
}
$categoryRule->delete();
return response()->json(['message' => '自動分類規則刪除成功']);
}
}