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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user