69 lines
1.7 KiB
C#
69 lines
1.7 KiB
C#
using CatherineLynwood.Models;
|
|
using CatherineLynwood.Services;
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CatherineLynwood.Controllers
|
|
{
|
|
|
|
[ApiController]
|
|
[Route("api/support")]
|
|
public class SupportController : ControllerBase
|
|
{
|
|
private DataAccess _dataAccess;
|
|
|
|
public record FlagDto(string Country);
|
|
|
|
public class SubscriptionDto
|
|
{
|
|
public string Name { get; set; }
|
|
public string Email { get; set; }
|
|
}
|
|
|
|
|
|
public SupportController(DataAccess dataAccess)
|
|
{
|
|
_dataAccess = dataAccess;
|
|
}
|
|
|
|
[HttpPost("flag")]
|
|
public async Task<IActionResult> Flag([FromBody] FlagDto dto)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dto?.Country))
|
|
return BadRequest(new { ok = false, error = "Country required" });
|
|
|
|
// TODO: replace with real DB call
|
|
var total = await _dataAccess.SaveFlagClick(dto.Country);
|
|
|
|
return Ok(new { ok = true, total });
|
|
}
|
|
|
|
[HttpPost("subscribe")]
|
|
public IActionResult Subscribe([FromBody] SubscriptionDto dto)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(dto?.Email))
|
|
return BadRequest(new { ok = false, error = "Email required" });
|
|
|
|
Contact contact = new Contact
|
|
{
|
|
EmailAddress = dto.Email,
|
|
Name = dto.Name
|
|
};
|
|
|
|
var ok = _dataAccess.SaveContact(contact, true);
|
|
|
|
return Ok(new { ok });
|
|
}
|
|
|
|
// ----- Dummy persistence you can swap for EF/Dapper calls -----
|
|
|
|
|
|
private static bool SaveSubscription(string email, string country)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
}
|