feat:實作 Member Portal MVP 前端與後端整合
後端: - 新增 DivingOffer Model / DivingOfferController(列表+詳情 API,支援搜尋/篩選/分頁) - 修正 Google OAuth callback 改為 redirect 至前端(SocialAuthController) - 新增 config/cors.php 允許前端 origin - .gitignore 新增 frontend/ 排除規則 前端(frontend/): - Vue 3 + Vite + Tailwind CSS + Pinia + Vue Router - 頁面:首頁、課程列表、課程詳情、登入、註冊、個人資料、OAuth callback - 整合至 Docker(multi-stage build,nginx 靜態服務於 port 5173) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\API;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\DivingOffer;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DivingOfferController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = min((int) $request->query('per_page', 12), 50);
|
||||
|
||||
$query = DivingOffer::query();
|
||||
|
||||
if ($q = $request->query('q')) {
|
||||
$query->where(function ($sub) use ($q) {
|
||||
$sub->where('title', 'like', "%{$q}%")
|
||||
->orWhere('location', 'like', "%{$q}%")
|
||||
->orWhere('spot', 'like', "%{$q}%");
|
||||
});
|
||||
}
|
||||
|
||||
if ($region = $request->query('region')) {
|
||||
$query->where('region', $region);
|
||||
}
|
||||
|
||||
if ($tag = $request->query('tag')) {
|
||||
$query->where('tag', 'like', "%{$tag}%");
|
||||
}
|
||||
|
||||
$paginated = $query->paginate($perPage);
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'data' => $paginated->items(),
|
||||
'meta' => [
|
||||
'total' => $paginated->total(),
|
||||
'per_page' => $paginated->perPage(),
|
||||
'current_page' => $paginated->currentPage(),
|
||||
'last_page' => $paginated->lastPage(),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $id)
|
||||
{
|
||||
$offer = DivingOffer::find($id);
|
||||
|
||||
if (!$offer) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => '課程不存在',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'data' => $offer,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -105,24 +105,10 @@ class SocialAuthController extends Controller
|
||||
|
||||
// 生成 Sanctum token
|
||||
$token = $user->createToken('google-auth')->plainTextToken;
|
||||
|
||||
// 載入會員資料
|
||||
$user->load('memberProfile');
|
||||
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'message' => 'Google 登入成功',
|
||||
'data' => [
|
||||
'user' => $user,
|
||||
'token' => $token,
|
||||
'token_type' => 'Bearer',
|
||||
]
|
||||
]);
|
||||
|
||||
return redirect(env('FRONTEND_URL') . '/auth/callback?token=' . $token);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'message' => 'Google 登入失敗:' . $e->getMessage()
|
||||
], 500);
|
||||
return redirect(env('FRONTEND_URL') . '/login?error=oauth_failed');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DivingOffer extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $table = 'diving_offers';
|
||||
|
||||
protected $fillable = [
|
||||
'title',
|
||||
'location',
|
||||
'spot',
|
||||
'rating',
|
||||
'reviews',
|
||||
'price',
|
||||
'badges',
|
||||
'description',
|
||||
'tag',
|
||||
'region',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'badges' => 'array',
|
||||
'rating' => 'float',
|
||||
'price' => 'integer',
|
||||
'reviews'=> 'integer',
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user