commit a70f3c5f092fa8a8ee16c38478764ae64fe94fb4
Author: Vojtěch Bartička <aitakaitov@gmail.com>
Date:   Mon Apr 11 19:15:25 2022 +0200

    Added UserController and GET on /users

diff --git a/Backend/Backend/Controllers/UserController.cs b/Backend/Backend/Controllers/UserController.cs
new file mode 100644
index 0000000..4990a61
--- /dev/null
+++ b/Backend/Backend/Controllers/UserController.cs
@@ -0,0 +1,48 @@
+﻿using Core.Services;
+using Microsoft.AspNetCore.Mvc;
+using Models.Users;
+using RestAPI.Authentication;
+using RestAPI.Controllers.Common;
+using RestAPI.Exceptions;
+using RestAPI.Utils;
+using System.Net;
+
+namespace RestAPI.Controllers
+{
+    public class UserController : CommonControllerBase
+    {
+        private readonly Serilog.ILogger logger;
+        private readonly IUserService userService;
+
+        public UserController(Serilog.ILogger logger, IUserService userService)
+        {
+            this.logger = logger;
+            this.userService = userService;
+        }
+
+        [HttpGet("/users")]
+        [Authorize(Models.Enums.ERole.ADMINISTRATOR)]
+        [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(UserList))]
+        [ProducesResponseType((int)HttpStatusCode.Forbidden)]
+        public ActionResult<UserList> GetUsers([FromServices] ClientInfo clientInfo)
+        {
+            if (clientInfo.LoggedUser == null)
+            {
+                logger.Warning("ClientInfo has null LoggerUser in [Authorized] controller /annotations");
+                return Problem();
+            }
+
+            try
+            {
+                var userList = userService.GetUsers();
+                return Ok(userList);
+            }
+            catch (Exception e)
+            {
+                throw new InternalErrorException(e.Message);
+            }
+
+            
+        }
+    }
+}
diff --git a/Backend/Core/Services/UserService/IUserService.cs b/Backend/Core/Services/UserService/IUserService.cs
index 96b3457..9a57dc0 100644
--- a/Backend/Core/Services/UserService/IUserService.cs
+++ b/Backend/Core/Services/UserService/IUserService.cs
@@ -1,5 +1,6 @@
 ﻿using Core.Entities;
 using Models.Enums;
+using Models.Users;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -16,5 +17,6 @@ namespace Core.Services
         public User UpdateUser(User user, string? username = null, string? name = null, string? surname = null, ERole? role = null);
         public User ChangePassword(User user, string newPassword);
         public User? CheckUsernamePassword(string username, string password);
+        public UserList GetUsers();
     }
 }
diff --git a/Backend/Core/Services/UserService/UserServiceEF.cs b/Backend/Core/Services/UserService/UserServiceEF.cs
index c3ca409..5a2c9b6 100644
--- a/Backend/Core/Services/UserService/UserServiceEF.cs
+++ b/Backend/Core/Services/UserService/UserServiceEF.cs
@@ -8,6 +8,8 @@ using System.Text;
 using System.Threading.Tasks;
 using Serilog;
 using BCrypt.Net;
+using Models.Users;
+using AutoMapper;
 
 namespace Core.Services
 {
@@ -15,11 +17,13 @@ namespace Core.Services
     {
         private readonly DatabaseContext _databaseContext;
         private readonly ILogger _logger;
+        private readonly IMapper _mapper;
 
-        public UserServiceEF(DatabaseContext context, ILogger logger)
+        public UserServiceEF(DatabaseContext context, ILogger logger, IMapper mapper)
         {
             _databaseContext = context;
             _logger = logger;
+            _mapper = mapper;
         }
 
         public User ChangePassword(User user, string newPassword)
@@ -141,5 +145,17 @@ namespace Core.Services
             _databaseContext.SaveChanges();
             return user;
         }
+
+        public UserList GetUsers()
+        {
+            var users = _databaseContext.Users.Select(u => u);
+            UserList userList = new UserList();
+            foreach (var user in users)
+            {
+                userList.Users.Add(_mapper.Map<UserInfo>(user));
+            }
+
+            return userList;
+        }
     }
 }
diff --git a/Backend/Models/Users/UserList.cs b/Backend/Models/Users/UserList.cs
new file mode 100644
index 0000000..476e81a
--- /dev/null
+++ b/Backend/Models/Users/UserList.cs
@@ -0,0 +1,13 @@
+﻿using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Models.Users
+{
+    public class UserList
+    {
+        public List<UserInfo> Users { get; set; } = new();
+    }
+}
