SoftTraderBackend/Controller/UserInterestController.cs
2026-03-20 10:42:48 -04:00

66 lines
1.4 KiB
C#

using Backend.DatabaseHandler;
using Backend.UserInterests;
using Microsoft.AspNetCore.Mvc;
namespace Backend.Controllers;
[ApiController]
[Route("api/user-interest")]
public sealed class UserInterestController : ControllerBase
{
private readonly IUserInterestStore _store;
public UserInterestController(IUserInterestStore store)
{
_store = store;
}
[HttpGet("fetch")]
public async Task<ActionResult<UserInterestFetchResponse>> FetchAll(
[FromQuery] string user,
[FromQuery] string type)
{
try
{
List<string> items = await _store.FetchAllAsync(user, type);
return Ok(new UserInterestFetchResponse
{
Items = items
});
}
catch (ArgumentException ex)
{
return BadRequest(ex.Message);
}
}
[HttpPost("add")]
public async Task<ActionResult<BoolResponse>> Add(
[FromBody] UserInterestModifyRequest request)
{
try
{
bool success = await _store.AddAsync(request.User, request.Type, request.Value);
return Ok(new BoolResponse { Success = success });
}
catch (ArgumentException ex)
{
return BadRequest(ex.Message);
}
}
[HttpDelete("remove")]
public async Task<ActionResult<BoolResponse>> Remove(
[FromBody] UserInterestModifyRequest request)
{
try
{
bool success = await _store.RemoveAsync(request.User, request.Type, request.Value);
return Ok(new BoolResponse { Success = success });
}
catch (ArgumentException ex)
{
return BadRequest(ex.Message);
}
}
}