Exemplo n.º 1
0
        public async Task <IActionResult> GetPost(long id)
        {
            var userId = GetUserIdFromClaims(User);

            var cacheKey = $"{nameof(Post)}{id}";

            var postJson = await _cachingService.GetAsync(cacheKey);

            if (!string.IsNullOrWhiteSpace(postJson))
            {
                var viewModel = Deserialize <PostViewModel>(postJson);
                return(Ok(viewModel));
            }

            var post = await _postService.GetPublicByIdAsync(id, userId ?? 0);

            if (post == null)
            {
                return(NotFound(NotFoundErrorViewModel.Create(nameof(Post), id)));
            }

            post = _processingService.ProcessPost(post, userId);

            var postViewModel = Mapper.Map <PostViewModel>(post);
            await _cachingService.AddAsync(cacheKey, Serialize(postViewModel));

            return(Ok(postViewModel));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetAllGames()
        {
            var cacheKey  = $"{nameof(Game)}s";
            var gamesJson = await _cachingService.GetAsync(cacheKey);

            if (!string.IsNullOrWhiteSpace(gamesJson))
            {
                var gameViewModels = Deserialize <List <GameViewModel> >(gamesJson);

                return(Ok(gameViewModels));
            }

            var games = await _gameService.GetAllGamesAsync();

            var mappedGames = Mapper.Map <List <GameViewModel> >(games);

            await _cachingService.AddAsync(cacheKey,
                                           Serialize(mappedGames));

            return(Ok(mappedGames));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetAllCharacters()
        {
            var cacheKey   = $"{nameof(Character)}s";
            var characters = await _characterService.GetAllWithGamesAsync();

            var charactersJson = await _cachingService.GetAsync(cacheKey);

            if (!string.IsNullOrWhiteSpace(charactersJson))
            {
                var cachedViewModels = Deserialize <List <GetCharacterViewModel> >(charactersJson);

                return(Ok(cachedViewModels));
            }

            var characterViewModels = Mapper.Map <List <GetCharacterListViewModel> >(characters);
            await _cachingService.AddAsync(cacheKey, Serialize(characterViewModels));

            return(Ok(characterViewModels));
        }