update
This commit is contained in:
+138
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Controllers\Api\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\IndexDomainFluctuationRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\StoreDomainFluctuationRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\UpdateDomainFluctuationRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Resources\DomainFluctuationResource;
|
||||
use Modules\DomainFluctuation\App\Models\DomainFluctuation;
|
||||
|
||||
class DomainFluctuationController extends Controller
|
||||
{
|
||||
public function index(IndexDomainFluctuationRequest $request): JsonResponse
|
||||
{
|
||||
$filter = $request->toDTO();
|
||||
|
||||
$query = DomainFluctuation::query()->with('term');
|
||||
|
||||
if ($filter->termId) {
|
||||
$query->where('term_id', $filter->termId);
|
||||
}
|
||||
|
||||
if ($filter->keyword) {
|
||||
$kw = '%' . $filter->keyword . '%';
|
||||
$query->where(function ($q) use ($kw) {
|
||||
$q->where('domainName', 'like', $kw)
|
||||
->orWhere('ownerName', 'like', $kw)
|
||||
->orWhere('email', 'like', $kw)
|
||||
->orWhere('phone', 'like', $kw);
|
||||
});
|
||||
}
|
||||
|
||||
if ($filter->ownerType) {
|
||||
$query->where('ownerType', $filter->ownerType);
|
||||
}
|
||||
|
||||
if ($filter->status !== null) {
|
||||
$query->where('status', $filter->status);
|
||||
}
|
||||
|
||||
if ($filter->action) {
|
||||
$query->where('action', $filter->action);
|
||||
}
|
||||
|
||||
if ($filter->from) {
|
||||
$query->where('registeredDate', '>=', $filter->from);
|
||||
}
|
||||
|
||||
if ($filter->to) {
|
||||
$query->where('registeredDate', '<=', $filter->to);
|
||||
}
|
||||
|
||||
$query->orderBy($filter->sortBy, $filter->sortDir);
|
||||
|
||||
$paginator = $query->paginate($filter->perPage, ['*'], 'page', $filter->page);
|
||||
|
||||
return DomainFluctuationResource::collection($paginator)->response();
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$domain = DomainFluctuation::with('term')->find($id);
|
||||
|
||||
if (! $domain) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy tên miền',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => DomainFluctuationResource::make($domain),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreDomainFluctuationRequest $request): JsonResponse
|
||||
{
|
||||
$dto = $request->toDTO();
|
||||
|
||||
$domain = DB::transaction(fn () => DomainFluctuation::create($dto->toArray()));
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tạo tên miền thành công',
|
||||
'data' => DomainFluctuationResource::make($domain),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(int $id, UpdateDomainFluctuationRequest $request): JsonResponse
|
||||
{
|
||||
$domain = DomainFluctuation::find($id);
|
||||
|
||||
if (! $domain) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy tên miền',
|
||||
], 404);
|
||||
}
|
||||
|
||||
try {
|
||||
DB::transaction(fn () => $domain->update($request->toDTO()->toArray()));
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Cập nhật tên miền thành công',
|
||||
'data' => DomainFluctuationResource::make($domain->fresh('term')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$domain = DomainFluctuation::find($id);
|
||||
|
||||
if (! $domain) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy tên miền',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$domain->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Xoá tên miền thành công',
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Controllers\Api\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\StoreTermRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Resources\DomainFluctuationTermResource;
|
||||
use Modules\DomainFluctuation\App\Models\DomainFluctuationTerm;
|
||||
use Modules\DomainFluctuation\App\Models\TermFluctuationType;
|
||||
|
||||
class TermController extends Controller
|
||||
{
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
$perPage = (int) $request->input('per_page', 20);
|
||||
|
||||
$terms = DomainFluctuationTerm::query()
|
||||
->with('type')
|
||||
->withCount('fluctuations')
|
||||
->orderByDesc('id')
|
||||
->paginate($perPage);
|
||||
|
||||
return DomainFluctuationTermResource::collection($terms)->response();
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$term = DomainFluctuationTerm::with('type')->withCount('fluctuations')->find($id);
|
||||
|
||||
if (! $term) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy đợt khai báo',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => DomainFluctuationTermResource::make($term),
|
||||
]);
|
||||
}
|
||||
|
||||
public function store(StoreTermRequest $request): JsonResponse
|
||||
{
|
||||
$userId = (int) ($request->user()?->id ?? 0);
|
||||
$dto = $request->toDTO($userId);
|
||||
|
||||
$term = DB::transaction(function () use ($dto, $request) {
|
||||
$term = DomainFluctuationTerm::create($dto->toArray());
|
||||
|
||||
TermFluctuationType::create([
|
||||
'term_fluctuation_id' => $term->id,
|
||||
'type' => $request->input('type', 'vnnic_06'),
|
||||
]);
|
||||
|
||||
return $term->load('type');
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Tạo đợt khai báo thành công',
|
||||
'data' => DomainFluctuationTermResource::make($term),
|
||||
], 201);
|
||||
}
|
||||
|
||||
public function update(int $id, StoreTermRequest $request): JsonResponse
|
||||
{
|
||||
$term = DomainFluctuationTerm::find($id);
|
||||
|
||||
if (! $term) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy đợt khai báo',
|
||||
], 404);
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($term, $request) {
|
||||
$term->update($request->only(['term_name', 'description', 'date_create', 'status']));
|
||||
|
||||
if ($request->filled('type')) {
|
||||
TermFluctuationType::updateOrCreate(
|
||||
['term_fluctuation_id' => $term->id],
|
||||
['type' => $request->input('type')],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Cập nhật đợt khai báo thành công',
|
||||
'data' => DomainFluctuationTermResource::make($term->fresh('type')),
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(int $id): JsonResponse
|
||||
{
|
||||
$term = DomainFluctuationTerm::find($id);
|
||||
|
||||
if (! $term) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy đợt khai báo',
|
||||
], 404);
|
||||
}
|
||||
|
||||
$term->delete();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'Xoá đợt khai báo thành công',
|
||||
]);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Controllers\Api\Client;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Modules\DomainFluctuation\App\Http\Requests\IndexDomainFluctuationRequest;
|
||||
use Modules\DomainFluctuation\App\Http\Resources\DomainFluctuationResource;
|
||||
use Modules\DomainFluctuation\App\Models\DomainFluctuation;
|
||||
|
||||
class DomainFluctuationController extends Controller
|
||||
{
|
||||
public function index(IndexDomainFluctuationRequest $request): JsonResponse
|
||||
{
|
||||
$filter = $request->toDTO();
|
||||
|
||||
$query = DomainFluctuation::query()
|
||||
->with('term')
|
||||
->where('status', 1);
|
||||
|
||||
if ($filter->termId) {
|
||||
$query->where('term_id', $filter->termId);
|
||||
}
|
||||
|
||||
if ($filter->keyword) {
|
||||
$kw = '%' . $filter->keyword . '%';
|
||||
$query->where(function ($q) use ($kw) {
|
||||
$q->where('domainName', 'like', $kw)
|
||||
->orWhere('ownerName', 'like', $kw);
|
||||
});
|
||||
}
|
||||
|
||||
$query->orderBy($filter->sortBy, $filter->sortDir);
|
||||
|
||||
$paginator = $query->paginate($filter->perPage, ['*'], 'page', $filter->page);
|
||||
|
||||
return DomainFluctuationResource::collection($paginator)->response();
|
||||
}
|
||||
|
||||
public function show(int $id): JsonResponse
|
||||
{
|
||||
$domain = DomainFluctuation::with('term')->where('status', 1)->find($id);
|
||||
|
||||
if (! $domain) {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'Không tìm thấy tên miền',
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'data' => DomainFluctuationResource::make($domain),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Modules\DomainFluctuation\App\DTOs\DomainFluctuationFilterDTO;
|
||||
|
||||
class IndexDomainFluctuationRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'term_id' => ['nullable', 'integer'],
|
||||
'keyword' => ['nullable', 'string', 'max:255'],
|
||||
'ownerType' => ['nullable', 'in:C,T'],
|
||||
'status' => ['nullable', 'integer', 'in:0,1'],
|
||||
'action' => ['nullable', 'string', 'max:100'],
|
||||
'from' => ['nullable', 'integer'],
|
||||
'to' => ['nullable', 'integer'],
|
||||
'per_page' => ['nullable', 'integer', 'min:1', 'max:200'],
|
||||
'page' => ['nullable', 'integer', 'min:1'],
|
||||
'sort_by' => ['nullable', 'in:id,domainName,registeredDate,expiredDate,actionDate,created_at'],
|
||||
'sort_dir' => ['nullable', 'in:asc,desc'],
|
||||
];
|
||||
}
|
||||
|
||||
public function toDTO(): DomainFluctuationFilterDTO
|
||||
{
|
||||
return DomainFluctuationFilterDTO::fromArray($this->validated());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Modules\DomainFluctuation\App\DTOs\DomainFluctuationDTO;
|
||||
|
||||
class StoreDomainFluctuationRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'domainName' => ['required', 'string', 'max:255'],
|
||||
'term_id' => ['required', 'integer', 'exists:domain_fluctuation_terms,id'],
|
||||
'ownerName' => ['required', 'string', 'max:255'],
|
||||
'ownerType' => ['required', 'in:C,T'],
|
||||
'address' => ['required', 'string'],
|
||||
'countryCode' => ['required', 'string', 'max:10'],
|
||||
'adminName' => ['required', 'string', 'max:255'],
|
||||
'phone' => ['required', 'string', 'max:50'],
|
||||
'email' => ['required', 'email', 'max:255'],
|
||||
'registeredDate' => ['required'],
|
||||
'expiredDate' => ['required'],
|
||||
'cityName' => ['nullable', 'string', 'max:255'],
|
||||
'cityCode' => ['nullable', 'string', 'max:50'],
|
||||
'districtName' => ['nullable', 'string', 'max:255'],
|
||||
'wardName' => ['nullable', 'string', 'max:255'],
|
||||
'fax' => ['nullable', 'string', 'max:50'],
|
||||
'icannRegistrarName' => ['nullable', 'string', 'max:255'],
|
||||
'icannRegistrarTradeName' => ['nullable', 'string', 'max:255'],
|
||||
'businessCode' => ['nullable', 'string', 'max:100'],
|
||||
'eidCode' => ['nullable', 'string', 'max:100'],
|
||||
'personalId' => ['nullable', 'string', 'max:50'],
|
||||
'birthDate' => ['nullable', 'string', 'max:20'],
|
||||
'isAgentManager' => ['nullable', 'boolean'],
|
||||
'action' => ['nullable', 'string', 'max:100'],
|
||||
'actionReason' => ['nullable', 'string'],
|
||||
'actionSource' => ['nullable', 'string', 'max:100'],
|
||||
'actionDate' => ['nullable'],
|
||||
'note' => ['nullable', 'string'],
|
||||
'ianaNumber' => ['nullable', 'integer'],
|
||||
'status' => ['nullable', 'integer', 'in:0,1'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'domainName.required' => 'Tên miền là bắt buộc',
|
||||
'term_id.required' => 'Đợt khai báo là bắt buộc',
|
||||
'term_id.exists' => 'Đợt khai báo không tồn tại',
|
||||
'ownerName.required' => 'Tên chủ sở hữu là bắt buộc',
|
||||
'ownerType.required' => 'Loại chủ sở hữu là bắt buộc',
|
||||
'ownerType.in' => 'Loại chủ sở hữu phải là C (cá nhân) hoặc T (tổ chức)',
|
||||
'registeredDate.required' => 'Ngày đăng ký là bắt buộc',
|
||||
'expiredDate.required' => 'Ngày hết hạn là bắt buộc',
|
||||
'address.required' => 'Địa chỉ là bắt buộc',
|
||||
'countryCode.required' => 'Mã quốc gia là bắt buộc',
|
||||
'adminName.required' => 'Tên quản trị là bắt buộc',
|
||||
'phone.required' => 'Số điện thoại là bắt buộc',
|
||||
'email.required' => 'Email là bắt buộc',
|
||||
'email.email' => 'Email không hợp lệ',
|
||||
];
|
||||
}
|
||||
|
||||
public function toDTO(): DomainFluctuationDTO
|
||||
{
|
||||
return DomainFluctuationDTO::fromArray($this->validated());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Modules\DomainFluctuation\App\DTOs\DomainFluctuationTermDTO;
|
||||
|
||||
class StoreTermRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'term_name' => ['required', 'string', 'max:255'],
|
||||
'description' => ['nullable', 'string'],
|
||||
'date_create' => ['nullable'],
|
||||
'status' => ['nullable', 'boolean'],
|
||||
'type' => ['nullable', 'in:vnnic_06,vnnic_07'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'term_name.required' => 'Tên đợt khai báo là bắt buộc',
|
||||
];
|
||||
}
|
||||
|
||||
public function toDTO(int $userId): DomainFluctuationTermDTO
|
||||
{
|
||||
return DomainFluctuationTermDTO::fromArray(array_merge(
|
||||
$this->validated(),
|
||||
['user_id' => $userId]
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Requests;
|
||||
|
||||
use Modules\DomainFluctuation\App\DTOs\DomainFluctuationDTO;
|
||||
|
||||
class UpdateDomainFluctuationRequest extends StoreDomainFluctuationRequest
|
||||
{
|
||||
public function rules(): array
|
||||
{
|
||||
return array_merge(parent::rules(), [
|
||||
'term_id' => ['sometimes', 'integer', 'exists:domain_fluctuation_terms,id'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function toDTO(): DomainFluctuationDTO
|
||||
{
|
||||
return DomainFluctuationDTO::fromArray($this->validated());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DomainFluctuationResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'domainName' => $this->domainName,
|
||||
'term_id' => $this->term_id,
|
||||
'term' => DomainFluctuationTermResource::make($this->whenLoaded('term')),
|
||||
'registeredDate' => $this->registeredDate,
|
||||
'expiredDate' => $this->expiredDate,
|
||||
'ownerName' => $this->ownerName,
|
||||
'ownerType' => $this->ownerType,
|
||||
'address' => $this->address,
|
||||
'wardName' => $this->wardName,
|
||||
'districtName' => $this->districtName,
|
||||
'cityName' => $this->cityName,
|
||||
'cityCode' => $this->cityCode,
|
||||
'countryCode' => $this->countryCode,
|
||||
'phone' => $this->phone,
|
||||
'email' => $this->email,
|
||||
'fax' => $this->fax,
|
||||
'adminName' => $this->adminName,
|
||||
'businessCode' => $this->businessCode,
|
||||
'eidCode' => $this->eidCode,
|
||||
'personalId' => $this->personalId,
|
||||
'birthDate' => $this->birthDate,
|
||||
'icannRegistrarName' => $this->icannRegistrarName,
|
||||
'icannRegistrarTradeName' => $this->icannRegistrarTradeName,
|
||||
'isAgentManager' => (bool) $this->isAgentManager,
|
||||
'action' => $this->action,
|
||||
'actionReason' => $this->actionReason,
|
||||
'actionSource' => $this->actionSource,
|
||||
'actionDate' => $this->actionDate,
|
||||
'note' => $this->note,
|
||||
'ianaNumber' => $this->ianaNumber,
|
||||
'status' => (int) $this->status,
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\DomainFluctuation\App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DomainFluctuationTermResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'term_name' => $this->term_name,
|
||||
'description' => $this->description,
|
||||
'date_create' => $this->date_create,
|
||||
'user_id' => $this->user_id,
|
||||
'status' => (bool) $this->status,
|
||||
'type' => $this->whenLoaded('type', fn () => $this->type?->type),
|
||||
'fluctuations_count' => $this->when(
|
||||
isset($this->fluctuations_count),
|
||||
fn () => (int) $this->fluctuations_count
|
||||
),
|
||||
'created_at' => $this->created_at,
|
||||
'updated_at' => $this->updated_at,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user