Projekt

Obecné

Profil

« Předchozí | Další » 

Revize c2a89232

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

Resolved issues from code review

Zobrazit rozdíly:

Backend/Backend/Controllers/AnnotationController.cs
63 63
                var res = annotationService.GetAnnotation(request.AnnotationId, clientInfo.LoggedUser.Id, clientInfo.LoggedUser.Role);
64 64
                return Ok(res);
65 65
            }
66
            catch (ArgumentException e)
66
            catch (InvalidOperationException e)
67 67
            {
68
                throw new BadRequestException(e.Message);
68
                throw new BadRequestException("Could not find specified annotation");
69 69
            }
70 70
            catch (UnauthorizedAccessException)
71 71
            {
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
93 93

  
94 94
        public AnnotationInfo GetAnnotation(Guid annotationId, Guid userId, ERole userRole)
95 95
        {
96
            var a = context.Annotations.Where(a => a.Id == annotationId).Include(a => a.User).Include(a => a.Document).Include(a => a.Document.Content).ToList();
97
            if (a.Count == 0)
98
            {
99
                throw new ArgumentException($"Annotation {annotationId} does not exist");
100
            }
101
            Annotation annotation = a.ElementAt(0);
102

  
96
            var annotation = context.Annotations
97
                .Where(a => a.Id == annotationId)
98
                .Include(a => a.User)
99
                .Include(a => a.Document).ThenInclude(d => d.Content)
100
                .First();
101
            
103 102
            if (userRole < ERole.ADMINISTRATOR)
104 103
            {
105 104
                if (annotation.User.Id != userId)
......
108 107
                }
109 108
            }
110 109

  
111
            var documentContent = context.Documents.Where(d => d.Id == annotation.Document.Id).Select(d => d.Content).ToList()[0];
110
            var documentContent = context.Documents.Where(d => d.Id == annotation.Document.Id).Select(d => d.Content).First();
112 111

  
113 112
            // We probably cannot use AutoMapper since we are dealing with too many different entities
114 113
            AnnotationInfo annotationInfo = new()
......
119 118
                Type = IsHtml(documentContent.Content) ? EDocumentType.HTML : EDocumentType.TEXT
120 119
            };
121 120

  
122
            var tags = context.AnnotationTags.Where(at => at.Annotation.Id == annotationId).Include(at => at.Tag).Include(at => at.SubTag).Include(at => at.Tag.Category).ToList();
121
            var tags = context.AnnotationTags.Where(at => at.Annotation.Id == annotationId)
122
                .Include(at => at.Tag).ThenInclude(t => t.Category)
123
                .Include(at => at.SubTag)
124
                .ToList();
125

  
123 126
            foreach (var tag in tags)
124 127
            {
125 128
                var tagInstance = mapper.Map<TagInstanceInfo>(tag);

Také k dispozici: Unified diff