Добавил лог в тг
This commit is contained in:
@@ -22,10 +22,10 @@ export function onLoad() {
|
||||
generateStatementModal.showModal();
|
||||
|
||||
const data = {
|
||||
"phone": "+7" + localStorage.getItem('phoneNumber'),
|
||||
"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')
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 - словарь, который будет содержать только начало закладок,
|
||||
// чтобы потом по ним находить соответствующие им концы закладок
|
||||
|
||||
Reference in New Issue
Block a user