/
renix
/
TravelGuide
Обзор
Документация
Войти
/
renix
/
TravelGuide
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
back/Controllers/OpenRouteController.cs
74 строки
2 KB
atikinvobud
Alghorithm
09 апр 2025, 23:04
09 апр 2025, 23:04
74b8200
Код
Авторство
О чём код?
//using back.DTOs.CityDTO; using back.DTOs.OpenRouteDTO; using back.Extensions; using back.Models; using back.Models.Entities; using back.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System.Text.Json; namespace back.Controllers; [ApiController] [Route("routes")] [Authorize] public class OpenRouteController : ControllerBase { private readonly OpenRouteService openRouteService; private readonly MatrixService matrixService; public OpenRouteController(OpenRouteService openRouteService, MatrixService matrixService) { this.openRouteService = openRouteService; this.matrixService = matrixService; } [HttpPost("get")] public async Task<IActionResult> Get([FromBody] GetOpenRouteDTO dto) { return Ok(await openRouteService.GetRouteAsync(dto.startLatitude, dto.startLontitude, dto.endLatitude, dto.endLontitude)); } [HttpPost("geocoder/{name}")] public async Task<IActionResult> Geocode([FromRoute] string name) { var (latitude, lontitude) = await openRouteService.GeoCodeAsync(name); return Ok(new { latitude, lontitude }); } [HttpGet("reversegeocoder/{latitude}/{longtitude}")] public async Task<IActionResult> ReverseGeocode([FromRoute] double latitude, [FromRoute] double longtitude) { return Ok(await openRouteService.ReverseGeocodeAsync(latitude, longtitude)); } [HttpPost("/matrix")] public async Task<IActionResult> Matrix() { await openRouteService.GetDistMatrix(); return Ok(); } [HttpPost("/add/{latitude}/{longtitude}")] public async Task<IActionResult> Add([FromRoute] double latitude, [FromRoute] double longtitude) { await openRouteService.AddLandmark(latitude, longtitude); return Ok(); } [HttpGet("/matrix")] public IActionResult GetDistanceMatrix() { var matrix = matrixService.GetDistanceMatrixAsync(); if (matrix == null || matrix.Count == 0) { return NotFound(new { message = "Distance matrix not found" }); } return Ok(new { matrix }); } [HttpDelete("/del")] public async Task Delete() { await matrixService.DeleteMatrixAsync(1); } }