Exemple #1
0
        public async Task <IActionResult> ShortenUrlCreate(ShortUrlInDTO originalUrl) ///Query params can be null so add hint
        {
            //Check URL in Request;
            if (!ModelState.IsValid)
            {
                return(BadRequest("URL not present in the request"));
            }

            //Check URL already Exists
            if (await _repo.UrlExists(originalUrl.OriginalURL))
            {
                return(BadRequest("Shortened URL already exists for " + originalUrl.OriginalURL));
            }

            //Generate and Save short URL
            var shortUrl = await _repo.CreateUrl(originalUrl.OriginalURL);

            return(Ok(shortUrl.ShortURL));
        }