littleshop/LittleShop/Controllers/ProductMultiBuysController.cs
SysAdmin 034b8facee Implement product multi-buys and variants system
Major restructuring of product variations:
- Renamed ProductVariation to ProductMultiBuy for quantity-based pricing (e.g., "3 for £25")
- Added new ProductVariant model for string-based options (colors, flavors)
- Complete separation of multi-buy pricing from variant selection

Features implemented:
- Multi-buy deals with automatic price-per-unit calculation
- Product variants for colors/flavors/sizes with stock tracking
- TeleBot checkout supports both multi-buys and variant selection
- Shopping cart correctly calculates multi-buy bundle prices
- Order system tracks selected variants and multi-buy choices
- Real-time bot activity monitoring with SignalR
- Public bot directory page with QR codes for Telegram launch
- Admin dashboard shows multi-buy and variant metrics

Technical changes:
- Updated all DTOs, services, and controllers
- Fixed cart total calculation for multi-buy bundles
- Comprehensive test coverage for new functionality
- All existing tests passing with new features

Database changes:
- Migrated ProductVariations to ProductMultiBuys
- Added ProductVariants table
- Updated OrderItems to track variants

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-21 00:30:12 +01:00

81 lines
2.3 KiB
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using LittleShop.DTOs;
using LittleShop.Services;
namespace LittleShop.Controllers;
[ApiController]
[Route("api/[controller]")]
[Authorize(AuthenticationSchemes = "Bearer")]
public class ProductMultiBuysController : ControllerBase
{
private readonly IProductService _productService;
public ProductMultiBuysController(IProductService productService)
{
_productService = productService;
}
[HttpGet("product/{productId}")]
public async Task<ActionResult<IEnumerable<ProductMultiBuyDto>>> GetProductMultiBuys(Guid productId)
{
var multiBuys = await _productService.GetProductMultiBuysAsync(productId);
return Ok(multiBuys);
}
[HttpGet("{id}")]
public async Task<ActionResult<ProductMultiBuyDto>> GetProductMultiBuy(Guid id)
{
var multiBuy = await _productService.GetProductMultiBuyByIdAsync(id);
if (multiBuy == null)
return NotFound();
return Ok(multiBuy);
}
[HttpPost]
[Authorize(Roles = "Admin")]
public async Task<ActionResult<ProductMultiBuyDto>> CreateProductMultiBuy(CreateProductMultiBuyDto createMultiBuyDto)
{
try
{
var multiBuy = await _productService.CreateProductMultiBuyAsync(createMultiBuyDto);
return CreatedAtAction(nameof(GetProductMultiBuy), new { id = multiBuy.Id }, multiBuy);
}
catch (ArgumentException ex)
{
return BadRequest(ex.Message);
}
}
[HttpPut("{id}")]
[Authorize(Roles = "Admin")]
public async Task<IActionResult> UpdateProductMultiBuy(Guid id, UpdateProductMultiBuyDto updateMultiBuyDto)
{
try
{
await _productService.UpdateProductMultiBuyAsync(id, updateMultiBuyDto);
return NoContent();
}
catch (ArgumentException ex)
{
return BadRequest(ex.Message);
}
}
[HttpDelete("{id}")]
[Authorize(Roles = "Admin")]
public async Task<IActionResult> DeleteProductMultiBuy(Guid id)
{
try
{
await _productService.DeleteProductMultiBuyAsync(id);
return NoContent();
}
catch (ArgumentException ex)
{
return BadRequest(ex.Message);
}
}
}