Esempio n. 1
0
        private async Task <ShortUrl> GetShortUrl(Slug slug, CancellationToken cancellationToken = default(CancellationToken))
        {
            Check.That <ApplicationException>(Check.IsNull(slug), "Slug is null.");

            var shortUrl = await _shortUrlRepository.GetBySlug(slug.Id, cancellationToken);

            Check.That <DomainException>(Check.IsNull(shortUrl), "shortUrl is null.");

            return(shortUrl);
        }
Esempio n. 2
0
        private async Task <ShortUrl> CheckAndGetShortUrl(Guid slugId, bool boost, bool isRouter, CancellationToken cancellationToken)
        {
            //Get shorturl entity
            var shortUrlEntity = await _shortUrlRepository.GetBySlug(slugId, cancellationToken);

            if (!isRouter)
            {
                //Check owner
                Check.That <ApplicationException>(!CurrentUser.IsAdmin() &&
                                                  !shortUrlEntity.CreatedBy.Equals(CurrentUser.Id), $"This slug not found for the user");
            }


            //Set Hits
            if (boost)
            {
                shortUrlEntity.Boost();
            }

            //Update the shorturl
            await _shortUrlRepository.Update(shortUrlEntity, cancellationToken);

            return(shortUrlEntity);
        }