// 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/[controller]")] [Authorize(Roles = "Customer")] public class AddressesController : ControllerBase { private readonly IAddressService _addressService; public AddressesController(IAddressService addressService) { _addressService = addressService; } [HttpGet] public async Task>> GetMyAddresses() { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier); var addresses = await _addressService.GetMyAddressesAsync(userId); return Ok(addresses); } [HttpPost] public async Task> 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 }); return CreatedAtAction(nameof(GetMyAddresses), new { id = createdAddress.Id }, createdAddress); } } }