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

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'),
"kurs": localStorage.getItem('kurs'),
"isFreeEducation": localStorage.getItem('paid') === "false",
"isOchno": false,
"isOchno": true,
"speciality": optionMapping[localStorage.getItem('option')],
"reason": localStorage.getItem('statement')
}

View File

@@ -8,11 +8,32 @@ namespace Otchinslator;
[ApiController]
[Authorize]
[AllowAnonymous]
public class StatementController(IStatementGenerator statementGenerator) : Controller
public class StatementController(IStatementGenerator statementGenerator, IConfiguration configuration) : Controller
{
[HttpPost("/generateStatement")]
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 userFIO = User.Claims.FirstOrDefault(x => x.Type == "name")?.Value;
@@ -35,13 +56,7 @@ public class StatementController(IStatementGenerator statementGenerator) : Contr
kurs = userDto.kurs,
isFreeEducation = userDto.isFreeEducation,
isOchno = userDto.isOchno,
speciality = userDto.speciality switch
{
1 => SpecialityType.Bakalavriat,
2 => SpecialityType.Magistatura,
3 => SpecialityType.Specialitet,
_ => throw new ArgumentOutOfRangeException()
}
speciality = speciality
};
var statement = await statementGenerator.GenerateStatementAsync(userData);
var pdf = await statementGenerator.ConvertToPDFAsync(statement);

View File

@@ -5,6 +5,16 @@ namespace Otchinslator;
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 - словарь, который будет содержать только начало закладок,
// чтобы потом по ним находить соответствующие им концы закладок