From eb2395516fae06725a79c6b0f35280809035cece Mon Sep 17 00:00:00 2001
From: esantangelo <enzo020895@gmail.com>
Date: Tue, 8 Dec 2020 22:55:03 -0300
Subject: [PATCH] add evaluation type endpoints

---
 .../Controllers/EvaluationController.cs       | 33 ++++++++++++++++++-
 Tsi1.Api/Tsi1.Api/Startup.cs                  |  1 +
 .../Interfaces/IEvaluationTypeService.cs      |  2 +-
 .../Services/EvaluationTypeService.cs         |  2 +-
 4 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/Tsi1.Api/Tsi1.Api/Controllers/EvaluationController.cs b/Tsi1.Api/Tsi1.Api/Controllers/EvaluationController.cs
index 669c0e2..a0b1f65 100644
--- a/Tsi1.Api/Tsi1.Api/Controllers/EvaluationController.cs
+++ b/Tsi1.Api/Tsi1.Api/Controllers/EvaluationController.cs
@@ -16,10 +16,13 @@ namespace Tsi1.Api.Controllers
     public class EvaluationController : ControllerBase
     {
         private readonly IEvaluationService _evaluationService;
+        private readonly IEvaluationTypeService _evaluationTypeService;
 
-        public EvaluationController(IEvaluationService evaluationService)
+
+        public EvaluationController(IEvaluationService evaluationService, IEvaluationTypeService evaluationTypeService)
         {
             _evaluationService = evaluationService;
+            _evaluationTypeService = evaluationTypeService;
         }
 
         [Authorize(Roles = UserTypes.Student)]
@@ -134,5 +137,33 @@ namespace Tsi1.Api.Controllers
 
             return Ok(result.Data);
         }
+
+        [Authorize(Roles = UserTypes.Student + ", " + UserTypes.FacultyAdmin + ", " + UserTypes.Professor)]
+        [HttpGet("GetEvaluationTypes")]
+        public async Task<IActionResult> GetEvaluationTypes()
+        {
+            var result = await _evaluationTypeService.GetAll();
+
+            if (result.HasError)
+            {
+                return BadRequest(result.Message);
+            }
+
+            return Ok(result.Data);
+        }
+
+        [Authorize(Roles = UserTypes.Student + ", " + UserTypes.FacultyAdmin + ", " + UserTypes.Professor)]
+        [HttpGet("GetEvaluationTypeById/{evaluationTypeId}")]
+        public async Task<IActionResult> GetEvaluationTypeById(int evaluationTypeId)
+        {
+            var result = await _evaluationTypeService.GetById(evaluationTypeId);
+
+            if (result.HasError)
+            {
+                return BadRequest(result.Message);
+            }
+
+            return Ok(result.Data);
+        }
     }
 }
diff --git a/Tsi1.Api/Tsi1.Api/Startup.cs b/Tsi1.Api/Tsi1.Api/Startup.cs
index 1f237ec..c576fde 100644
--- a/Tsi1.Api/Tsi1.Api/Startup.cs
+++ b/Tsi1.Api/Tsi1.Api/Startup.cs
@@ -107,6 +107,7 @@ namespace Tsi1.Api
             services.AddScoped<IChatService, ChatService>();
             services.AddScoped<IActivityService, ActivityService>();
             services.AddScoped<IEvaluationService, EvaluationService>();
+            services.AddScoped<IEvaluationTypeService, EvaluationTypeService>();
 
             services.AddSingleton<PresenceTracker>();
 
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationTypeService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationTypeService.cs
index 55ac357..ec7b5bf 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationTypeService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Interfaces/IEvaluationTypeService.cs
@@ -11,6 +11,6 @@ namespace Tsi1.BusinessLayer.Interfaces
     {
         public Task<ServiceResult<EvaluationTypeDto>> GetById(int id);
 
-        public Task<ServiceResult<List<EvaluationTypeDto>>> GetAll(string userType);
+        public Task<ServiceResult<List<EvaluationTypeDto>>> GetAll();
     }
 }
diff --git a/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationTypeService.cs b/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationTypeService.cs
index d2ce280..a3ea2c3 100644
--- a/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationTypeService.cs
+++ b/Tsi1.Api/Tsi1.BusinessLayer/Services/EvaluationTypeService.cs
@@ -22,7 +22,7 @@ namespace Tsi1.BusinessLayer.Services
             _mapper = mapper;
         }
 
-        public async Task<ServiceResult<List<EvaluationTypeDto>>> GetAll(string userType)
+        public async Task<ServiceResult<List<EvaluationTypeDto>>> GetAll()
         {
             var result = new ServiceResult<List<EvaluationTypeDto>>();
 
-- 
GitLab