Пример #1
0
        public async Task <IActionResult> ShuffleDeck([FromBody] ShuffleRequest request)
        {
            var decks = await Services.DeckService.Find(request.DeckName);

            if (!decks.Any())
            {
                return(NotFound(string.Format(Resource.DeckNotFound, request.DeckName)));
            }

            if (decks.Count() > 1)
            {
                return(BadRequest(string.Format(Resource.MultiplyDeckNames, request.DeckName)));
            }

            var deck = decks.First();

            deck = await Services.ShuffleService.Shuffle(deck);

            await Services.DeckService.Update(deck);

            var response = Mapper.MapToDeckHeader(deck);

            await LinksService.AddLinksAsync(response);

            return(Ok(response));
        }
Пример #2
0
        public async Task <IActionResult> GetDecks()
        {
            var decks = await Services.DeckService.FindAll();

            var response = decks.Select(d => Mapper.MapToDeckHeader(d)).ToArray();

            foreach (var r in response)
            {
                await LinksService.AddLinksAsync(r);
            }

            return(Ok(response));
        }
Пример #3
0
        public async Task <IActionResult> CreateDeck([FromBody] CreateDeckRequest request)
        {
            var decks = await Services.DeckService.Find(request.DeckName);

            if (decks.Any())
            {
                return(BadRequest(string.Format(Resource.DeckAlreadyExists, request.DeckName)));
            }

            await Services.DeckService.Create(request.DeckName);

            decks = await Services.DeckService.Find(request.DeckName);

            var response = Mapper.MapToDeck(decks.First());
            await LinksService.AddLinksAsync(response);

            return(CreatedAtAction(nameof(CreateDeck), response));
        }
Пример #4
0
        public async Task <IActionResult> GetDeck([FromRoute] string deckName)
        {
            var decks = await Services.DeckService.Find(deckName);

            if (!decks.Any())
            {
                return(NotFound(string.Format(Resource.DeckNotFound, deckName)));
            }

            if (decks.Count() > 1)
            {
                return(BadRequest(string.Format(Resource.MultiplyDeckNames, deckName)));
            }

            var response = Mapper.MapToDeck(decks.First());
            await LinksService.AddLinksAsync(response);

            return(Ok(response));
        }
Пример #5
0
        public async Task <IActionResult> GetSecuredValue(string hash)
        {
            var getData = new GetSecuredValueQuery(hash.ToLower());
            var result  = await Mediator.Send(getData);

            if (result == null)
            {
                return(NotFound());
            }

            var response = new SecuredDataResponse
            {
                Value       = result.Value,
                IsEncrypted = result.IsEncrypted,
                ExpiresAt   = result.ExpiresAt
            };

            await LinksService.AddLinksAsync(response);

            return(Ok(response));
        }
Пример #6
0
        public async Task <IActionResult> CreateLink(
            [FromBody] CreateLinkRequest request,
            CancellationToken cancellationToken)
        {
            var createLink = new CreateLinkCommand(
                request.Data,
                request.IsEncrypted,
                request.Secrets,
                request.TtlSeconds);

            var link = await Mediator.Send(createLink, cancellationToken);

            var response = new CreateLinkResponse
            {
                ExpiresAt = link.ExpiresAt,
                LinkId    = link.LinkId
            };

            await LinksService.AddLinksAsync(response);

            return(Created("links/{{hash}}", response));
        }