discount und summary
This commit is contained in:
@@ -1,18 +1,98 @@
|
||||
// Auto-generiert von CreateWebshopFiles.ps1
|
||||
// src/Webshop.Api/Controllers/Admin/AdminDiscountsController.cs
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Discounts;
|
||||
using Webshop.Application.Services.Admin.Interfaces;
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// API-Endpunkte zur Verwaltung von Rabatten und Gutscheincodes.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminDiscountsController : ControllerBase
|
||||
{
|
||||
private readonly IAdminDiscountService _adminDiscountService;
|
||||
|
||||
public AdminDiscountsController(IAdminDiscountService adminDiscountService)
|
||||
{
|
||||
_adminDiscountService = adminDiscountService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ruft eine Liste aller konfigurierten Rabatte ab.
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<DiscountDto>>> GetAllDiscounts()
|
||||
{
|
||||
var discounts = await _adminDiscountService.GetAllDiscountsAsync();
|
||||
return Ok(discounts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ruft einen einzelnen Rabatt anhand seiner eindeutigen ID ab.
|
||||
/// </summary>
|
||||
/// <param name="id">Die ID des Rabatts.</param>
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<DiscountDto>> GetDiscountById(Guid id)
|
||||
{
|
||||
var discount = await _adminDiscountService.GetDiscountByIdAsync(id);
|
||||
if (discount == null) return NotFound();
|
||||
return Ok(discount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Erstellt einen neuen Rabatt.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// **Funktionsweise von Rabatten:**
|
||||
/// - **DiscountType:** 'Percentage' (z.B. 10 f<>r 10%) oder 'FixedAmount' (z.B. 5 f<>r 5,00<30>).
|
||||
/// - **CouponCode:** Wenn `requiresCouponCode` auf `true` gesetzt ist, muss ein eindeutiger `couponCode` angegeben werden.
|
||||
/// - **G<>ltigkeit:** Kann durch `startDate` und `endDate` zeitlich begrenzt werden.
|
||||
/// - **Zuweisung:** Der Rabatt kann entweder bestimmten Produkten (`assignedProductIds`) oder ganzen Kategorien (`assignedCategoryIds`) zugewiesen werden. Wenn beide Listen leer sind, gilt der Rabatt f<>r den gesamten Warenkorb (sofern `minimumOrderAmount` erreicht ist).
|
||||
/// </remarks>
|
||||
/// <param name="discountDto">Das Datenobjekt des zu erstellenden Rabatts.</param>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<DiscountDto>> CreateDiscount([FromBody] DiscountDto discountDto)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
var createdDiscount = await _adminDiscountService.CreateDiscountAsync(discountDto);
|
||||
return CreatedAtAction(nameof(GetDiscountById), new { id = createdDiscount.Id }, createdDiscount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aktualisiert einen bestehenden Rabatt.
|
||||
/// </summary>
|
||||
/// <param name="id">Die ID des zu aktualisierenden Rabatts.</param>
|
||||
/// <param name="discountDto">Die neuen Daten f<>r den Rabatt.</param>
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateDiscount(Guid id, [FromBody] DiscountDto discountDto)
|
||||
{
|
||||
if (id != discountDto.Id) return BadRequest();
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var success = await _adminDiscountService.UpdateDiscountAsync(discountDto);
|
||||
if (!success) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// L<>scht einen Rabatt.
|
||||
/// </summary>
|
||||
/// <param name="id">Die ID des zu l<>schenden Rabatts.</param>
|
||||
[HttpDelete("{id}")]
|
||||
public async Task<IActionResult> DeleteDiscount(Guid id)
|
||||
{
|
||||
var success = await _adminDiscountService.DeleteDiscountAsync(id);
|
||||
if (!success) return NotFound();
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@ using Webshop.Application.Services.Admin;
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
{
|
||||
/// <summary>
|
||||
/// API-Endpunkte zur Verwaltung der zentralen Shop-Stammdaten.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/[controller]")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
@@ -19,6 +22,12 @@ namespace Webshop.Api.Controllers.Admin
|
||||
_shopInfoService = shopInfoService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ruft die aktuellen Stammdaten des Shops ab.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Diese Daten werden typischerweise in einem "Stammdaten"- oder "Shop-Einstellungen"-Formular im Admin-Dashboard angezeigt.
|
||||
/// </remarks>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<AdminShopInfoDto>> GetShopInfo()
|
||||
{
|
||||
@@ -26,6 +35,13 @@ namespace Webshop.Api.Controllers.Admin
|
||||
return Ok(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aktualisiert die zentralen Stammdaten des Shops.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Sendet das gesamte, ausgefüllte DTO. Alle Felder werden überschrieben.
|
||||
/// </remarks>
|
||||
/// <param name="shopInfoDto">Das Datenobjekt mit den neuen Shop-Informationen.</param>
|
||||
[HttpPut]
|
||||
public async Task<IActionResult> UpdateShopInfo([FromBody] AdminShopInfoDto shopInfoDto)
|
||||
{
|
||||
|
||||
@@ -7,6 +7,9 @@ using Webshop.Application.Services.Public;
|
||||
|
||||
namespace Webshop.Api.Controllers.Public
|
||||
{
|
||||
/// <summary>
|
||||
/// API-Endpunkte zum Abrufen öffentlicher Shop-Informationen.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/v1/public/[controller]")]
|
||||
[AllowAnonymous]
|
||||
@@ -19,6 +22,12 @@ namespace Webshop.Api.Controllers.Public
|
||||
_shopInfoService = shopInfoService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ruft die öffentlichen Stammdaten des Shops ab.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Diese Informationen sind für jeden Besucher sichtbar und werden typischerweise im Footer, auf der Kontaktseite oder im Impressum verwendet.
|
||||
/// </remarks>
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<PublicShopInfoDto>> GetPublicShopInfo()
|
||||
{
|
||||
|
||||
@@ -103,9 +103,12 @@ builder.Services.AddScoped<IOrderRepository, OrderRepository>();
|
||||
builder.Services.AddScoped<IShippingMethodRepository, ShippingMethodRepository>();
|
||||
builder.Services.AddScoped<IAddressRepository, AddressRepository>();
|
||||
builder.Services.AddScoped<IDiscountRepository, DiscountRepository>();
|
||||
builder.Services.AddScoped<IReviewRepository, ReviewRepository>();
|
||||
builder.Services.AddScoped<ISettingRepository, SettingRepository>();
|
||||
builder.Services.AddScoped<IShopInfoRepository, ShopInfoRepository>();
|
||||
builder.Services.AddScoped<IDiscountRepository, DiscountRepository>();
|
||||
|
||||
//fehlt noch
|
||||
builder.Services.AddScoped<IReviewRepository, ReviewRepository>();
|
||||
|
||||
// Services
|
||||
builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
@@ -125,11 +128,14 @@ builder.Services.AddScoped<ICustomerService, CustomerService>();
|
||||
builder.Services.AddScoped<IOrderService, OrderService>();
|
||||
builder.Services.AddScoped<IAddressService, AddressService>();
|
||||
builder.Services.AddScoped<ICheckoutService, CheckoutService>();
|
||||
builder.Services.AddScoped<IReviewService, ReviewService>();
|
||||
builder.Services.AddScoped<IAdminShopInfoService, AdminShopInfoService>();
|
||||
builder.Services.AddScoped<IShopInfoService, ShopInfoService>();
|
||||
builder.Services.AddScoped<ISettingService, SettingService>();
|
||||
builder.Services.AddScoped<IAdminSettingService, AdminSettingService>();
|
||||
builder.Services.AddScoped<IAdminDiscountService, AdminDiscountService>();
|
||||
|
||||
//fehlt noch
|
||||
builder.Services.AddScoped<IReviewService, ReviewService>();
|
||||
|
||||
|
||||
// Controller und API-Infrastruktur
|
||||
|
||||
Reference in New Issue
Block a user