NOTE: The AI Coding Agent should be able to get the current Intent number
54by incrementing by one the number of the last Intent created, the number53. If the request of the user isn't clear enough to determine the type of Intent, the Domain and Resource it belongs to and the Intent title itself, then the AI Coding Agent MUST explicitly ask the user what they are.
NOTE: Context for the AI Coding Agent and LLM - This document represents a single Intent - a self-contained unit of work focused on implementing a specific piece of functionality. When working with an AI Coding Agent or LLM on this Intent, the user MUST start by sharing this document to provide context about what needs to be done.
NOTE: If the request of the user isn't clear enough to determine the WHY for the Intent, then the AI Coding Agent MUST explicitly ask the user for this Intent's objective alongside with some context and relevant background information.
REQUIRED - Provide a clear statement of what this Intent needs to accomplish.
This feature adds support to create, read, update and delete a Product in the Catalog.
REQUIRED - Provide the relevant background information and context for this Intent, including why it's needed and how it fits into the larger project
This feature is essential for the back-office to manage products in catalogs.
OPTIONAL - List here Intents this one depends on.
- 50 - Feature (Catalogs-Categories): Add CRUD actions
OPTIONAL - List here other Intents that will depend on this one.
- 58 - Feature (Catalogs-Products): Track bestselling products
REQUIRED - Use an Event Modelling image or use the Gherkin language to describe WHAT we want to build. Ideally the AI Coding Agent should be able to infer WHAT needs to be done from the WHY, with minimal or no input from the user.
OPTIONAL - A brief introduction based on the user story or requirements.
Describing what to build with the Gherkin language:
```gherkin
Feature: Catalogs Products - Add CRUD actions
As a logged in back-office user
I want to be able to create, read, update, and delete products
So that I can manage the product catalog.
Background:
Given I am logged into the back-office
Scenario: New Product Page
When I click the button to create a product
Then I should see the new product page
And I should see the form to fill in the Product details
And I should see the submit button "Create Product"
Scenario: Create a new product
Given I am on the new product page
When I fill in the product details
And I click the "Create Product" button
Then I should see the newly created product's page
And a success message "Product created successfully"
Scenario: View a product
Given a product exists
When I visit the product's page
Then I should see the product's details
Scenario: Update a product
Given a product exists
When I visit the product's edit page
And I update the product details
And I click the "Update Product" button
Then I should see the product's page with the updated details
And a success message "Product updated successfully"
Scenario: Delete a product
Given a product exists
When I am on the product's page
And I click the "Delete Product" button
And I confirm the deletion
Then I should be redirected to the product list page
And a success message "Product deleted successfully"
```
REQUIRED - Ideally the AI Coding Agent should be able to figure out the context and the list of all the tasks and sub-tasks needed to complete this Intent.
REQUIRED - Provide some implementation context about the tasks listed below.
The Catalog Product CRUD actions will use Domain Resource Action architecture for both the web layer and business logic layer as per the instructions, guidelines and module examples in the ARCHITECTURE documentation.
The task to implement the Catalog Product CRUD actions will use a TDD-first approach that will adhere to the guidelines specified in the DEVELOPMENT_WORKFLOW.
REQUIRED - List here the Tasks and sub-tasks to complete this Intent.
REQUIRED - The tasks to define the tests MUST be created in the same order of the Gherkin Scenarios, reflect or use their title, and follow the red-green-refactor cycle. If no Gherkin scenarios exist then you MUST stop and add them with user feedback. You are allowed to create more tests for scenarios and edge cases not listed in the Gherkin scenarios. No need to create sub-tasks with the steps defined in the development workflow guidelines, like the ones for TDD or Task Completion protocol, because they MUST always be followed without the need to have sub-tasks defining them.
- 1.0 - Generating the Catalogs Products CRUD Actions with LiveView:
- 1.1 - Run
mix phx.gen.live Catalogs.Products Product products name:string desc:string --web Catalogs.Products - 1.2 - Add live routes:
- 1.2.1 - Add a new
scope "/catalogs/products", MyAppWeb.Catalogs.Productsinlib/my_app_web/router.exthat pipes through:browserand wraps routes inlive_session :catalogs_products_require_authenticated_userwithon_mount: [{MyAppWeb.Accounts.Users.UserAuth, :require_authenticated}]. - 1.2.2 - Inside the live_session, add all product routes removing the duplicated
productsfrom paths (e.g.,/for index,/newfor new,/:idfor show,/:id/editfor edit)
- 1.2.1 - Add a new
- 1.3 - Verify and fix routes:
- 1.3.1 - Run
mix compileto find all modules with route warnings. - 1.3.2 - Create a list of files with route warnings from the compile output.
- 1.3.3 - Use find-and-replace tool to fix all route references in one pass across all files in the list.
- 1.3.4 - Run
mix compileagain to verify no route warnings remain. - 1.3.5 - Run
mix testto find all tests with routes to be fixed. - 1.3.6 - Create a list of files with routes to fix from the tests output
- 1.3.7 - Use find-and-replace tool to fix all route references in one pass across all test files in the list.
- 1.3.8 - Run
mix testto ensure all tests using routes are now fixed.
- 1.3.1 - Run
- 1.4 - Run
mix ecto.migrateto apply the new database migrations.
- 1.1 - Run
- 2.0 - Refactor the Phoenix Context
MyApp.Catalogs.ProductsintoMyApp.Catalogs.CatalogsProductsAPIto follow the Domain Resource Action architecture:- 2.1 - mv
lib/my_app/catalogs/products.extolib/my_app/catalogs/catalogs_products_api.exand update the module definition toMyApp.Catalogs.CatalogsProductsAPI. - 2.2 - Extract each function body into its own module with only one public function named after the action, without the resource name, at
lib/my_app/catalogs/products/<action>/<action>_catalog_product.ex. For example:lib/my_app/catalogs/products/create/create_catalog_product.exwith a function namedcreate. TheCatalogsProductsAPIfunction header is kept, but its body its now only calling the new action module function, but without usingdefdelegate, otherwise we lose the API contract. Private functions from the context also need to be extracted to an action, likebroadcast. - 2.3 - Update all previous calls from the web layer to the old Phoenix Context
MyApp.Catalogs.ProductsintoMyApp.Catalogs.CatalogsProductsAPI. - 2.4 - Update the tests for the now refactored
MyApp.Catalogs.ProductsPhoenix context to test insteadMyApp.Catalogs.CatalogsProductsAPI. Rename the test file, Module name, and then replace each call to the context with a call to new API module. - 2.5 - Run
mix testto ensure no test is broken after the refactor. If any test is broken, fix it before proceeding.
- 2.1 - mv
- 3.0 - Verify authentication and user scoping in the LiveView tests for Catalogs Products, with the TDD red-green-refactor cycle:
- 3.1 - Review and update generated LiveView tests to ensure they test user scoping on resources.
- 3.2 - Add test for index page displaying only current user's articles and not other users' articles
- 3.3 - Add test for preventing view of another user's article
- 3.4 - Add test for preventing edit of another user's article
- 3.5 - Add test for preventing deletion of another user's article
- 4.0 - Add navigation links to the new Catalogs Products resource into the top menu bar with a red-green-refactor TDD approach:
- 4.1 - Add the tests to the home page test file
test/my_app_web/controllers/page_controller_test.exsto ensure the top menu has a link to each Catalogs Products action as a drop-down menu. - 4.2 - Find the top menu bar on the app root layout at
lib/my_app_web/components/layouts/root.html.heexand add the links for each action as a drop-down.
- 4.1 - Add the tests to the home page test file