From eedbe9aaae4f233434d7e05f6e65c927738ed01d Mon Sep 17 00:00:00 2001 From: kittyegg Date: Thu, 14 May 2026 12:56:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20pa?= =?UTF-8?q?tch-=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?short=20url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/ShortUrlController.cs | 21 +++++++++++++++++++ URL-Shortener/DTO/UpdateShortUrlDto.cs | 17 +++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 URL-Shortener/DTO/UpdateShortUrlDto.cs diff --git a/URL-Shortener/Controllers/ShortUrlController.cs b/URL-Shortener/Controllers/ShortUrlController.cs index 36c6853..ad58ccc 100644 --- a/URL-Shortener/Controllers/ShortUrlController.cs +++ b/URL-Shortener/Controllers/ShortUrlController.cs @@ -54,6 +54,27 @@ namespace URL_Shortener.Controllers return CreatedAtRoute(nameof(GetShortUrlByIdAsync), new { id = shortUrl.Id }, shortUrl); } + [HttpPatch("{id:int}")] + public async Task UpdateShortUrlAsync(int id, UpdateShortUrlDto dto) + { + var shortUrl = await _db.ShortUrls.FindAsync(id); + if (shortUrl == null) + return NotFound("Short URL not found"); + + if (!string.IsNullOrEmpty(dto.OriginalUrl)) + shortUrl.OriginalUrl = dto.OriginalUrl; + if (dto.ExpirationDateTime.HasValue) + shortUrl.ExpirationDateTime = dto.ExpirationDateTime; + if (dto.ClickLimit.HasValue) + shortUrl.ClickLimit = dto.ClickLimit.Value; + if (dto.ResetExpirationDateTime) + shortUrl.ExpirationDateTime = null; + + await _db.SaveChangesAsync(); + + return Ok(shortUrl); + } + [HttpDelete("{id:int}")] public async Task DeleteShortUrlByIdAsync(int id) { diff --git a/URL-Shortener/DTO/UpdateShortUrlDto.cs b/URL-Shortener/DTO/UpdateShortUrlDto.cs new file mode 100644 index 0000000..e5322a2 --- /dev/null +++ b/URL-Shortener/DTO/UpdateShortUrlDto.cs @@ -0,0 +1,17 @@ +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace URL_Shortener.DTO +{ + public class UpdateShortUrlDto + { + public string? OriginalUrl { get; set; } + + public DateTime? ExpirationDateTime { get; set; } = null; + + public int? ClickLimit { get; set; } = null; + + [DefaultValue(false)] + public bool ResetExpirationDateTime { get; set; } = false; + } +}