Добавил поиск аудиторий и обработку ошибок от вышестоящего сервиса
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 4m30s
All checks were successful
Create and publish a Docker image / Publish image (push) Successful in 4m30s
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
|
# Прокси для расписания в Modeus
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [x] Добавить RateLimiter
|
- [x] Добавить RateLimiter
|
||||||
- [ ] Добавить обработку ошибок при запросах к modeus
|
- [x] Добавить обработку ошибок при запросах к modeus
|
@@ -1,3 +1,4 @@
|
|||||||
|
using System.Net;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.RateLimiting;
|
using Microsoft.AspNetCore.RateLimiting;
|
||||||
@@ -8,8 +9,9 @@ namespace SfeduSchedule.Controllers
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/[controller]")]
|
[Route("api/[controller]")]
|
||||||
[EnableRateLimiting("throttle")]
|
[EnableRateLimiting("throttle")]
|
||||||
public class ScheduleController(ModeusService modeusService) : ControllerBase
|
public class ScheduleController(ModeusService modeusService, ILogger<ScheduleController> logger) : ControllerBase
|
||||||
{
|
{
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить расписание для указанных пользователей.
|
/// Получить расписание для указанных пользователей.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -39,10 +41,43 @@ namespace SfeduSchedule.Controllers
|
|||||||
[HttpPost]
|
[HttpPost]
|
||||||
public async Task<IActionResult> Post([FromBody] ModeusScheduleRequest request)
|
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);
|
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>
|
/// <summary>
|
||||||
/// Получить GUID пользователя по полному имени. (требуется авторизация)
|
/// Получить GUID пользователя по полному имени. (требуется авторизация)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -53,7 +88,7 @@ namespace SfeduSchedule.Controllers
|
|||||||
/// <response code="401">Неавторизованный</response>
|
/// <response code="401">Неавторизованный</response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authorize(AuthenticationSchemes = "ApiKey")]
|
[Authorize(AuthenticationSchemes = "ApiKey")]
|
||||||
[Route("GetGuid")]
|
[Route("getguid")]
|
||||||
public async Task<IActionResult> GetGuid(string fullname)
|
public async Task<IActionResult> GetGuid(string fullname)
|
||||||
{
|
{
|
||||||
var guid = await modeusService.GetGuidAsync(fullname);
|
var guid = await modeusService.GetGuidAsync(fullname);
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace SfeduSchedule
|
namespace SfeduSchedule
|
||||||
{
|
{
|
||||||
public class ModeusScheduleRequest(int size, DateTime timeMin, DateTime timeMax, List<Guid> attendeePersonId)
|
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 DateTime TimeMax { get; set; } = timeMax;
|
||||||
public List<Guid> AttendeePersonId { get; set; } = attendeePersonId;
|
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() {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,16 @@ namespace SfeduSchedule.Services
|
|||||||
return await response.Content.ReadAsStringAsync();
|
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)
|
public async Task<string?> GetGuidAsync(string fullName)
|
||||||
{
|
{
|
||||||
var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/people/persons/search");
|
var request = new HttpRequestMessage(HttpMethod.Post, $"schedule-calendar-v2/api/people/persons/search");
|
||||||
|
Reference in New Issue
Block a user