checkout
This commit is contained in:
@@ -4,9 +4,11 @@ using Microsoft.AspNetCore.Authorization;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.Services.Customers.Interfaces;
|
||||
using Webshop.Application.DTOs.Orders;
|
||||
using Webshop.Application.DTOs.Shipping; // Neu
|
||||
using System.Security.Claims;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Webshop.Application;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Webshop.Api.Controllers.Customer
|
||||
{
|
||||
@@ -22,11 +24,26 @@ namespace Webshop.Api.Controllers.Customer
|
||||
_checkoutService = checkoutService;
|
||||
}
|
||||
|
||||
// --- NEU: Endpoint um verf<72>gbare Versandmethoden basierend auf dem Warenkorb zu holen ---
|
||||
[HttpPost("available-shipping-methods")]
|
||||
[ProducesResponseType(typeof(IEnumerable<ShippingMethodDto>), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> GetAvailableShippingMethods([FromBody] ShippingCalculationRequestDto request)
|
||||
{
|
||||
var result = await _checkoutService.GetCompatibleShippingMethodsAsync(request.Items);
|
||||
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => Ok(result.Value),
|
||||
ServiceResultType.InvalidInput => BadRequest(new { Message = result.ErrorMessage }),
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = "Fehler beim Laden der Versandmethoden." })
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPost("create-order")]
|
||||
[ProducesResponseType(typeof(OrderDetailDto), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status403Forbidden)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status409Conflict)]
|
||||
public async Task<IActionResult> CreateOrder([FromBody] CreateOrderDto orderDto)
|
||||
{
|
||||
@@ -35,7 +52,6 @@ namespace Webshop.Api.Controllers.Customer
|
||||
return BadRequest(ModelState);
|
||||
}
|
||||
|
||||
// UserId aus dem JWT-Token des eingeloggten Kunden extrahieren
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
if (string.IsNullOrEmpty(userId))
|
||||
{
|
||||
@@ -50,7 +66,7 @@ namespace Webshop.Api.Controllers.Customer
|
||||
ServiceResultType.InvalidInput => BadRequest(new { Message = result.ErrorMessage }),
|
||||
ServiceResultType.Conflict => Conflict(new { Message = result.ErrorMessage }),
|
||||
ServiceResultType.Unauthorized => Unauthorized(new { Message = result.ErrorMessage }),
|
||||
ServiceResultType.Forbidden => Forbid(), // Forbid returns 403 without a body
|
||||
ServiceResultType.Forbidden => Forbid(),
|
||||
_ => StatusCode(StatusCodes.Status500InternalServerError, new { Message = result.ErrorMessage ?? "Ein unerwarteter Fehler ist aufgetreten." })
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ using System.Text.Json.Serialization;
|
||||
|
||||
// --- Eigene Namespaces ---
|
||||
using Webshop.Api.SwaggerFilters;
|
||||
using Webshop.Application.DTOs.Email;
|
||||
using Webshop.Application.Services.Admin;
|
||||
using Webshop.Application.Services.Admin.Interfaces;
|
||||
using Webshop.Application.Services.Auth;
|
||||
@@ -111,8 +112,9 @@ builder.Services.Configure<ResendClientOptions>(options =>
|
||||
options.ApiToken = builder.Configuration["Resend:ApiToken"]!;
|
||||
});
|
||||
builder.Services.AddTransient<IResend, ResendClient>();
|
||||
builder.Services.Configure<EmailSettings>(builder.Configuration.GetSection("EmailSettings"));
|
||||
|
||||
// Repositories
|
||||
// --- Repositories ---
|
||||
builder.Services.AddScoped<IProductRepository, ProductRepository>();
|
||||
builder.Services.AddScoped<ISupplierRepository, SupplierRepository>();
|
||||
builder.Services.AddScoped<ICustomerRepository, CustomerRepository>();
|
||||
@@ -121,17 +123,32 @@ builder.Services.AddScoped<ICategorieRepository, CategorieRepository>();
|
||||
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
|
||||
builder.Services.AddScoped<IShippingMethodRepository, ShippingMethodRepository>();
|
||||
builder.Services.AddScoped<IAddressRepository, AddressRepository>();
|
||||
builder.Services.AddScoped<IDiscountRepository, DiscountRepository>();
|
||||
builder.Services.AddScoped<IDiscountRepository, DiscountRepository>(); // War doppelt
|
||||
builder.Services.AddScoped<ISettingRepository, SettingRepository>();
|
||||
builder.Services.AddScoped<IShopInfoRepository, ShopInfoRepository>();
|
||||
builder.Services.AddScoped<IDiscountRepository, DiscountRepository>();
|
||||
builder.Services.AddScoped<IReviewRepository, ReviewRepository>();
|
||||
|
||||
// Services
|
||||
// --- Services ---
|
||||
// Public & Core
|
||||
builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
builder.Services.AddScoped<IProductService, ProductService>();
|
||||
builder.Services.AddScoped<IPaymentMethodService, PaymentMethodService>();
|
||||
builder.Services.AddScoped<ICategorieService, CategorieService>();
|
||||
builder.Services.AddScoped<IPaymentMethodService, PaymentMethodService>();
|
||||
builder.Services.AddScoped<IShopInfoService, ShopInfoService>();
|
||||
builder.Services.AddScoped<ISettingService, SettingService>();
|
||||
builder.Services.AddScoped<IDiscountService, DiscountService>();
|
||||
builder.Services.AddScoped<IReviewService, ReviewService>();
|
||||
builder.Services.AddScoped<IEmailService, EmailService>(); // WICHTIG: F<>r Auth & Checkout
|
||||
|
||||
// Customer Scope
|
||||
builder.Services.AddScoped<ICustomerService, CustomerService>();
|
||||
builder.Services.AddScoped<IOrderService, OrderService>();
|
||||
builder.Services.AddScoped<IAddressService, AddressService>();
|
||||
builder.Services.AddScoped<ICheckoutService, CheckoutService>(); // War doppelt
|
||||
builder.Services.AddScoped<ICartService, CartService>(); // WICHTIG: F<>r Checkout Cleanup
|
||||
builder.Services.AddScoped<ICustomerReviewService, CustomerReviewService>();
|
||||
|
||||
// Admin Scope
|
||||
builder.Services.AddScoped<IAdminUserService, AdminUserService>();
|
||||
builder.Services.AddScoped<IAdminProductService, AdminProductService>();
|
||||
builder.Services.AddScoped<IAdminSupplierService, AdminSupplierService>();
|
||||
@@ -139,21 +156,9 @@ builder.Services.AddScoped<IAdminPaymentMethodService, AdminPaymentMethodService
|
||||
builder.Services.AddScoped<IAdminCategorieService, AdminCategorieService>();
|
||||
builder.Services.AddScoped<IAdminOrderService, AdminOrderService>();
|
||||
builder.Services.AddScoped<IAdminShippingMethodService, AdminShippingMethodService>();
|
||||
builder.Services.AddScoped<IAdminDiscountService, AdminDiscountService>();
|
||||
builder.Services.AddScoped<IAdminSettingService, AdminSettingService>();
|
||||
builder.Services.AddScoped<ICustomerService, CustomerService>();
|
||||
builder.Services.AddScoped<IOrderService, OrderService>();
|
||||
builder.Services.AddScoped<IAddressService, AddressService>();
|
||||
builder.Services.AddScoped<ICheckoutService, CheckoutService>();
|
||||
builder.Services.AddScoped<IAdminDiscountService, AdminDiscountService>(); // War doppelt
|
||||
builder.Services.AddScoped<IAdminSettingService, AdminSettingService>(); // War doppelt
|
||||
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>();
|
||||
builder.Services.AddScoped<ICheckoutService, CheckoutService>();
|
||||
builder.Services.AddScoped<IDiscountService, DiscountService>();
|
||||
builder.Services.AddScoped<IReviewService, ReviewService>();
|
||||
builder.Services.AddScoped<ICustomerReviewService, CustomerReviewService>();
|
||||
builder.Services.AddScoped<IAdminReviewService, AdminReviewService>();
|
||||
builder.Services.AddScoped<IAdminAnalyticsService, AdminAnalyticsService>();
|
||||
builder.Services.AddScoped<IAdminAddressService, AdminAddressService>();
|
||||
|
||||
Reference in New Issue
Block a user