Related Product Service
Overview
The Related Product service manages relationships between products (cross-sell / upsell / related items).
It allows you to:
- list all related product links for a given product
- create a link between
ProductIdandRelatedProductId - delete an existing link
This service stores relationships only (two product IDs).
It does not return full product objects - only link rows from the RelatedProducts table.
All operations are tenant-aware and audited.
Endpoints
GET
/api/v1/RelatedProduct/GetAllRelatedProductByProductid/{productId}
Returns all related-product links for a specific product.
Behavior:
- Validates
productId > 0in the service - Checks whether the product exists
- Returns a list of relationship rows from the database
- If no links exist, the service returns an empty list (and logs a user action)
Controller behavior:
- Returns
404if the returned list is empty
Response:
List<RelatedProduct>(DB entity rows)
Typically contains:ProductIdRelatedProductId
Errors:
- Returns
404if no related products exist for this product (controller behavior)
Authorization:
- Requires Bearer Token
POST
/api/v1/RelatedProduct/AddNewRelatedProduct
Creates a relationship between two products.
Request body:
ProductId(long, required)RelatedProductId(long, required)
Behavior:
- Prevents duplicate relationships (
ProductId+RelatedProductId) - Inserts a new row into
RelatedProducts - Writes an audit log entry on success
Validation notes (important):
- The service currently checks:
if (ProductId <= 0 && RelatedProductId <= 0) return false;This means if only one of them is invalid (e.g.ProductId = 0,RelatedProductId = 123), it may still pass. Recommended: change&&to||to require both values.
Errors:
- Returns
400if:- validation -
- relationship already exists
- insert -
Authorization:
- Requires Bearer Token
DELETE
/api/v1/RelatedProduct/DeleteRelatedProduct/{productId}/{relatedproductId}
Deletes a relationship between two products.
Route parameters:
productId(long, required)relatedproductId(long, required)
Behavior:
- Deletes a single relationship row where:
ProductId == productIdANDRelatedProductId == relatedproductId
- Writes an audit log entry on success
Errors:
- Returns
400if relationship does not exist or deletion -
Authorization:
- Requires Bearer Token
Notes
- This service manages relationships only (no product details).
GETreturns DB entity rows (not a dedicated ViewModel).- The controller returns
404when the list is empty. - All state-changing operations are audited.
- Internal errors are logged and not exposed to API consumers.