adminaddre
This commit is contained in:
@@ -23,71 +23,58 @@ namespace Webshop.Api.Controllers.Admin
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(IEnumerable<AddressDto>), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> GetAllAddresses()
|
||||
public async Task<IActionResult> GetAllUnlinkedAddresses()
|
||||
{
|
||||
var result = await _adminAddressService.GetAllAddressesAsync();
|
||||
var result = await _adminAddressService.GetAllUnlinkedAddressesAsync();
|
||||
return Ok(result.Value);
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(AddressDto), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> GetAddressById(Guid id)
|
||||
{
|
||||
var result = await _adminAddressService.GetAddressByIdAsync(id);
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => Ok(result.Value),
|
||||
ServiceResultType.Forbidden => Forbid(),
|
||||
_ => NotFound(new { Message = result.ErrorMessage })
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPost("customer/{customerId}")]
|
||||
[ProducesResponseType(typeof(AddressDto), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> CreateAddressForCustomer(Guid customerId, [FromBody] CreateAddressDto addressDto)
|
||||
[HttpPost] // Route vereinfacht, da keine customerId mehr benötigt wird
|
||||
public async Task<IActionResult> CreateAddress([FromBody] CreateAddressDto addressDto)
|
||||
{
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var result = await _adminAddressService.CreateAddressForCustomerAsync(addressDto, customerId);
|
||||
|
||||
var result = await _adminAddressService.CreateAddressAsync(addressDto);
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => CreatedAtAction(nameof(GetAddressById), new { id = result.Value!.Id }, result.Value),
|
||||
ServiceResultType.NotFound => NotFound(new { Message = result.ErrorMessage }),
|
||||
_ => BadRequest(new { Message = result.ErrorMessage })
|
||||
};
|
||||
}
|
||||
|
||||
[HttpPut("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> UpdateAddress(Guid id, [FromBody] UpdateAddressDto addressDto)
|
||||
{
|
||||
if (id != addressDto.Id) return BadRequest(new { Message = "ID in URL und Body stimmen nicht überein." });
|
||||
if (id != addressDto.Id) return BadRequest("ID in URL und Body stimmen nicht überein.");
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
var result = await _adminAddressService.UpdateAddressAsync(addressDto);
|
||||
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => NoContent(),
|
||||
ServiceResultType.Forbidden => Forbid(),
|
||||
_ => NotFound(new { Message = result.ErrorMessage })
|
||||
};
|
||||
}
|
||||
|
||||
[HttpDelete("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> DeleteAddress(Guid id)
|
||||
{
|
||||
var result = await _adminAddressService.DeleteAddressAsync(id);
|
||||
return result.Type switch
|
||||
{
|
||||
ServiceResultType.Success => NoContent(),
|
||||
ServiceResultType.Forbidden => Forbid(),
|
||||
_ => NotFound(new { Message = result.ErrorMessage })
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user