コード例 #1
0
        /// <summary>
        /// Creates or replaces the provided conversation item, based on the id.
        /// </summary>
        /// <param name="issueId">The issue on which the operation will be executed at.</param>
        /// <param name="conversationItemId">The id of the conversation.</param>
        /// <param name="conversationItem">The conversation that will be created or replaced if already existing.</param>
        public async Task CreateOrReplaceConversationItemAsync(string issueId, string conversationItemId, IssueConversationDTO conversationItem)
        {
            ObjectId conversationItemOid = Validators.ValidateObjectId(conversationItemId, "Provided conversation id is no valid ObjectId.");

            var issue = await _issueRepository.GetIssueByIdAsync(issueId);

            await AssertUserCanWriteConversation(issue);

            if (conversationItemOid.Equals(conversationItem.Id) is false)
            {
                throw new HttpStatusException(StatusCodes.Status400BadRequest, "Id missmatch.");
            }

            var issueConversationModel = new IssueConversation()
            {
                Id            = conversationItem.Id,
                CreatorUserId = Validators.ValidateObjectId(conversationItem.Creator?.Id.ToString(), "The conversation item is missing a valid userId."),
                Data          = conversationItem.Data,
                // Conversation from the outside  is always a message and
                // can therefore not contain requirements
                Requirements = null,
                Type         = IssueConversation.MessageType,
            };

            await _issueRepository.CreateOrUpdateConversationItemAsync(issueId, issueConversationModel);
        }
コード例 #2
0
 public IssueConversationDTO(IssueConversation issueConversation, UserDTO creator)
 {
     Id            = issueConversation.Id;
     Creator       = creator;
     Type          = issueConversation.Type;
     Data          = issueConversation.Data;
     OtherTicketId = issueConversation.OtherTicketId;
     Requirements  = issueConversation.Requirements;
     ExpectedTime  = issueConversation.ExpectedTime;
     CreatedAt     = issueConversation.CreatedAt;
     if (issueConversation.StateChange is StateChange stateChange)
     {
         StateChange = new StateChangeDTO(stateChange);
     }
 }
コード例 #3
0
        /// <summary>
        /// Creates a conversation item or updates it if existing.
        /// </summary>
        /// <param name="issueId">The issue on which the conversation will be added to.</param>
        /// <param name="issueConversation">The conversation item.</param>
        public async Task CreateOrUpdateConversationItemAsync(string issueId, IssueConversation issueConversation)
        {
            // check if the parsed objectId is not the 000...000 default objectId.
            ObjectId issueOid = Validators.ValidateObjectId(issueId, "Cannot parse issue string id to a valid object id.");

            var filterDef = Builders <Issue> .Filter;

            var issueFilter       = filterDef.Eq(iss => iss.Id, issueOid);
            var distinguishFilter = filterDef.ElemMatch(iss => iss.ConversationItems, (ci) => ci.Id.Equals(issueConversation.Id));
            var push = Builders <Issue> .Update.Push(iss => iss.ConversationItems, issueConversation);

            var result = await _dbCollection.UpdateOneAsync(issueFilter& !distinguishFilter, push);

            // MatchedCount == 0 => filter does not return a conversation item, so we need to update one. If a ci was inserted the MatchedCount would be 1.
            if (result.MatchedCount == 0)
            {
                // [-1] actes as $-Operator from mongodb.
                var update = Builders <Issue> .Update.Set(iss => iss.ConversationItems[-1], issueConversation);

                await _dbCollection.UpdateOneAsync(issueFilter& distinguishFilter, update);
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates a new conversation for the provided issueId.
        /// </summary>
        /// <param name="issueId">The issue which will gets appended with the provided conversation.</param>
        /// <param name="conversationItem">The new conversation item.</param>
        /// <returns>The inserted conversation item.</returns>
        public async Task <IssueConversationDTO> CreateNewIssueConversationAsync(string issueId, IssueConversationDTO conversationItem)
        {
            var issue = await _issueRepository.GetIssueByIdAsync(issueId);

            await AssertUserCanWriteConversation(issue);

            await _issueService.AssertNotArchived(issue);

            var conversationItems = issue.ConversationItems;

            // if ConversationItems are null = empty, create a new list, which will gets appended.
            if (conversationItems is null)
            {
                conversationItems = new List <IssueConversation>();
            }

            // TODO: after auth code impl. check if the user who creating this request is identical to the "conversationItem.Creator.Id" -> a client cannot create a conversation for other than himself.

            IssueConversation newConversation = new IssueConversation()
            {
                Id            = ObjectId.GenerateNewId(),
                CreatorUserId = _httpContextAccessor.HttpContext.User.GetUserId(),
                Data          = conversationItem.Data,
                Requirements  = new List <string>(),
                Type          = conversationItem.Type
            };

            // append the conversationItems with the new conversation item.
            conversationItems.Add(newConversation);

            // send Message to Author
            await CreateMessageForAuthor(issue);

            // update the issue and the conversationItems withit.
            await _issueRepository.UpdateAsync(issue);

            return(await MapIssueConversationDTOAsync(issue.Id, newConversation));
        }
コード例 #5
0
        private async Task <IssueConversationDTO> MapIssueConversationDTOAsync(ObjectId issueId, IssueConversation ic)
        {
            var creator = await _userService.GetUser(ic.CreatorUserId);

            if (ic.OtherTicketId is ObjectId otherTicketId)
            {
                var otherIssue = await _issueRepository.GetAsync(otherTicketId);

                var otherIssueName = otherIssue.IssueDetail.Name;

                ic.Data = ic.Type switch
                {
                    IssueConversation.PredecessorAddedType => $"{otherIssueName} wurde als Vorgänger hinzugefügt.",
                    IssueConversation.PredecessorRemovedType => $"{otherIssueName} wurde als Vorgänger entfernt.",
                    IssueConversation.ChildIssueAddedType => $"{otherIssueName} wurde als Unterticket hinzugefügt.",
                    IssueConversation.ChildIssueRemovedType => $"{otherIssueName} wurde als Unterticket entfernt.",
                    _ => throw new HttpStatusException(StatusCodes.Status500InternalServerError, "Invalid conversation item")
                };
            }

            return(new IssueConversationDTO(ic, creator));
        }