Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 2c8d08af

Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)

Added option to hide category from annotators, changed endpoints and services

Zobrazit rozdíly:

Backend/Backend/Controllers/TagController.cs
38 38
            return Problem();
39 39
        }
40 40

  
41
        return Ok(tagService.GetTagTree());
41
        return Ok(tagService.GetTagTree(clientInfo.LoggedUser.Role));
42 42
    }
43 43

  
44 44
    [HttpPost("/categories")]
Backend/Core/Entities/TagCategory.cs
13 13
        public string Name { get; set; }
14 14
        public string Color { get; set; }
15 15
        public string Description { get; set; }
16
        public bool DisabledForAnnotators { get; set; } = false;
16 17
    }
17 18
}
Backend/Core/Seeding/DummyTags.cs
371 371
            {
372 372
                Name = "K diskuzi tagy pro jednotlivé cookies",
373 373
                Description = "",
374
                Color = "#FF00FF"
374
                Color = "#FF00FF",
375
                DisabledForAnnotators = true
375 376
            };
376 377
            context.TagCategories.Add(experimentalCat);
377 378

  
Backend/Core/Services/TagService/ITagService.cs
12 12
{
13 13
    public interface ITagService
14 14
    {
15
        public TagTreeResponse GetTagTree();
15
        public TagTreeResponse GetTagTree(ERole userRole);
16 16
        public void CreateCategory(CreateCategoryRequest request);
17 17
        public void DeleteCategory(Guid categoryId);
18 18
        public void UpdateCategory(ModifyCategoryRequest request, Guid categoryId);
Backend/Core/Services/TagService/TagServiceEF.cs
27 27
            this.mapper = mapper;
28 28
        }
29 29

  
30
        public TagTreeResponse GetTagTree()
30
        public TagTreeResponse GetTagTree(ERole userRole)
31 31
        {
32 32
            // Prefetch from DB
33 33
            var tagCategories = databaseContext.TagCategories.Select(tc => tc).ToList();
......
37 37
            var tagCategoriesDTOs = new List<TagCategoryInfo>();
38 38
            foreach (var tagCategory in tagCategories)
39 39
            {
40
                if (tagCategory.DisabledForAnnotators && userRole == ERole.ANNOTATOR)
41
                {
42
                    continue;
43
                }
44

  
40 45
                var tagCategoryDTO = mapper.Map<TagCategoryInfo>(tagCategory);
41 46
                var categoryTags = tags.Where(t => t.Category == tagCategory);
42 47
                var tagDTOs = new List<TagInfo>();
......
77 82

  
78 83
            CategoryNameUnusedElseThrow(request.Name);
79 84

  
80
            databaseContext.TagCategories.Add(new Entities.TagCategory()
85
            databaseContext.TagCategories.Add(new TagCategory()
81 86
            {
82 87
                Name = request.Name,
83 88
                Color = request.Color,
84
                Description = request.Description
89
                Description = request.Description,
90
                DisabledForAnnotators = request.DisabledForAnnotators
85 91
            });
86 92

  
87 93
            databaseContext.SaveChanges();
......
121 127
                category.Color = request.Color;
122 128
            }
123 129

  
130
            if (request.DisabledForAnnotators != null)
131
            {
132
                category.DisabledForAnnotators = (bool) request.DisabledForAnnotators;
133
            }
134

  
124 135
            databaseContext.SaveChanges();
125 136
        }
126 137

  
Backend/Models/Tags/CreateCategoryRequest.cs
11 11
        public string Name { get; set; }
12 12
        public string Description { get; set; } = "";
13 13
        public string Color { get; set; }
14
        public bool DisabledForAnnotators { get; set; } = false;
14 15
    }
15 16
}
Backend/Models/Tags/ModifyCategoryRequest.cs
11 11
        public string? Name { get; set; }
12 12
        public string? Description { get; set; }
13 13
        public string? Color { get; set; }
14

  
15
        public bool? DisabledForAnnotators { get; set; }
16

  
14 17
    }
15 18
}

Také k dispozici: Unified diff