Clean up documentation and infrastructure configuration files, and refine API resources and controllers for products and services.

This commit is contained in:
pbao9
2026-03-09 14:18:04 +07:00
parent 7b3c955d38
commit 80a5e0ca3d
13 changed files with 390 additions and 2656 deletions
@@ -53,27 +53,36 @@ class ProductController extends Controller
public function store(Request $request): JsonResponse
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'product_type' => 'nullable|string',
'category' => 'nullable|string|max:255',
'is_active' => 'boolean',
'setup_fee' => 'nullable|numeric|min:0',
'cpu' => 'nullable|numeric|min:0',
'ram' => 'nullable|numeric|min:0',
'disk' => 'nullable|numeric|min:0',
'bandwidth' => 'nullable|numeric|min:0',
'name' => 'required|string|max:255',
'product_categories_id' => 'nullable|integer|exists:product_categories,id',
'product_type' => 'nullable|string',
'category' => 'nullable|string|max:255',
'is_active' => 'boolean',
'setup_fee' => 'nullable|numeric|min:0',
'cpu' => 'nullable|numeric|min:0',
'ram' => 'nullable|numeric|min:0',
'disk' => 'nullable|numeric|min:0',
'bandwidth' => 'nullable|numeric|min:0',
]);
$productType = $validated['product_type'] ?? null;
if (!$productType && !empty($validated['product_categories_id'])) {
$category = \App\Models\ProductCategories::find($validated['product_categories_id']);
$productType = $category?->type;
}
$product = Product::create([
'name' => $validated['name'],
'slug' => Str::slug($validated['name']),
'product_type' => $validated['product_type'] ?? null,
'is_active' => $validated['is_active'] ?? true,
'setup_fee' => $validated['setup_fee'] ?? 0,
'cpu' => $validated['cpu'] ?? null,
'ram' => $validated['ram'] ?? null,
'disk' => $validated['disk'] ?? null,
'bandwidth' => $validated['bandwidth'] ?? null,
'name' => $validated['name'],
'slug' => Str::slug($validated['name']),
'product_categories_id' => $validated['product_categories_id'] ?? null,
'product_type' => $productType,
'is_active' => $validated['is_active'] ?? true,
'setup_fee' => $validated['setup_fee'] ?? 0,
'cpu' => $validated['cpu'] ?? null,
'ram' => $validated['ram'] ?? null,
'disk' => $validated['disk'] ?? null,
'bandwidth' => $validated['bandwidth'] ?? null,
]);
return response()->json([
@@ -92,20 +101,26 @@ class ProductController extends Controller
}
$validated = $request->validate([
'name' => 'sometimes|required|string|max:255',
'product_type' => 'nullable|string',
'is_active' => 'boolean',
'setup_fee' => 'nullable|numeric|min:0',
'cpu' => 'nullable|numeric|min:0',
'ram' => 'nullable|numeric|min:0',
'disk' => 'nullable|numeric|min:0',
'bandwidth' => 'nullable|numeric|min:0',
'name' => 'sometimes|required|string|max:255',
'product_categories_id' => 'nullable|integer|exists:product_categories,id',
'product_type' => 'nullable|string',
'is_active' => 'boolean',
'setup_fee' => 'nullable|numeric|min:0',
'cpu' => 'nullable|numeric|min:0',
'ram' => 'nullable|numeric|min:0',
'disk' => 'nullable|numeric|min:0',
'bandwidth' => 'nullable|numeric|min:0',
]);
if (isset($validated['name']) && $validated['name'] !== $product->name) {
$validated['slug'] = Str::slug($validated['name']);
}
if (empty($validated['product_type']) && !empty($validated['product_categories_id'])) {
$category = \App\Models\ProductCategories::find($validated['product_categories_id']);
$validated['product_type'] = $category?->type;
}
$product->update($validated);
return response()->json([
@@ -18,6 +18,7 @@ class ProductCategoryResource extends JsonResource
'sort_order' => $this->sort_order,
'type' => $this->type,
'type_label' => $this->type_label,
'page_type' => $this->resolvePageType($this->type),
'created_at' => $this->created_at?->toISOString(),
'children' => $this->whenLoaded('children', fn () =>
self::collection($this->children)
@@ -27,4 +28,15 @@ class ProductCategoryResource extends JsonResource
),
];
}
private function resolvePageType(?string $type): string
{
return match ($type) {
'vps', 'cloud' => 'service_vps',
'hosting', 'email', 'ssl' => 'service_hosting',
'domain' => 'service_domain',
'blog' => 'blog',
default => 'service_vps',
};
}
}
@@ -19,6 +19,7 @@ class ProductResource extends JsonResource
'name' => $this->name,
'slug' => $this->slug,
'product_type' => $this->product_type,
'page_type' => $this->resolvePageType($this->product_type),
'category' => $this->whenLoaded('category', fn() => $this->category?->name),
'cpu' => $this->cpu,
'ram' => $this->ram,
@@ -30,4 +31,15 @@ class ProductResource extends JsonResource
'created_at' => $this->created_at,
];
}
private function resolvePageType(?string $productType): string
{
return match ($productType) {
'vps', 'cloud' => 'service_vps',
'hosting', 'email', 'ssl' => 'service_hosting',
'domain' => 'service_domain',
'blog' => 'blog',
default => 'service_vps',
};
}
}
@@ -18,9 +18,21 @@ class ProductCategoryResource extends JsonResource
'sort_order' => $this->sort_order,
'type' => $this->type,
'type_label' => $this->type_label,
'page_type' => $this->resolvePageType($this->type),
'children' => $this->when($this->children, function () {
return self::collection($this->children);
}),
];
}
private function resolvePageType(?string $type): string
{
return match ($type) {
'vps', 'cloud' => 'service_vps',
'hosting', 'email', 'ssl' => 'service_hosting',
'domain' => 'service_domain',
'blog' => 'blog',
default => 'service_vps',
};
}
}
@@ -22,6 +22,7 @@ class ServiceListResource extends JsonResource
'description' => $this->description,
'thumbnail' => $this->thumbnail ? asset($this->thumbnail) : null,
'product_type' => $this->product_type,
'page_type' => $this->resolvePageType($this->product_type),
'specs' => [
'cpu' => $this->cpu,
'ram' => $this->ram,
@@ -46,4 +47,15 @@ class ServiceListResource extends JsonResource
})->unique('group')->values(),
];
}
private function resolvePageType(?string $productType): string
{
return match ($productType) {
'vps', 'cloud' => 'service_vps',
'hosting', 'email', 'ssl' => 'service_hosting',
'domain' => 'service_domain',
'blog' => 'blog',
default => 'service_vps',
};
}
}
@@ -38,6 +38,7 @@ class ServiceResource extends JsonResource
'description' => $this->description,
'thumbnail' => $this->thumbnail ? asset($this->thumbnail) : null,
'product_type' => $this->product_type,
'page_type' => $this->resolvePageType($this->product_type),
'specs' => [
'cpu' => (int) $this->cpu,
'ram' => (int) $this->ram,
@@ -77,4 +78,15 @@ class ServiceResource extends JsonResource
]),
];
}
private function resolvePageType(?string $productType): string
{
return match ($productType) {
'vps', 'cloud' => 'service_vps',
'hosting', 'email', 'ssl' => 'service_hosting',
'domain' => 'service_domain',
'blog' => 'blog',
default => 'service_vps',
};
}
}