Adress und shipping
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// src/Webshop.Api/Controllers/Admin/AdminShippingMethodsController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Shipping;
|
||||
using Webshop.Application.Services.Admin;
|
||||
|
||||
namespace Webshop.Api.Controllers.Admin
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/admin/shippingmethods")]
|
||||
[Authorize(Roles = "Admin")]
|
||||
public class AdminShippingMethodsController : ControllerBase
|
||||
{
|
||||
private readonly IAdminShippingMethodService _shippingMethodService;
|
||||
|
||||
public AdminShippingMethodsController(IAdminShippingMethodService shippingMethodService)
|
||||
{
|
||||
_shippingMethodService = shippingMethodService;
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<ShippingMethodDto>> CreateShippingMethod([FromBody] ShippingMethodDto shippingMethodDto)
|
||||
{
|
||||
// Implementierung im AdminShippingMethodService
|
||||
var createdMethod = await _shippingMethodService.CreateAsync(shippingMethodDto);
|
||||
return CreatedAtAction(nameof(GetShippingMethodById), new { id = createdMethod.Id }, createdMethod);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ActionResult<ShippingMethodDto>> GetShippingMethodById(Guid id)
|
||||
{
|
||||
// ...
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Webshop.Api/Controllers/Customers/AddressesController.cs
Normal file
45
Webshop.Api/Controllers/Customers/AddressesController.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
// src/Webshop.Api/Controllers/Customer/AddressesController.cs
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
using Webshop.Application.DTOs.Customers;
|
||||
using Webshop.Application.Services.Customers;
|
||||
|
||||
namespace Webshop.Api.Controllers.Customer
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/v1/customer/addresses")]
|
||||
[Authorize(Roles = "Customer")]
|
||||
public class AddressesController : ControllerBase
|
||||
{
|
||||
private readonly IAddressService _addressService;
|
||||
|
||||
public AddressesController(IAddressService addressService)
|
||||
{
|
||||
_addressService = addressService;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<ActionResult<IEnumerable<AddressDto>>> GetMyAddresses()
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var addresses = await _addressService.GetMyAddressesAsync(userId);
|
||||
return Ok(addresses);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<ActionResult<AddressDto>> CreateAddress([FromBody] CreateAddressDto addressDto)
|
||||
{
|
||||
var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
|
||||
var (createdAddress, errorMessage) = await _addressService.CreateAddressAsync(addressDto, userId);
|
||||
|
||||
if (createdAddress == null) return BadRequest(new { Message = errorMessage });
|
||||
|
||||
// Annahme: Es gibt eine GetMyAddressById-Methode
|
||||
return CreatedAtAction(nameof(GetMyAddresses), new { id = createdAddress.Id }, createdAddress);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,7 +84,7 @@ builder.Services.AddScoped<IPaymentMethodRepository, PaymentMethodRepository>();
|
||||
builder.Services.AddScoped<ICategoryRepository, CategoryRepository>();
|
||||
builder.Services.AddScoped<IOrderRepository, OrderRepository>();
|
||||
builder.Services.AddScoped<IShippingMethodRepository, ShippingMethodRepository>();
|
||||
|
||||
builder.Services.AddScoped<IAddressRepository, AddressRepository>();
|
||||
// AUTH Services
|
||||
builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
|
||||
@@ -101,6 +101,7 @@ builder.Services.AddScoped<IAdminSupplierService, AdminSupplierService>();
|
||||
builder.Services.AddScoped<IAdminPaymentMethodService, AdminPaymentMethodService>();
|
||||
builder.Services.AddScoped<IAdminCategoryService, AdminCategoryService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
builder.Services.AddScoped<IAdminOrderService, AdminOrderService>();
|
||||
builder.Services.AddScoped<IAdminShippingMethodService, AdminShippingMethodService>();
|
||||
|
||||
//builder.Services.AddScoped<IAdminDiscountService, AdminDiscountService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
builder.Services.AddScoped<IAdminOrderService, AdminOrderService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
@@ -109,6 +110,7 @@ builder.Services.AddScoped<IAdminOrderService, AdminOrderService>(); // Hinzugef
|
||||
// CUSTOMER Services (sp<73>ter Implementierungen hinzuf<75>gen)
|
||||
builder.Services.AddScoped<ICustomerService, CustomerService>();
|
||||
builder.Services.AddScoped<IOrderService, OrderService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
builder.Services.AddScoped<IAddressService, AddressService>();
|
||||
//builder.Services.AddScoped<ICheckoutService, CheckoutService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
//builder.Services.AddScoped<IReviewService, ReviewService>(); // Hinzugef<65>gt f<>r Konsistenz
|
||||
|
||||
|
||||
Reference in New Issue
Block a user