using Managing.Application.Abstractions;
using Managing.Domain.MoneyManagements;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace Managing.Api.Controllers;
///
/// 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.
///
[ApiController]
[Authorize]
[Route("[controller]")]
[Produces("application/json")]
public class MoneyManagementController : ControllerBase
{
private readonly IMoneyManagementService _moneyManagementService;
///
/// Initializes a new instance of the class.
///
/// The service for managing money management strategies.
public MoneyManagementController(IMoneyManagementService moneyManagementService)
{
_moneyManagementService = moneyManagementService;
}
///
/// Creates a new money management strategy or updates an existing one.
///
/// The money management strategy to create or update.
/// The created or updated money management strategy.
[HttpPost]
public async Task> PostMoneyManagement(MoneyManagement moneyManagement)
{
return Ok(await _moneyManagementService.CreateOrUpdateMoneyManagement(moneyManagement));
}
///
/// Retrieves all money management strategies.
///
/// A list of money management strategies.
[HttpGet]
[Route("moneymanagements")]
public ActionResult> GetMoneyManagements()
{
return Ok(_moneyManagementService.GetMoneyMangements());
}
///
/// Retrieves a specific money management strategy by name.
///
/// The name of the money management strategy to retrieve.
/// The requested money management strategy if found.
[HttpGet]
public ActionResult GetMoneyManagement(string name)
{
return Ok(_moneyManagementService.GetMoneyMangement(name));
}
///
/// Deletes a specific money management strategy by name.
///
/// The name of the money management strategy to delete.
/// An ActionResult indicating the outcome of the operation.
[HttpDelete]
public ActionResult DeleteMoneyManagement(string name)
{
return Ok(_moneyManagementService.DeleteMoneyManagement(name));
}
}