Ejemplo n.º 1
0
        public async Task <Response> DeleteUrl(Guid identifier)
        {
            var adaptedUrl = await _repository.GetUrlByIdentifier(identifier);

            var existingUrl = UrlFactory.ConvertToUrl(adaptedUrl);

            await _repository.DeleteUrl(existingUrl);

            return(ResponseFactory.InitializeResponseSuccess($"Short Url Deleted {identifier}", existingUrl));
        }
Ejemplo n.º 2
0
        public async Task <Response> UpdateUrl(UrlModel model)
        {
            var adaptedUrl = await _repository.GetUrlByIdentifier(model.Identifier);

            var existingUrl = UrlFactory.ConvertToUrl(adaptedUrl);

            if (!model.ShortUrlPath.Equals(existingUrl.ShortUrlPath) && !await IsShortUrlPathTaken(model.ShortUrlPath))
            {
                return(ResponseFactory.InitializeResponseFailed($"ShortUrlPath {model.ShortUrlPath} already taken", model));
            }

            existingUrl.OriginalUrl  = model.OriginalUrl;
            existingUrl.ShortUrlPath = model.ShortUrlPath;

            await _repository.UpdateUrl(existingUrl);

            return(ResponseFactory.InitializeResponseSuccess($"Updated Short Url {existingUrl.ShortUrlPath}", existingUrl));
        }