Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 3cee56d3

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

Annotation state returned with document list info

Zobrazit rozdíly:

Backend/Core/MapperProfiles/UserProfileEF.cs
13 13
    {
14 14
        public UserProfileEF()
15 15
        {
16
           CreateMap<User, UserInfo>();
16
            CreateMap<User, UserInfo>();
17
            CreateMap<User, DocumentUserInfo>();
17 18
        }
18 19
    }
19 20
}
Backend/Core/Services/DocumentService/DocumentServiceEF.cs
12 12
using AutoMapper;
13 13
using Models.Users;
14 14
using Ganss.XSS;
15
using Microsoft.EntityFrameworkCore;
15 16

  
16 17
namespace Core.Services.DocumentService
17 18
{
......
137 138
            foreach (var document in documents.GetRange(firstIndex, pageSize))
138 139
            {
139 140
                var annotatingUsers = databaseContext.Annotations.Where(a => a.Document == document).Select(a => a.User).ToList();
140
                List<UserInfo> annotatingUsersDto = annotatingUsers.Select(a => mapper.Map<UserInfo>(a)).ToList();
141
                List<DocumentUserInfo> annotatingUsersDto = new();
142
               
143
                // Include annotation state
144
                foreach (var annotatingUser in annotatingUsers)
145
                {
146
                    var annotation = databaseContext.Annotations
147
                        .Include(a => a.Document)
148
                        .Single(a => a.Document == document && a.User == annotatingUser);
149
                    var dui = mapper.Map<DocumentUserInfo>(annotatingUser);
150
                    dui.State = annotation.State;
151
                    annotatingUsersDto.Add(dui);
152
                }
141 153

  
142 154
                DocumentListInfo dai = mapper.Map<DocumentListInfo>(document);
143 155
                dai.AnnotatingUsers = annotatingUsersDto;
Backend/Models/Documents/DocumentListInfo.cs
14 14
    public string Name { get; set; }
15 15
    public int Length { get; set; }
16 16
    public int RequiredAnnotations { get; set; }
17
    public List<UserInfo> AnnotatingUsers { get; set; } = new();
17
    public List<DocumentUserInfo> AnnotatingUsers { get; set; } = new();
18 18
}
Backend/Models/Users/DocumentUserInfo.cs
1
using Models.Enums;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7

  
8
namespace Models.Users
9
{
10
    public class DocumentUserInfo
11
    {
12
        public Guid Id { get; set; }
13
        public string Username { get; set; }
14
        public string Name { get; set; }
15
        public string Surname { get; set; }
16
        public EState State { get; set; }
17
    }
18
}

Také k dispozici: Unified diff