73 lines
2.7 KiB
C#
73 lines
2.7 KiB
C#
using Managing.Application.Abstractions;
|
|
using Managing.Domain.MoneyManagements;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Managing.Api.Controllers;
|
|
|
|
/// <summary>
|
|
/// Controller for managing money management strategies.
|
|
/// Provides endpoints for creating, retrieving, updating, and deleting money management strategies.
|
|
/// Requires authorization for access and produces JSON responses.
|
|
/// </summary>
|
|
[ApiController]
|
|
[Authorize]
|
|
[Route("[controller]")]
|
|
[Produces("application/json")]
|
|
public class MoneyManagementController : ControllerBase
|
|
{
|
|
private readonly IMoneyManagementService _moneyManagementService;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="MoneyManagementController"/> class.
|
|
/// </summary>
|
|
/// <param name="moneyManagementService">The service for managing money management strategies.</param>
|
|
public MoneyManagementController(IMoneyManagementService moneyManagementService)
|
|
{
|
|
_moneyManagementService = moneyManagementService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a new money management strategy or updates an existing one.
|
|
/// </summary>
|
|
/// <param name="moneyManagement">The money management strategy to create or update.</param>
|
|
/// <returns>The created or updated money management strategy.</returns>
|
|
[HttpPost]
|
|
public async Task<ActionResult<MoneyManagement>> PostMoneyManagement(MoneyManagement moneyManagement)
|
|
{
|
|
return Ok(await _moneyManagementService.CreateOrUpdateMoneyManagement(moneyManagement));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves all money management strategies.
|
|
/// </summary>
|
|
/// <returns>A list of money management strategies.</returns>
|
|
[HttpGet]
|
|
[Route("moneymanagements")]
|
|
public ActionResult<IEnumerable<MoneyManagement>> GetMoneyManagements()
|
|
{
|
|
return Ok(_moneyManagementService.GetMoneyMangements());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Retrieves a specific money management strategy by name.
|
|
/// </summary>
|
|
/// <param name="name">The name of the money management strategy to retrieve.</param>
|
|
/// <returns>The requested money management strategy if found.</returns>
|
|
[HttpGet]
|
|
public ActionResult<MoneyManagement> GetMoneyManagement(string name)
|
|
{
|
|
return Ok(_moneyManagementService.GetMoneyMangement(name));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes a specific money management strategy by name.
|
|
/// </summary>
|
|
/// <param name="name">The name of the money management strategy to delete.</param>
|
|
/// <returns>An ActionResult indicating the outcome of the operation.</returns>
|
|
[HttpDelete]
|
|
public ActionResult DeleteMoneyManagement(string name)
|
|
{
|
|
return Ok(_moneyManagementService.DeleteMoneyManagement(name));
|
|
}
|
|
} |