Добавил поиск аудиторий и обработку ошибок от вышестоящего сервиса
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 4m30s

This commit is contained in:
2025-09-09 17:00:57 +03:00
parent 82e7d92584
commit 428ee1d388
4 changed files with 67 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
# Прокси для расписания в Modeus
## TODO
- [x] Добавить RateLimiter
- [ ] Добавить обработку ошибок при запросах к modeus
- [x] Добавить обработку ошибок при запросах к modeus

View File

@@ -1,3 +1,4 @@
using System.Net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
@@ -8,8 +9,9 @@ namespace SfeduSchedule.Controllers
[ApiController]
[Route("api/[controller]")]
[EnableRateLimiting("throttle")]
public class ScheduleController(ModeusService modeusService) : ControllerBase
public class ScheduleController(ModeusService modeusService, ILogger<ScheduleController> logger) : ControllerBase
{
/// <summary>
/// Получить расписание для указанных пользователей.
/// </summary>
@@ -39,10 +41,43 @@ namespace SfeduSchedule.Controllers
[HttpPost]
public async Task<IActionResult> Post([FromBody] ModeusScheduleRequest request)
{
var schedule = await modeusService.GetScheduleAsync(request);
string? schedule;
try
{
schedule = await modeusService.GetScheduleAsync(request);
}
catch (HttpRequestException e)
{
logger.LogError(e, "Ошибка при получении расписания");
return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), e.Message);
}
return Ok(schedule);
}
/// <summary>
/// Поиск аудиторий по пользовательскому запросу.
/// </summary>
/// <param name="request">Объект запроса, содержащий параметры фильтрации аудиторий.</param>
/// <returns>Список аудиторий.</returns>
/// <response code="200">Возвращает список аудиторий</response>
/// <response code="429">Слишком много запросов</response>
[HttpPost]
[Route("rooms/search")]
public async Task<IActionResult> SearchRooms([FromBody] RoomSearchRequest request)
{
string? rooms;
try
{
rooms = await modeusService.SearchRoomsAsync(request);
}
catch (HttpRequestException e)
{
logger.LogError(e, "Ошибка при поиске аудиторий");
return StatusCode((int)(e.StatusCode ?? HttpStatusCode.InternalServerError), e.Message);
}
return Ok(rooms);
}
/// <summary>
/// Получить GUID пользователя по полному имени. (требуется авторизация)
/// </summary>
@@ -53,7 +88,7 @@ namespace SfeduSchedule.Controllers
/// <response code="401">Неавторизованный</response>
[HttpGet]
[Authorize(AuthenticationSchemes = "ApiKey")]
[Route("GetGuid")]
[Route("getguid")]
public async Task<IActionResult> GetGuid(string fullname)
{
var guid = await modeusService.GetGuidAsync(fullname);

View File

@@ -1,3 +1,5 @@
using System.ComponentModel;
namespace SfeduSchedule
{
public class ModeusScheduleRequest(int size, DateTime timeMin, DateTime timeMax, List<Guid> attendeePersonId)
@@ -7,4 +9,19 @@ namespace SfeduSchedule
public DateTime TimeMax { get; set; } = timeMax;
public List<Guid> AttendeePersonId { get; set; } = attendeePersonId;
}
public class RoomSearchRequest
{
[DefaultValue("")]
public string Name { get; set; } = "";
[DefaultValue("+building.name,+name")]
public string Sort { get; set; } = "+building.name,+name";
[DefaultValue(10)]
public int Size { get; set; } = 10;
[DefaultValue(0)]
public int Page { get; set; } = 0;
[DefaultValue(false)]
public bool Deleted { get; set; } = false;
public RoomSearchRequest() {}
}
}

View File

@@ -31,6 +31,16 @@ namespace SfeduSchedule.Services
return await response.Content.ReadAsStringAsync();
}
public async Task<string?> SearchRoomsAsync(RoomSearchRequest requestDto)
{
var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/campus/rooms/search");
request.Content = new StringContent(JsonSerializer.Serialize(requestDto, _options), System.Text.Encoding.UTF8, "application/json");
var response = await _httpClient.SendAsync(request);
_logger.LogInformation("SearchRoomsAsync: Ответ получен: {StatusCode}", response.StatusCode);
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
public async Task<string?> GetGuidAsync(string fullName)
{
var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/people/persons/search");