2023-10-27 01:33:28 +00:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-11-04 20:05:55 +00:00
|
|
|
|
using tcc_app.Models;
|
2023-10-27 01:33:28 +00:00
|
|
|
|
|
|
|
|
|
namespace TCC.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("simulation")]
|
|
|
|
|
public class SimulationController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
public SimulationController()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("harmonic-progression")]
|
|
|
|
|
public async Task<IActionResult> GetHarmonicProgression([FromQuery] int n)
|
|
|
|
|
{
|
2023-11-02 22:14:16 +00:00
|
|
|
|
double sum = 0;
|
2023-10-27 01:33:28 +00:00
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
|
{
|
|
|
|
|
sum += 1.0f / i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok(sum);
|
|
|
|
|
}
|
2023-10-29 22:01:13 +00:00
|
|
|
|
|
2023-11-04 20:05:55 +00:00
|
|
|
|
[HttpPost("json")]
|
|
|
|
|
public async Task<IActionResult> PostJson([FromBody] PersonJson person)
|
2023-10-29 22:01:13 +00:00
|
|
|
|
{
|
2023-11-04 20:05:55 +00:00
|
|
|
|
return Ok(person);
|
2023-10-29 22:01:13 +00:00
|
|
|
|
}
|
2023-11-02 22:14:16 +00:00
|
|
|
|
|
|
|
|
|
[HttpPost("protobuf")]
|
|
|
|
|
public async Task<IActionResult> PostProtobuf()
|
|
|
|
|
{
|
2023-11-04 20:05:55 +00:00
|
|
|
|
PersonProto person;
|
2023-11-02 22:14:16 +00:00
|
|
|
|
byte[] response;
|
|
|
|
|
using (var stream = Request.BodyReader.AsStream())
|
|
|
|
|
{
|
2023-11-04 20:05:55 +00:00
|
|
|
|
person = ProtoBuf.Serializer.Deserialize<PersonProto>(stream);
|
2023-11-02 22:14:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var stream = new MemoryStream())
|
|
|
|
|
{
|
2023-11-04 20:05:55 +00:00
|
|
|
|
ProtoBuf.Serializer.Serialize(stream, person);
|
2023-11-02 22:14:16 +00:00
|
|
|
|
response = stream.ToArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await Response.Body.WriteAsync(response, 0, response.Length);
|
|
|
|
|
return new EmptyResult();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-27 01:33:28 +00:00
|
|
|
|
}
|