Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 15c88dc1

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

Added sentiment to Tags and SubTags, modified create/update tag/subtag endpoints, added set instance sentiment endpoint

Zobrazit rozdíly:

Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
562 562
            {
563 563
                annotationTag.Tag = context.Tags.Where(t => t.Id == request.Id).Single();
564 564
                annotationTag.SubTag = null;
565

  
566
                if (annotationTag.Tag.SentimentEnabled)
567
                {
568
                    annotationTag.Sentiment = ETagSentiment.NEUTRAL;
569
                }
565 570
            }
566 571
            else if (request.Type == ETagType.SUBTAG)
567 572
            {
568 573
                var subTag = context.SubTags.Where(st => st.Id == request.Id).Include(st => st.Tag).Single();
569 574
                annotationTag.SubTag = subTag;
570 575
                annotationTag.Tag = subTag.Tag;
576

  
577
                if (annotationTag.SubTag.SentimentEnabled)
578
                {
579
                    annotationTag.Sentiment = ETagSentiment.NEUTRAL;
580
                }
571 581
            }
572 582
            else
573 583
            {
......
615 625

  
616 626
            context.SaveChanges();
617 627
        }
628

  
629
        public void SetTagInstanceSentiment(Guid annotationId, Guid instanceId, Guid userId, ERole userRole, ETagSentiment sentiment)
630
        {
631
            Annotation annotation = null;
632
            try
633
            {
634
                annotation = context.Annotations
635
                   .Where(a => a.Id == annotationId)
636
                   .Include(a => a.User)
637
                   .Include(a => a.Document).ThenInclude(d => d.Content)
638
                   .First();
639

  
640
            }
641
            catch (Exception ex)
642
            {
643
                throw new InvalidOperationException("Could not find annotation");
644
            }
645

  
646

  
647
            if (userRole < ERole.ADMINISTRATOR)
648
            {
649
                if (annotation.User.Id != userId)
650
                {
651
                    throw new UnauthorizedAccessException($"User {userId} does not have assigned annotation {annotationId}");
652
                }
653
            }
654

  
655

  
656
            var tagInstances = context.AnnotationTags.Where(at => at.Instance == instanceId).ToList();
657
            if (tagInstances.Count() == 0)
658
            {
659
                throw new InvalidOperationException("No such instance found");
660
            }
661

  
662
            foreach (var tagInstance in tagInstances)
663
            {
664
                tagInstance.Sentiment = sentiment;
665
            }
666

  
667
            context.SaveChanges();
668
        }
618 669
    }
619 670
}

Také k dispozici: Unified diff