Добавил лог в тг

This commit is contained in:
2025-01-02 15:20:20 +03:00
parent 098eeb468e
commit 96fff95a5d
3 changed files with 35 additions and 10 deletions

View File

@@ -25,7 +25,7 @@ export function onLoad() {
"phone": "+7 " + localStorage.getItem('phoneNumber'), "phone": "+7 " + localStorage.getItem('phoneNumber'),
"kurs": localStorage.getItem('kurs'), "kurs": localStorage.getItem('kurs'),
"isFreeEducation": localStorage.getItem('paid') === "false", "isFreeEducation": localStorage.getItem('paid') === "false",
"isOchno": false, "isOchno": true,
"speciality": optionMapping[localStorage.getItem('option')], "speciality": optionMapping[localStorage.getItem('option')],
"reason": localStorage.getItem('statement') "reason": localStorage.getItem('statement')
} }

View File

@@ -8,11 +8,32 @@ namespace Otchinslator;
[ApiController] [ApiController]
[Authorize] [Authorize]
[AllowAnonymous] [AllowAnonymous]
public class StatementController(IStatementGenerator statementGenerator) : Controller public class StatementController(IStatementGenerator statementGenerator, IConfiguration configuration) : Controller
{ {
[HttpPost("/generateStatement")] [HttpPost("/generateStatement")]
public async Task<IActionResult> GenerateStatement(UserDTO userDto) public async Task<IActionResult> GenerateStatement(UserDTO userDto)
{ {
var speciality = userDto.speciality switch
{
1 => SpecialityType.Bakalavriat,
2 => SpecialityType.Magistatura,
3 => SpecialityType.Specialitet,
_ => throw new ArgumentOutOfRangeException()
};
if (speciality == SpecialityType.Bakalavriat && userDto.kurs > 4)
{
Utils.LogToTg("Походу ломают `SpecialityType.Bakalavriat && userDto.kurs > 4`", configuration);
return BadRequest("Некорректный курс для бакалавриата");
}
if (speciality == SpecialityType.Magistatura && userDto.kurs > 2)
{
Utils.LogToTg("Походу ломают `SpecialityType.Magistatura && userDto.kurs > 2`", configuration);
return BadRequest("Некорректный курс для магистратуры");
}
var userEmail = User.Identity.Name; var userEmail = User.Identity.Name;
var userFIO = User.Claims.FirstOrDefault(x => x.Type == "name")?.Value; var userFIO = User.Claims.FirstOrDefault(x => x.Type == "name")?.Value;
@@ -35,13 +56,7 @@ public class StatementController(IStatementGenerator statementGenerator) : Contr
kurs = userDto.kurs, kurs = userDto.kurs,
isFreeEducation = userDto.isFreeEducation, isFreeEducation = userDto.isFreeEducation,
isOchno = userDto.isOchno, isOchno = userDto.isOchno,
speciality = userDto.speciality switch speciality = speciality
{
1 => SpecialityType.Bakalavriat,
2 => SpecialityType.Magistatura,
3 => SpecialityType.Specialitet,
_ => throw new ArgumentOutOfRangeException()
}
}; };
var statement = await statementGenerator.GenerateStatementAsync(userData); var statement = await statementGenerator.GenerateStatementAsync(userData);
var pdf = await statementGenerator.ConvertToPDFAsync(statement); var pdf = await statementGenerator.ConvertToPDFAsync(statement);

View File

@@ -5,6 +5,16 @@ namespace Otchinslator;
public static class Utils public static class Utils
{ {
public static async void LogToTg(string message, IConfiguration configuration)
{
string url = $"https://api.telegram.org/bot{configuration["BOT_TOKEN"]}/sendMessage?chat_id={configuration["ChatId"]}&text={Uri.EscapeDataString(message)}";
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode) { Console.WriteLine("Message tg sent successfully!"); }
else
Console.WriteLine($"Failed to send tg message: {response.StatusCode}");
}
// Получаем все закладки в документе // Получаем все закладки в документе
// bStartWithNoEnds - словарь, который будет содержать только начало закладок, // bStartWithNoEnds - словарь, который будет содержать только начало закладок,
// чтобы потом по ним находить соответствующие им концы закладок // чтобы потом по ним находить соответствующие им концы закладок