From 1c48750d87afb119e085507d6b3bf9965d6e1b0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9=20=D0=A8=D0=B8?= =?UTF-8?q?=D0=BC=D0=B0=D0=BD=D1=81=D0=BA=D0=B8=D0=B9?= Date: Thu, 16 Nov 2023 20:04:25 +0300 Subject: [PATCH] also hotfix --- Controllers/WeatherForecastController.cs | 23 ++++++++++++++-------- Database/Tables/Redirects.cs | 3 ++- Justice/Interactions/CitiesInteractions.cs | 2 +- Types/RedirectType.cs | 14 +++++++++++++ 4 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 Types/RedirectType.cs diff --git a/Controllers/WeatherForecastController.cs b/Controllers/WeatherForecastController.cs index 9093121..325f976 100644 --- a/Controllers/WeatherForecastController.cs +++ b/Controllers/WeatherForecastController.cs @@ -11,16 +11,23 @@ namespace DiscordApp.Controllers { [HttpGet("/redirects/{uri}")] - public IActionResult Get(string uri) + public IActionResult Get(string uri, [FromBody] string? bodyContent) { var data = Startup.appDbContext.Redirects.First(k => k.Id == uri); - Startup.appDbContext.Redirects.Remove(data); - Startup.appDbContext.SaveChanges(); - return Redirect(data.url); + if (data.RedirectType == Types.RedirectType.None) + { + data.RedirectType = Types.RedirectType.Redirected; + Startup.appDbContext.Redirects.Update(data); + Startup.appDbContext.SaveChanges(); + return Redirect(data.url); + } + else + { + return BadRequest(); + } } - - [HttpPost("/addOnMap")] - public ActionResult Create(string bodyContent) + [HttpPost("/redirects/{uri}")] + public IActionResult Post(string uri, [FromBody] string bodyContent) { JsonNode jsonBodyContent = JsonNode.Parse(bodyContent); string[] paymentData = jsonBodyContent["data"].ToString().Split(";"); @@ -35,7 +42,7 @@ namespace DiscordApp.Controllers .Build(); }).RunSynchronously(); - return Ok(); + return Redirect(message.GetJumpUrl()); } } diff --git a/Database/Tables/Redirects.cs b/Database/Tables/Redirects.cs index 8b4d2cd..1f35bd1 100644 --- a/Database/Tables/Redirects.cs +++ b/Database/Tables/Redirects.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using DiscordApp.Types; namespace DiscordApp.Database.Tables { @@ -9,6 +10,6 @@ namespace DiscordApp.Database.Tables [Key] public string Id { get; set; } public string url { get; set; } - + public RedirectType RedirectType { get; set; } = RedirectType.None; } } diff --git a/Justice/Interactions/CitiesInteractions.cs b/Justice/Interactions/CitiesInteractions.cs index 90f6594..6b44505 100644 --- a/Justice/Interactions/CitiesInteractions.cs +++ b/Justice/Interactions/CitiesInteractions.cs @@ -24,7 +24,7 @@ namespace DiscordApp.Justice.Interactions var redirectTable = new Redirects() { Id = redirectUri , url = uri}; Startup.appDbContext.Redirects.Add(redirectTable); Startup.appDbContext.SaveChanges(); - await FollowupAsync("Нажмите на кнопку ниже для оплаты", components: new ComponentBuilder().WithButton("Оплатить", url: $"https://discord.yawaflua.ru/redirects/{redirectUri}", style: ButtonStyle.Link).Build());//, ephemeral: true); + await FollowupAsync("Нажмите на кнопку ниже для оплаты", components: new ComponentBuilder().WithButton("Оплатить", url: $"https://discord.yawaflua.ru/redirects/{redirectUri}", style: ButtonStyle.Link).Build(), ephemeral: true); } diff --git a/Types/RedirectType.cs b/Types/RedirectType.cs new file mode 100644 index 0000000..3f035a8 --- /dev/null +++ b/Types/RedirectType.cs @@ -0,0 +1,14 @@ +namespace DiscordApp.Types +{ + public enum RedirectType + { + /// + /// Если еще не использовался + /// + None = 0, + /// + /// Если один раз уже редиректил + /// + Redirected = 1 + } +}