Notes/Controllers/ApiController.cs
2023-01-09 15:54:20 -05:00

37 lines
738 B
C#

using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Mvc;
namespace BinaryDad.Notes.Controllers;
[ApiController]
[Route("[controller]")]
public class ApiController : ControllerBase
{
private readonly INoteService noteService;
public ApiController(INoteService noteService)
{
this.noteService = noteService;
}
[HttpGet]
[Route("get")]
public string Get() => noteService.Get();
[HttpPost]
[Route("save")]
public async Task<bool> Save()
{
var content = string.Empty;
using (var reader = new StreamReader(Request.Body))
{
content = await reader.ReadToEndAsync();
}
noteService.Save(content);
return true;
}
}