/// <summary> /// get the actual url base the short url of it /// </summary> /// <param name="shortUrl">short url for redirect to actual path</param> /// <returns></returns> public string GetUrl(string shortUrl) { var q = _shortUrlRepository.GetUrl(shortUrl); if (q != null) { q.TimesOfView++; _shortUrlRepository.Update(q); return(q.ActualURL); } return(null); }
public async Task <IActionResult> ShortenUrlGet(ShortUrlInDTO originalUrl)///Query params can be null so add hint { //Check URL in Request; if (!ModelState.IsValid) { _logger.LogError("Invalid request. Url sent was: {originalUrl}", originalUrl); return(BadRequest("URL not present in the request")); } //Check URL already Exists if (!await _repo.UrlExists(originalUrl.OriginalURL)) { return(BadRequest("Shortened URL does not exists for " + originalUrl.OriginalURL)); } //Generate and Save short URL var shortUrl = await _repo.GetUrl(originalUrl.OriginalURL); return(Ok(shortUrl.ShortURL)); }