Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 58363b44

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

Backend checks for duplicate tags and returns bad request

Zobrazit rozdíly:

Backend/Backend/Controllers/AnnotationController.cs
92 92
                annotationService.AddAnnotationInstance(annotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role, request);
93 93
                return Ok();
94 94
            }
95
            catch (InvalidOperationException e)
96
            {
97
                throw new BadRequestException("Could not find specified annotation");
98
            }
99 95
            catch (UnauthorizedAccessException)
100 96
            {
101 97
                return Forbid();
102 98
            }
103

  
99
            catch (Exception e)
100
            {
101
                throw new BadRequestException(e.Message);
102
            }
104 103
        }
105 104

  
106 105
        [HttpDelete("/annotation/{annotationId}/{occurenceId}")]
......
121 120
                annotationService.DeleteAnnotationInstance(annotationId, occurenceId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role);
122 121
                return Ok();
123 122
            }
124
            catch (InvalidOperationException e)
125
            {
126
                throw new BadRequestException("Could not find specified annotation");
127
            }
128 123
            catch (UnauthorizedAccessException)
129 124
            {
130 125
                return Forbid();
131 126
            }
127
            catch (Exception e)
128
            {
129
                throw new BadRequestException(e.Message);
130
            }
132 131

  
133 132
        }
134 133
    }
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
683 683

  
684 684
                        parent.ChildNodes.Clear();
685 685
                        foreach (var child in newChildren) { parent.ChildNodes.Add(child); }*/
686
                        
686

  
687 687
                        descendantsToEdit = docToEdit.DocumentNode.DescendantsAndSelf().ToList();
688 688
                        descendantsCount = descendantsToEdit.Count();
689 689
                        break;
......
743 743
            {
744 744
                annotationTag.Tag = context.Tags.Where(t => t.Id == request.Id).Single();
745 745
                annotationTag.SubTag = null;
746

  
747
                // If for the same annotation exists a tag with same position and length and of the same type, ignore
748
                if (context.AnnotationTags.Any(at => 
749
                at.Position == annotationTag.Position &&
750
                at.Length == annotationTag.Length &&
751
                at.Annotation == annotation &&
752
                at.Tag == annotationTag.Tag))
753
                {
754
                    throw new InvalidOperationException("Duplicate tag");
755
                }
756

  
746 757
            }
747 758
            else if (request.Type == ETagType.SUBTAG)
748 759
            {
749 760
                var subTag = context.SubTags.Where(st => st.Id == request.Id).Include(st => st.Tag).Single();
750 761
                annotationTag.SubTag = subTag;
751 762
                annotationTag.Tag = subTag.Tag;
763

  
764
                if (context.AnnotationTags.Any(at => 
765
                at.Position == annotationTag.Position &&
766
                at.Length == annotationTag.Length &&
767
                at.Annotation == annotation &&
768
                at.Tag == annotationTag.Tag &&
769
                at.SubTag == annotationTag.SubTag))
770
                {
771
                    throw new InvalidOperationException("Duplicate tag");
772
                }
752 773
            }
753 774
            else
754 775
            {

Také k dispozici: Unified diff