Notes/Controllers/ApiController.cs

37 lines
738 B
C#
Raw Normal View History

2023-01-05 15:32:21 +00:00
using BinaryDad.Notes.Services;
using Microsoft.AspNetCore.Mvc;
2022-11-29 15:14:15 +00:00
namespace BinaryDad.Notes.Controllers;
[ApiController]
[Route("[controller]")]
public class ApiController : ControllerBase
{
2023-01-05 15:32:21 +00:00
private readonly INoteService noteService;
2022-11-29 15:14:15 +00:00
2023-01-05 15:32:21 +00:00
public ApiController(INoteService noteService)
2022-11-29 15:14:15 +00:00
{
2023-01-05 15:32:21 +00:00
this.noteService = noteService;
2022-11-29 15:14:15 +00:00
}
2023-01-09 20:54:20 +00:00
[HttpGet]
[Route("get")]
public string Get() => noteService.Get();
2022-11-29 15:14:15 +00:00
[HttpPost]
[Route("save")]
public async Task<bool> Save()
{
var content = string.Empty;
using (var reader = new StreamReader(Request.Body))
{
content = await reader.ReadToEndAsync();
}
2023-01-05 15:32:21 +00:00
noteService.Save(content);
2022-11-29 15:14:15 +00:00
return true;
}
}