diff --git a/app/Domains/Menu/Controllers/MenuController.php b/app/Domains/Menu/Controllers/MenuController.php deleted file mode 100644 index 2c9135e..0000000 --- a/app/Domains/Menu/Controllers/MenuController.php +++ /dev/null @@ -1,79 +0,0 @@ -json($menues); - } - - public function store(Request $request): JsonResponse - { - $validated = $request->validate([ - 'code' => 'required|string|unique:menues,code', - 'label' => 'required|string|max:255', - 'parent_menu_code' => [ - 'nullable', - 'string', - Rule::exists('menues', 'code'), - 'different:code', - ], - 'content_type' => [ - 'sometimes', - Rule::in([Menu::CONTENT_TYPE_STATIC, Menu::CONTENT_TYPE_DYNAMIC]), - ], - 'static_content_schema' => 'required_if:content_type,static|nullable|array', - 'route' => 'required|string', - ]); - - $menu = Menu::create($validated); - - return response()->json($menu, 201); - } - - public function show(Menu $menu): JsonResponse - { - return response()->json($menu); - } - - public function update(Request $request, Menu $menu): JsonResponse - { - $validated = $request->validate([ - 'code' => 'sometimes|required|string|unique:menues,code,'.$menu->id, - 'label' => 'sometimes|required|string|max:255', - 'parent_menu_code' => [ - 'nullable', - 'string', - Rule::exists('menues', 'code'), - Rule::notIn([$menu->code]), - ], - 'content_type' => [ - 'sometimes', - Rule::in([Menu::CONTENT_TYPE_STATIC, Menu::CONTENT_TYPE_DYNAMIC]), - ], - 'static_content_schema' => 'required_if:content_type,static|nullable|array', - 'route' => 'sometimes|required|string', - ]); - - $menu->update($validated); - - return response()->json($menu); - } - - public function destroy(Menu $menu): JsonResponse - { - $menu->delete(); - - return response()->json(null, 204); - } -} diff --git a/app/Domains/Menu/Controllers/TenantMenuController.php b/app/Domains/Menu/Controllers/TenantMenuController.php deleted file mode 100644 index bd0a2a1..0000000 --- a/app/Domains/Menu/Controllers/TenantMenuController.php +++ /dev/null @@ -1,32 +0,0 @@ -where('codigo', $tenantCode)->firstOrFail(); - $menu = Menu::query()->where('code', $menuCode)->firstOrFail(); - - $tenantMenu = $this->tenantMenuService->configure( - $tenant, - $menu, - $request->validated('static_content'), - ); - - return response()->json($tenantMenu); - } -} diff --git a/app/Domains/Menu/Requests/StoreTenantMenuRequest.php b/app/Domains/Menu/Requests/StoreTenantMenuRequest.php deleted file mode 100644 index 0ee9b99..0000000 --- a/app/Domains/Menu/Requests/StoreTenantMenuRequest.php +++ /dev/null @@ -1,49 +0,0 @@ -menuModel = Menu::query() - ->where('code', $this->route('menu_code')) - ->first(); - - if (! $this->menuModel) { - throw ValidationException::withMessages([ - 'menu_code' => __('api.menu.not_found'), - ]); - } - } - - public function rules(): array - { - if ($this->menuModel?->content_type !== Menu::CONTENT_TYPE_STATIC) { - return [ - 'static_content' => ['nullable', 'array'], - ]; - } - - $rules = [ - 'static_content' => ['required', 'array'], - ]; - - foreach ($this->menuModel->static_content_schema as $field => $rule) { - $rules["static_content.{$field}"] = $rule; - } - - return $rules; - } -} diff --git a/app/Domains/Menu/Services/TenantMenuService.php b/app/Domains/Menu/Services/TenantMenuService.php deleted file mode 100644 index 102c498..0000000 --- a/app/Domains/Menu/Services/TenantMenuService.php +++ /dev/null @@ -1,26 +0,0 @@ - TenantMenu::query()->updateOrCreate( - [ - 'tenant_code' => $tenant->codigo, - 'menu_code' => $menu->code, - ], - [ - 'static_content' => $menu->content_type === Menu::CONTENT_TYPE_STATIC - ? $staticContent - : null, - ], - )); - } -} diff --git a/app/Domains/Menu/routes/api.php b/app/Domains/Menu/routes/api.php deleted file mode 100644 index 3d03a24..0000000 --- a/app/Domains/Menu/routes/api.php +++ /dev/null @@ -1,12 +0,0 @@ -createTenant(); - $menu = Menu::query()->create([ - 'code' => 'about', - 'label' => 'Nosotros', - 'content_type' => Menu::CONTENT_TYPE_STATIC, - 'static_content_schema' => [ - 'title' => 'required|string|max:20', - 'sections' => 'required|array|min:1', - 'sections.*.body' => 'required|string', - ], - 'route' => '/about', - ]); - - $this->postJson("/api/{$tenant->codigo}/menues/{$menu->code}", [ - 'static_content' => [ - 'title' => 123, - 'sections' => [], - ], - ]) - ->assertUnprocessable() - ->assertJsonValidationErrors([ - 'static_content.title', - 'static_content.sections', - ]); - - $this->assertDatabaseMissing('tenants_menues', [ - 'tenant_code' => $tenant->codigo, - 'menu_code' => $menu->code, - ]); - } - - public function test_it_configures_a_static_menu_when_content_matches_the_schema(): void - { - $tenant = $this->createTenant(); - $menu = Menu::query()->create([ - 'code' => 'about', - 'label' => 'Nosotros', - 'content_type' => Menu::CONTENT_TYPE_STATIC, - 'static_content_schema' => [ - 'title' => 'required|string|max:20', - 'sections' => 'required|array|min:1', - 'sections.*.body' => 'required|string', - ], - 'route' => '/about', - ]); - - $content = [ - 'title' => 'Nosotros', - 'sections' => [ - ['body' => 'Nuestra historia'], - ], - ]; - - $this->postJson("/api/{$tenant->codigo}/menues/{$menu->code}", [ - 'static_content' => $content, - ]) - ->assertOk() - ->assertJsonPath('static_content.title', 'Nosotros') - ->assertJsonPath('static_content.sections.0.body', 'Nuestra historia'); - - $this->assertSame( - $content, - $tenant->menues()->where('menues.code', $menu->code)->firstOrFail()->pivot->static_content - ); - } - - public function test_dynamic_menus_do_not_require_static_content(): void - { - $tenant = $this->createTenant(); - $menu = Menu::query()->create([ - 'code' => 'catalog', - 'label' => 'Catálogo', - 'route' => '/catalog', - ]); - - $this->postJson("/api/{$tenant->codigo}/menues/{$menu->code}") - ->assertOk() - ->assertJsonPath('static_content', null); - - $this->assertDatabaseHas('tenants_menues', [ - 'tenant_code' => $tenant->codigo, - 'menu_code' => $menu->code, - 'static_content' => null, - ]); - } - - public function test_contact_content_requires_coordinates_inside_each_address(): void - { - $tenant = $this->createTenant(); - $this->seed(MenuSeeder::class); - - $this->postJson("/api/{$tenant->codigo}/menues/help.contact", [ - 'static_content' => [ - 'whatsapp' => [ - 'whatsapp_url' => 'https://wa.me/543412602222', - 'whatsapp_label' => 'Chatea con nosotros', - ], - 'phone' => '+54 9 (0341) 6658247', - 'locations' => [ - 'rosario' => [ - 'label' => 'Rosario', - 'addresses' => [ - [ - 'label' => 'Av. San Lorenzo 1542', - 'address' => 'Av. San Lorenzo 1542, Rosario', - 'coordinates' => [-91, -181], - ], - ], - ], - ], - 'map_locations' => [ - 'legacy_point' => [-32.946820, -60.639320], - ], - ], - ]) - ->assertUnprocessable() - ->assertJsonValidationErrors([ - 'static_content.locations.rosario.addresses.0.coordinates.0', - 'static_content.locations.rosario.addresses.0.coordinates.1', - 'static_content.map_locations', - ]); - } - - private function createTenant(): Tenant - { - $headerLogo = $this->createAttachment('header.png'); - $footerLogo = $this->createAttachment('footer.png'); - - return Tenant::query()->create([ - 'codigo' => 'acme', - 'nombre' => 'Acme', - 'dominio' => 'acme.com', - 'primary_color' => '#111111', - 'secondary_color' => '#222222', - 'danger_color' => '#333333', - 'success_color' => '#444444', - 'header_bg_color' => '#ffffff', - 'footer_bg_color' => '#ffffff', - 'header_logo_id' => $headerLogo->id, - 'footer_logo_id' => $footerLogo->id, - ]); - } - - private function createAttachment(string $filename): Attachment - { - return Attachment::query()->create([ - 'path' => "test/{$filename}", - 'filename' => $filename, - 'type' => AttachmentType::Image, - 'mime_type' => 'image/png', - ]); - } -}