Revize 8c9ce202
Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)
Backend/Core/Contexts/DatabaseContext.cs | ||
---|---|---|
3 | 3 |
using Microsoft.Extensions.Configuration; |
4 | 4 |
using System; |
5 | 5 |
using System.Collections.Generic; |
6 |
using System.ComponentModel.DataAnnotations.Schema; |
|
6 | 7 |
using System.Linq; |
7 | 8 |
using System.Text; |
8 | 9 |
using System.Threading.Tasks; |
... | ... | |
36 | 37 |
optionsBuilder.UseNpgsql(_configuration["ConnectionString"], b => b.MigrationsAssembly("RestAPI")); |
37 | 38 |
//optionsBuilder.UseNpgsql("Host=localhost:5432;Database=dbo;Username=myuser;Password=password"); |
38 | 39 |
} |
40 |
|
|
41 |
protected override void OnModelCreating(ModelBuilder modelBuilder) |
|
42 |
{ |
|
43 |
} |
|
39 | 44 |
} |
40 | 45 |
} |
Backend/Core/Entities/Annotation.cs | ||
---|---|---|
39 | 39 |
public EModified ModifiedType { get; set; } = EModified.NONE; |
40 | 40 |
|
41 | 41 |
public ICollection<Class> Classes { get; set; } = new List<Class>(); |
42 |
|
|
43 |
public ICollection<FinalAnnotation> FinalAnnotations { get; set; } = new List<FinalAnnotation>(); |
|
42 | 44 |
} |
43 | 45 |
} |
Backend/Core/Entities/FinalAnnotation.cs | ||
---|---|---|
1 | 1 |
using System; |
2 | 2 |
using System.Collections.Generic; |
3 |
using System.ComponentModel.DataAnnotations.Schema; |
|
3 | 4 |
using System.Linq; |
4 | 5 |
using System.Text; |
5 | 6 |
using System.Threading.Tasks; |
Backend/Core/Entities/FinalAnnotationTag.cs | ||
---|---|---|
8 | 8 |
{ |
9 | 9 |
public class FinalAnnotationTag : AnnotationTagGeneric |
10 | 10 |
{ |
11 |
// May cause problems? |
|
12 | 11 |
public FinalAnnotation Annotation { get; set; } |
13 | 12 |
public bool IsFinal { get; set; } = false; |
14 |
public List<User> Users { get; set; } = new();
|
|
13 |
public ICollection<User> Users { get; set; } = new List<User>();
|
|
15 | 14 |
} |
16 | 15 |
} |
Backend/Core/Entities/User.cs | ||
---|---|---|
20 | 20 |
public string Surname { get; set; } |
21 | 21 |
|
22 | 22 |
public ERole Role { get; set; } |
23 |
|
|
24 |
public ICollection<FinalAnnotationTag> FinalAnnotationTags { get; set; } = new List<FinalAnnotationTag>(); |
|
23 | 25 |
} |
24 | 26 |
} |
Backend/Core/MapperProfiles/TagProfileEF.cs | ||
---|---|---|
23 | 23 |
CreateMap<AnnotationTag, FinalAnnotationTag>() |
24 | 24 |
.ForMember(fat => fat.Id, opt => opt.Ignore()) |
25 | 25 |
.ForMember(fat => fat.Annotation, opt => opt.Ignore()); |
26 |
|
|
27 |
CreateMap<FinalAnnotationTag, TagInstanceInfo>(); |
|
26 | 28 |
} |
27 | 29 |
} |
28 | 30 |
} |
Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs | ||
---|---|---|
50 | 50 |
var users = context.Users.Where(u => request.UserIdList.Contains(u.Id)).ToList(); |
51 | 51 |
foreach (var user in users) |
52 | 52 |
{ |
53 |
var userAnnotatedDocuments = context.Annotations.Where(a => a.User == user).Select(a => a.Document).ToList(); |
|
53 |
var userAnnotatedDocuments = context.Annotations |
|
54 |
.Where(a => !(a is FinalAnnotation)) |
|
55 |
.Where(a => a.User == user) |
|
56 |
.Select(a => a.Document) |
|
57 |
.ToList(); |
|
54 | 58 |
foreach (var doc in documents) |
55 | 59 |
{ |
56 | 60 |
if (userAnnotatedDocuments.Contains(doc)) |
... | ... | |
78 | 82 |
public AnnotationListResponse GetUserAnnotations(Guid userId) |
79 | 83 |
{ |
80 | 84 |
var annotations = context.Annotations |
85 |
.Where(a => !(a is FinalAnnotation)) |
|
81 | 86 |
.Where(a => a.User.Id == userId) |
82 | 87 |
.Include(a => a.Document) |
83 | 88 |
.ToList(); |
89 |
|
|
84 | 90 |
var infos = new List<AnnotationListInfo>(); |
85 | 91 |
foreach (var annotation in annotations) |
86 | 92 |
{ |
... | ... | |
133 | 139 |
if (!isFinal) |
134 | 140 |
{ |
135 | 141 |
annotation = context.Annotations |
142 |
.Where(a => !(a is FinalAnnotation)) |
|
136 | 143 |
.Where(a => a.Id == annotationId) |
137 | 144 |
.Include(a => a.User) |
138 | 145 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
... | ... | |
158 | 165 |
|
159 | 166 |
var documentContent = context.Documents.Where(d => d.Id == annotation.Document.Id).Select(d => d.Content).First(); |
160 | 167 |
|
161 |
var tags = context.AnnotationTags.Where(at => at.Annotation.Id == annotationId) |
|
162 |
.Include(at => at.Tag) |
|
168 |
IQueryable<AnnotationTagGeneric> tagsQuery; |
|
169 |
List<AnnotationTagGeneric> tags; |
|
170 |
if (!isFinal) |
|
171 |
{ |
|
172 |
tagsQuery = context.AnnotationTags.Where(at => at.Annotation.Id == annotationId); |
|
173 |
} |
|
174 |
else |
|
175 |
{ |
|
176 |
tagsQuery = context.FinalAnnotationTags.Where(at => at.Annotation.Id == annotationId); |
|
177 |
} |
|
178 |
|
|
179 |
tags = tagsQuery.Include(at => at.Tag) |
|
163 | 180 |
.ThenInclude(t => t.Category) |
164 | 181 |
.Include(at => at.SubTag) |
165 | 182 |
.OrderBy(at => at.Position) |
166 |
.Select(at => at as AnnotationTagGeneric)
|
|
183 |
.Select(at => at) |
|
167 | 184 |
.ToList(); |
168 | 185 |
|
169 | 186 |
List<TagInstanceInfo> tagInstanceInfos = new(); |
... | ... | |
259 | 276 |
if (!isFinal) |
260 | 277 |
{ |
261 | 278 |
annotation = context.Annotations |
279 |
.Where(a => !(a is FinalAnnotation)) |
|
262 | 280 |
.Where(a => a.Id == annotationId) |
263 | 281 |
.Include(a => a.User) |
264 | 282 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
... | ... | |
389 | 407 |
if (!isFinal) |
390 | 408 |
{ |
391 | 409 |
annotation = context.Annotations |
410 |
.Where(a => !(a is FinalAnnotation)) |
|
392 | 411 |
.Where(a => a.Id == annotationId) |
393 | 412 |
.Include(a => a.User) |
394 | 413 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
... | ... | |
462 | 481 |
if (!isFinal) |
463 | 482 |
{ |
464 | 483 |
annotation = context.Annotations |
484 |
.Where(a => !(a is FinalAnnotation)) |
|
465 | 485 |
.Where(a => a.Id == annotationId) |
466 | 486 |
.Include(a => a.User) |
467 | 487 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
... | ... | |
524 | 544 |
if (!isFinal) |
525 | 545 |
{ |
526 | 546 |
annotation = context.Annotations |
547 |
.Where(a => !(a is FinalAnnotation)) |
|
527 | 548 |
.Where(a => a.Id == annotationId) |
528 | 549 |
.Include(a => a.User) |
529 | 550 |
.Include(a => a.Document).ThenInclude(d => d.Content) |
... | ... | |
568 | 589 |
} |
569 | 590 |
|
570 | 591 |
var annotations = context.Annotations |
592 |
.Where(a => !(a is FinalAnnotation)) |
|
571 | 593 |
.Include(a => a.Document) |
572 | 594 |
.Where(a => a.Document == document && a.State == EState.DONE) |
573 | 595 |
.ToList(); |
Backend/Core/Services/DocumentService/DocumentServiceEF.cs | ||
---|---|---|
137 | 137 |
List<DocumentListInfo> documentInfos = new List<DocumentListInfo>(); |
138 | 138 |
foreach (var document in documents.GetRange(firstIndex, pageSize)) |
139 | 139 |
{ |
140 |
var annotatingUsers = databaseContext.Annotations.Where(a => a.Document == document).Select(a => a.User).ToList(); |
|
140 |
var annotatingUsers = databaseContext.Annotations |
|
141 |
.Where(a => !(a is FinalAnnotation)) |
|
142 |
.Where(a => a.Document == document) |
|
143 |
.Select(a => a.User).ToList(); |
|
144 |
|
|
141 | 145 |
List<DocumentUserInfo> annotatingUsersDto = new(); |
142 | 146 |
|
143 | 147 |
// Include annotation state |
144 | 148 |
foreach (var annotatingUser in annotatingUsers) |
145 | 149 |
{ |
146 | 150 |
var annotation = databaseContext.Annotations |
151 |
.Where(a => !(a is FinalAnnotation)) |
|
147 | 152 |
.Include(a => a.Document) |
148 |
.Single(a => a.Document == document && a.User == annotatingUser); |
|
153 |
.Single(a => a.Document == document && a.User == annotatingUser && !(a is FinalAnnotation));
|
|
149 | 154 |
var dui = mapper.Map<DocumentUserInfo>(annotatingUser); |
150 | 155 |
dui.State = annotation.State; |
151 | 156 |
annotatingUsersDto.Add(dui); |
Backend/Core/Services/TagService/TagServiceEF.cs | ||
---|---|---|
279 | 279 |
{ |
280 | 280 |
if (!isFinal) |
281 | 281 |
{ |
282 |
annotation = databaseContext.Annotations.Include(a => a.User).First(a => a.Id == annotationId); |
|
282 |
annotation = databaseContext.Annotations |
|
283 |
.Where(a => !(a is FinalAnnotation)) |
|
284 |
.Include(a => a.User).First(a => a.Id == annotationId); |
|
283 | 285 |
} |
284 | 286 |
else |
285 | 287 |
{ |
Backend/Core/Services/UserService/UserServiceEF.cs | ||
---|---|---|
186 | 186 |
foreach (var user in users) |
187 | 187 |
{ |
188 | 188 |
var userInfo = _mapper.Map<UserInfo>(user); |
189 |
userInfo.AssignedDocumentsCount = _databaseContext.Annotations.Include(a => a.User).Where(a => a.User == user).Count(); |
|
189 |
userInfo.AssignedDocumentsCount = _databaseContext.Annotations |
|
190 |
.Include(a => a.User) |
|
191 |
.Where(a => !(a is FinalAnnotation)) |
|
192 |
.Where(a => a.User == user) |
|
193 |
.Count(); |
|
190 | 194 |
userList.Users.Add(userInfo); |
191 | 195 |
} |
192 | 196 |
|
Backend/Models/Tags/TagInstanceInfo.cs | ||
---|---|---|
1 | 1 |
using Models.Enums; |
2 |
using Models.Users; |
|
2 | 3 |
using System; |
3 | 4 |
using System.Collections.Generic; |
4 | 5 |
using System.Linq; |
... | ... | |
26 | 27 |
|
27 | 28 |
public ETagSentiment? Sentiment { get; set; } |
28 | 29 |
public string SelectedText { get; set; } |
30 |
|
|
31 |
public List<UserInfo>? Users { get; set; } |
|
32 |
public bool? IsFinal { get; set; } |
|
29 | 33 |
} |
30 | 34 |
} |
Také k dispozici: Unified diff
Fixed issues with database OR mapping