commit 6bdb3d9579457212b04dd5a9d5df5898aadaa594
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Fri Apr 15 13:24:35 2022 +0200

    Endpoint /user/annotations for user's annotations
    
    Added endpoint to UserController

diff --git a/Backend/Backend/Controllers/UserController.cs b/Backend/Backend/Controllers/UserController.cs
index a619ed3..5886b1d 100644
--- a/Backend/Backend/Controllers/UserController.cs
+++ b/Backend/Backend/Controllers/UserController.cs
@@ -1,4 +1,5 @@
 ﻿using Core.Services;
+using Core.Services.AnnotationService;
 using Microsoft.AspNetCore.Mvc;
 using Models.Users;
 using RestAPI.Authentication;
@@ -13,11 +14,13 @@ namespace RestAPI.Controllers
     {
         private readonly Serilog.ILogger logger;
         private readonly IUserService userService;
+        private readonly IAnnotationService annotationService;
 
-        public UserController(Serilog.ILogger logger, IUserService userService)
+        public UserController(Serilog.ILogger logger, IUserService userService, IAnnotationService annotationService)
         {
             this.logger = logger;
             this.userService = userService;
+            this.annotationService = annotationService;
         }
 
         [HttpGet("/users")]
@@ -42,7 +45,22 @@ namespace RestAPI.Controllers
                 throw new InternalErrorException(e.Message);
             }
 
-            
+
+        }
+
+        [HttpGet("/user/annotations")]
+        [ProducesResponseType((int)HttpStatusCode.OK)]
+        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+        public ActionResult GetUserAnnotations([FromServices] ClientInfo clientInfo)
+        {
+            if (clientInfo.LoggedUser == null)
+            {
+                logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations");
+                return Problem();
+            }
+
+            var res = annotationService.GetUserAnnotations(clientInfo.LoggedUser.Id);
+            return Ok(res);
         }
     }
 }
diff --git a/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs b/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
index 89e4803..1ca9463 100644
--- a/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
+++ b/Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
@@ -8,6 +8,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using Microsoft.EntityFrameworkCore;
 
 namespace Core.Services.AnnotationService
 {
@@ -34,7 +35,7 @@ namespace Core.Services.AnnotationService
                 throw new InvalidOperationException($"{request.DocumentIdList.Count - documents.Count()} of the received documents do not exist");
             }
 
-            var users = context.Users.Where(u => request.UserIdList.Contains(u.Id)).ToList(); 
+            var users = context.Users.Where(u => request.UserIdList.Contains(u.Id)).ToList();
             foreach (var user in users)
             {
                 var userAnnotatedDocuments = context.Annotations.Where(a => a.User == user).Select(a => a.Document).ToList();
@@ -61,5 +62,29 @@ namespace Core.Services.AnnotationService
 
             context.SaveChanges();
         }
+
+        public AnnotationListResponse GetUserAnnotations(Guid userId)
+        {
+            var annotations = context.Annotations.Where(a => a.User.Id == userId).Include(a => a.Document).ToList();
+            var documentIds = annotations.Select(a => a.Document.Id).ToList();
+            var documents = context.Documents.Where(d => documentIds.Contains(d.Id));
+            var infos = new List<AnnotationListInfo>();
+
+            var annotationsDocuments = annotations.Zip(documents, (a, d) => new { Annotation = a, Document = d });
+            foreach (var ad in annotationsDocuments)
+            {
+                infos.Add(new AnnotationListInfo()
+                {
+                    AnnotationId = ad.Annotation.Id,
+                    DocumentName = ad.Document.Name,
+                    State = ad.Annotation.State
+                });
+            }
+
+            return new AnnotationListResponse()
+            {
+                Annotations = infos
+            };
+        }
     }
 }
diff --git a/Backend/Core/Services/AnnotationService/IAnnotationService.cs b/Backend/Core/Services/AnnotationService/IAnnotationService.cs
index 2cc5f70..d09c469 100644
--- a/Backend/Core/Services/AnnotationService/IAnnotationService.cs
+++ b/Backend/Core/Services/AnnotationService/IAnnotationService.cs
@@ -10,5 +10,6 @@ namespace Core.Services.AnnotationService
     public interface IAnnotationService
     {
         public void CreateDocumentAnnotations(AnnotationsAddRequest request, Guid userId);
+        public AnnotationListResponse GetUserAnnotations(Guid userId);
     }
 }
diff --git a/Backend/Models/Annotations/AnnotationListInfo.cs b/Backend/Models/Annotations/AnnotationListInfo.cs
new file mode 100644
index 0000000..cfdc28d
--- /dev/null
+++ b/Backend/Models/Annotations/AnnotationListInfo.cs
@@ -0,0 +1,16 @@
+﻿using Models.Enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Models.Annotations
+{
+    public class AnnotationListInfo
+    {
+        public string DocumentName { get; set; }
+        public EState State { get; set; }
+        public Guid AnnotationId { get; set; }
+    }
+}
diff --git a/Backend/Models/Annotations/AnnotationListResponse.cs b/Backend/Models/Annotations/AnnotationListResponse.cs
new file mode 100644
index 0000000..4fb0d17
--- /dev/null
+++ b/Backend/Models/Annotations/AnnotationListResponse.cs
@@ -0,0 +1,13 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Models.Annotations
+{
+    public class AnnotationListResponse
+    {
+        public List<AnnotationListInfo> Annotations { get; set; } = new();
+    }
+}
