public async Task <IActionResult> GetSkill(int id)
        {
            if (_memoryCache.TryGetValue(string.Format(GET_SKILL_CACHE, id), out GetSkillViewModel skill))
            {
                return(Ok(skill));
            }

            var query  = new GetSkillQuery(id);
            var result = await _mediator.Send(query);

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


            var memoryCacheOptions = new MemoryCacheEntryOptions
            {
                //Daqui a 1h, irei invalidar a cache
                AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(3600),

                //Tempo decorrido sem requisições => Passa 20 minutos seguidos sem nenhuma requisição
                SlidingExpiration = TimeSpan.FromSeconds(1200)
            };

            _memoryCache.Set(string.Format(GET_SKILL_CACHE, id), result, memoryCacheOptions);

            return(Ok(result));
        }
Beispiel #2
0
        public async Task <ActionResult <SkillResponse> > GetSkill([FromRoute] int skillId)
        {
            var query = new GetSkillQuery(skillId);
            var skill = await this.mediator.Send(query);

            return(this.Ok(skill));
        }
        public async Task <ApiResponse <GetSkillQueryResult> > GetById(Guid id)
        {
            var query = new GetSkillQuery
            {
                Id = id
            };
            var data = await _operationMediator.HandleAsync(query);

            return(ApiResponse.Ok(data));
        }
Beispiel #4
0
        public async Task <ActionResult <SkillResponse> > RegisterSkillAsync([FromRoute] int profileId, [FromBody] SkillModel model)
        {
            var command = new RegisterSkillCommand(profileId, model);
            var result  = await this.mediator.Send(command);

            if (result.IsFailed)
            {
                return(this.UnprocessableEntity(result));
            }

            var user = await this.mediator.Send(new GetCurrentUserQuery());

            var notification = new EvaluateSkillNotification(user.Id, result.Value, model.Score);

            await this.mediator.Publish(notification);

            var query = new GetSkillQuery(result.Value);
            var skill = await this.mediator.Send(query);

            return(CreatedAtRoute(nameof(GetSkill), new { skillId = skill !.Id }, skill));