Beispiel #1
0
        public async Task <ActionResult <ClaimResponse> > ReassingEpisode([FromBody] TopicReasingPostRequest topicReasing)
        {
            User user = null;

            try
            {
                user = await _auth.GetUserFromValidToken(Request);
            }
            catch (TokenDoesNotExistException e)
            {
                return(Unauthorized());
            }
            catch (Exception e)
            {
                _logger.LogError($"Error while trying to get user trying to reassing episode with id: {topicReasing.EpisodeId} to user with id: {topicReasing.UserId}. Error:\n{e.Message}");
                SentrySdk.CaptureException(e);
                return(Problem());
            }

            try
            {
                if (!await _auth.CheckIfUserHasElivatedPermission(Request))
                {
                    return(Unauthorized());
                }
                _logger.LogInformation($"A user with the id: {user.Id} and the role id: {user.RolesId} is reassigning the episode with the id: {topicReasing.EpisodeId} to the user with the id: {topicReasing.UserId}");

                EpisodeExtended episode = await _database.GetMinimalEpisodeAsync(topicReasing.EpisodeId);

                if (episode.Claimed)
                {
                    return(BadRequest("Episode is already claimed!"));
                }

                ClaimResponse response = await _claim.ReassingClaimAsync(episode, topicReasing.UserId);

                return(Ok(response));
            }
            catch (TokenDoesNotExistException e)
            {
                return(Unauthorized());
            }
            catch (Exception e)
            {
                _logger.LogError($"Error while trying to reassing claim. Reassing was requested by user with id: {user.Id}. Episode requested to be reassigned is episode with id: {topicReasing.EpisodeId}. The user it should be reassigned to has is: {topicReasing.UserId}. Error:\n{e.Message}");
                SentrySdk.CaptureException(e);
            }

            return(Problem());
        }
Beispiel #2
0
        public async Task <ActionResult <ClaimResponse> > Post(int id) // id = EpisodeId
        {
            if (id == 0)
            {
                return(BadRequest("Id cannot be 0!"));
            }
            if (id < 0)
            {
                return(BadRequest("Id cannot be smaller than 0!"));
            }

            try
            {
                User user = await _auth.GetUserFromValidToken(Request);

                EpisodeExtended episode = await _database.GetMinimalEpisodeAsync(id);

                if (episode.Claimed)
                {
                    return(BadRequest("Episode is already claimed!"));
                }

                ClaimResponse response = await _claim.ClaimEpisodeAsync(episode, user.Id);

                return(Ok(response));
            }
            catch (EpisodeUnclaimedButAlreadyHasTopcisException e)
            {
                return(BadRequest("Episode is already claimed!"));
            }
            catch (TokenDoesNotExistException e)
            {
                return(Unauthorized());
            }
            catch (Exception e)
            {
                if (e.Message.Contains("23505") || e.Message.Contains("unique_user"))
                {
                    _logger.LogError($"User tried to claim episode wiht id {id}. But the user already claimed another episode.");
                    return(BadRequest("User already has another claimed episode!"));
                }

                _logger.LogError($"Error while trying to claim episode with id: {id}. Error:\n{e.Message}");
                SentrySdk.CaptureException(e);
            }

            return(Problem());
        }