Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/catalog brand #1057

Merged
merged 14 commits into from
Nov 22, 2024

Conversation

jacekmichalski
Copy link
Contributor

This pull request introduces several major changes to the Catalog module, including the addition of a new Brand entity and corresponding CRUD operations, as well as updates to the database schema and migrations to support these changes.

Database Schema and Migrations:

  • Added new Brand entity and updated the Product entity to include a foreign key relationship with Brand. This includes creating the Brands table and modifying the Products table to reference BrandId. [1] [2] [3] [4] [5] [6]
  • Removed the old migration file and replaced it with a new migration file that includes the Brands table and updates to the Products table. [1] [2]

Authorization:

  • Updated FshPermissions to include permissions for Brand operations such as view, search, create, update, delete, and export.

Application Layer:

  • Introduced new commands, handlers, and validators for creating, deleting, and retrieving Brand entities. This includes:
    • CreateBrandCommand and its handler, validator, and response. [1] [2] [3] [4]
    • DeleteBrandCommand and its handler. [1] [2]
    • GetBrandRequest and its handler, which includes caching logic. [1] [2]

Event Handling:

  • Added an event handler for the BrandCreated event to log the creation of a new brand.

Search and Specifications:

  • Implemented SearchBrandSpecs to support searching and paginating through Brand entities.

These changes collectively enhance the functionality of the Catalog module by adding support for managing brands and ensuring that the database schema and application logic are updated accordingly.

Introduced the `Brand` class in the `FSH.Starter.WebApi.Catalog.Domain` namespace, inheriting from `AuditableEntity` and implementing `IAggregateRoot`. Added properties for `Name` and `Description`, and methods for creating and updating brand instances. Queued domain events `BrandCreated` and `BrandUpdated` during these operations.

Added `BrandCreated` and `BrandUpdated` classes in the `FSH.Starter.WebApi.Catalog.Domain.Events` namespace, both inheriting from `DomainEvent` and including a property for the `Brand` instance.

Added `BrandNotFoundException` class in the `FSH.Starter.WebApi.Catalog.Domain.Exceptions` namespace, inheriting from `NotFoundException` to handle cases where a brand with a specified ID is not found.
Added commands and handlers for brand management:
- CreateBrandCommand, CreateBrandCommandValidator, CreateBrandHandler, and CreateBrandResponse for creating brands.
- DeleteBrandCommand and DeleteBrandHandler for deleting brands.
- BrandCreatedEventHandler for handling brand creation events.
- BrandResponse and GetBrandHandler for retrieving brand details.
- GetBrandRequest for brand retrieval requests.
- SearchBrandSpecs, SearchBrandsCommand, and SearchBrandsHandler for searching brands with pagination.
- UpdateBrandCommand, UpdateBrandCommandValidator, UpdateBrandHandler, and UpdateBrandResponse for updating brand details.
Introduce new endpoints for brand operations in the
FSH.Starter.WebApi.Catalog.Infrastructure.Endpoints.v1 namespace.
Endpoints include CreateBrand, DeleteBrand, GetBrand,
SearchBrands, and UpdateBrand, each secured with specific
permissions and mapped to appropriate routes. Handlers use
MediatR for request handling and response production.
Introduce BrandConfiguration class to configure the Brand entity
for Entity Framework Core. This includes enabling multi-tenancy,
setting the primary key, and specifying maximum lengths for the
Name (100 characters) and Description (1000 characters) properties.
The changes introduce new permissions related to the "Brands" resource in the `FshPermissions` class. Specifically, the following permissions are added:
- View Brands (with `IsBasic` set to true)
- Search Brands (with `IsBasic` set to true)
- Create Brands
- Update Brands
- Delete Brands
- Export Brands

The "View Brands" and "Search Brands" permissions are marked as basic, indicating they might be available to users with basic access rights.
- Modified GetProductHandler to use specification pattern
- Added GetProductSpecs for flexible product querying
- Updated ProductResponse to include BrandResponse
- Enhanced SearchProductSpecs to include brand details
- Updated Product class to establish brand relationship
- Modified Create and Update methods to accept brandId
Introduce new endpoints in CatalogModule for brand creation, retrieval, listing, updating, and deletion. Register scoped services for Brand in RegisterCatalogServices method. Add DbSet<Brand> property in CatalogDbContext for managing Brand entities.
- Updated CreateProductCommand and UpdateProductCommand to include BrandId with a default value of null.
- Modified CreateProductHandler and UpdateProductHandler to pass BrandId when creating or updating a product.
- Added BrandId filter condition in SearchProductSpecs.
- Updated CatalogDbInitializer to include BrandId when seeding the database.
Removed old migration and added new migration to create Brands table alongside Products table. Updated Designer and DbContext snapshot to reflect new schema. Updated project file to include new Catalog folder.
Enhanced ApiClient with cancellation tokens and new brand methods.
Updated serialization to use JsonSerializerSettings. Upgraded
NJsonSchema and NSwag to 14.1.0.0. Changed runtime in nswag.json
from WinX64 to Net80.
Introduced a new "Brands" section in the application:
- Added a navigation link for "Brands" in `NavMenu.razor`.
- Implemented permission checks for viewing Brands in `NavMenu.razor.cs`.
- Created `Brands.razor` page with route `/catalog/brands`.
- Set up `EntityTable` component for managing brands.
- Added `Brands` class and dependency injection in `Brands.razor.cs`.
- Defined `BrandViewModel` for CRUD operations in `Brands.razor.cs`.
Added a `MudSelect` component in `Products.razor` for brand selection, bound to `context.BrandId` and populated with a list of brands. Introduced a private `_brands` field in `Products.razor.cs` to store the list of brands. Modified `OnInitialized` to `OnInitializedAsync` and added `LoadBrandsAsync` to fetch brands from the server. Updated `EntityServerTableContext` initialization to include the brand name field.
Added a dropdown (`MudSelect`) for selecting a brand in the advanced
search section of the `Products.razor` file, allowing users to filter
products by brand with an "All Brands" option. Updated the search
function in `Products.razor.cs` to include the selected brand ID
(`SearchBrandId`). Changed the type of `SearchBrandId` from `Guid` to
`Guid?` to support the nullable brand ID for the "All Brands" option.
The `ItemGroup` containing the `<Folder Include="Catalog\" />` line was removed from the `PostgreSQL.csproj` file. This change eliminates the folder reference to `Catalog` from the project file.
@jacekmichalski
Copy link
Contributor Author

@iammukeshm can you review it and merge it?

@jacekmichalski
Copy link
Contributor Author

@AliRafay can you review it?

@iammukeshm iammukeshm merged commit cd770dc into fullstackhero:main Nov 22, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants