예제 #1
0
        public async Task <IActionResult> Create(VoteDto request)
        {
            var userId = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));

            var user = await _dbContext.Users.FindAsync(userId);

            user.Vote(request.MovieId, request.Type);

            await _dbContext.SaveChangesAsync();

            return(Created(string.Empty, default));
        }
예제 #2
0
        public async Task <IActionResult> Post([FromBody] CreateMovieRequest movie)
        {
            var userId   = int.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier));
            var newMovie = new Movie(movie.Title, movie.Description, movie.PublicationDate, userId);

            _dbContext.Movies.Add(newMovie);

            await _dbContext.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = newMovie.Id }, movie));
        }
예제 #3
0
        public async Task <IActionResult> Authenticate(AuthenticateUserRequest request)
        {
            var user = await _authService.Authenticate(request.Username, request.Password);

            if (user is null)
            {
                return(Unauthorized());
            }

            var token = _jwtService.GenerateToken(user.Id, user.Username);

            var refreshTokenValue = _refreshTokenService.GenerateRefreshToken();

            var refreshToken = RefreshToken.Create(refreshTokenValue, user.Id);

            _dbContext.RefreshTokens.Add(refreshToken);

            await _dbContext.SaveChangesAsync();

            return(Ok(new { user.Username, token, refreshToken = refreshToken.Token, RefreshTokenExpiresAt = refreshToken.ExpirationDate }));
        }