From d37e87b456bdd250a141c5d2853541420c8eedbc Mon Sep 17 00:00:00 2001
From: Matej Vavrek <matvav13@gmail.com>
Date: Tue, 12 Nov 2024 16:16:54 +0100
Subject: [PATCH 1/5] Prefixed API endpoints with /api/

---
 Api/Controllers/EventCommentController.cs          | 2 +-
 Api/Controllers/EventController.cs                 | 2 +-
 Api/Controllers/EventParticipantController.cs      | 2 +-
 Api/Controllers/LocationController.cs              | 2 +-
 Api/Controllers/RestaurantController.cs            | 2 +-
 Api/Controllers/ReviewAggregateResultController.cs | 2 +-
 Api/Controllers/ReviewCommentController.cs         | 2 +-
 Api/Controllers/ReviewController.cs                | 2 +-
 Api/Controllers/UserController.cs                  | 2 +-
 9 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/Api/Controllers/EventCommentController.cs b/Api/Controllers/EventCommentController.cs
index f0288f8..a8f55be 100644
--- a/Api/Controllers/EventCommentController.cs
+++ b/Api/Controllers/EventCommentController.cs
@@ -6,7 +6,7 @@ using BusinessLayer.Utils.Filters;
 
 namespace Api.Controllers
 {
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     [ApiController]
     public class EventCommentController : Controller
     {
diff --git a/Api/Controllers/EventController.cs b/Api/Controllers/EventController.cs
index e6bb967..c1ec93f 100644
--- a/Api/Controllers/EventController.cs
+++ b/Api/Controllers/EventController.cs
@@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
 {
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     [ApiController]
     public class EventController : Controller
     {
diff --git a/Api/Controllers/EventParticipantController.cs b/Api/Controllers/EventParticipantController.cs
index 2ddf5c5..6888d6a 100644
--- a/Api/Controllers/EventParticipantController.cs
+++ b/Api/Controllers/EventParticipantController.cs
@@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
 {
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     [ApiController]
     public class EventParticipantController : Controller
     {
diff --git a/Api/Controllers/LocationController.cs b/Api/Controllers/LocationController.cs
index 11a3f24..2d77d15 100644
--- a/Api/Controllers/LocationController.cs
+++ b/Api/Controllers/LocationController.cs
@@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
 {
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     [ApiController]
     public class LocationController(ILocationService locationService) : Controller
     {
diff --git a/Api/Controllers/RestaurantController.cs b/Api/Controllers/RestaurantController.cs
index 2c3923e..ddf4a8b 100644
--- a/Api/Controllers/RestaurantController.cs
+++ b/Api/Controllers/RestaurantController.cs
@@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
 {
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     [ApiController]
     public class RestaurantController(
         IRestaurantService restaurantService,
diff --git a/Api/Controllers/ReviewAggregateResultController.cs b/Api/Controllers/ReviewAggregateResultController.cs
index eb4cfb0..7edab9d 100644
--- a/Api/Controllers/ReviewAggregateResultController.cs
+++ b/Api/Controllers/ReviewAggregateResultController.cs
@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc;
 namespace Api.Controllers
 {
     [ApiController]
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     public class ReviewAggregateResultController : Controller
     {
         private readonly IReviewAggregateResultService _service;
diff --git a/Api/Controllers/ReviewCommentController.cs b/Api/Controllers/ReviewCommentController.cs
index 85e05b2..a2cc685 100644
--- a/Api/Controllers/ReviewCommentController.cs
+++ b/Api/Controllers/ReviewCommentController.cs
@@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc;
 namespace Api.Controllers
 {
     [ApiController]
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     public class ReviewCommentController : Controller
     {
         private readonly IReviewCommentService _service;
diff --git a/Api/Controllers/ReviewController.cs b/Api/Controllers/ReviewController.cs
index 3601ab9..6095a25 100644
--- a/Api/Controllers/ReviewController.cs
+++ b/Api/Controllers/ReviewController.cs
@@ -7,7 +7,7 @@ using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
 {
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     [ApiController]
     public class ReviewController : Controller
     {
diff --git a/Api/Controllers/UserController.cs b/Api/Controllers/UserController.cs
index 1a92514..f1bca6a 100644
--- a/Api/Controllers/UserController.cs
+++ b/Api/Controllers/UserController.cs
@@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
 {
-    [Route("/[controller]")]
+    [Route("/api/[controller]")]
     [ApiController]
     public class UserController(IUserService userService) : Controller
     {
-- 
GitLab


From 3267bcd83c56cab2ccaa615f520dbeb1bbfe2875 Mon Sep 17 00:00:00 2001
From: Matej Vavrek <matvav13@gmail.com>
Date: Wed, 13 Nov 2024 00:28:27 +0100
Subject: [PATCH 2/5] Fixed up some warnings in services, made sure all DTOs
 are records

---
 BusinessLayer/DTOs/Event/EventCreateDTO.cs             |  2 +-
 BusinessLayer/DTOs/Event/EventDTO.cs                   |  2 +-
 BusinessLayer/DTOs/Event/EventInfoDTO.cs               |  2 +-
 BusinessLayer/DTOs/Event/EventUpdateDTO.cs             |  2 +-
 .../DTOs/EventComment/EventCommentCreateDTO.cs         |  2 +-
 BusinessLayer/DTOs/EventComment/EventCommentDTO.cs     |  2 +-
 .../DTOs/EventComment/EventCommentUpdateDTO.cs         |  2 +-
 .../DTOs/EventParticipant/EventParticipantCreateDTO.cs |  2 +-
 .../DTOs/EventParticipant/EventParticipantDTO.cs       |  2 +-
 .../DTOs/EventParticipant/EventParticipantUpdateDTO.cs |  2 +-
 BusinessLayer/DTOs/Review/ReviewDTO.cs                 |  3 +--
 BusinessLayer/DTOs/Review/ReviewDetailDTO.cs           |  2 +-
 .../DTOs/ReviewAggregate/ReviewAggregateDTO.cs         |  2 +-
 .../DTOs/ReviewComment/ReviewCommentCreateDTO.cs       |  2 +-
 BusinessLayer/DTOs/ReviewComment/ReviewCommentDTO.cs   |  2 +-
 .../DTOs/ReviewComment/ReviewCommentUpdateDTO.cs       |  2 +-
 BusinessLayer/DTOs/User/UserDetailDto.cs               |  2 +-
 .../EventCommentService/EventCommentService.cs         |  4 ++--
 .../Services/RestaurantService/RestaurantService.cs    | 10 +++++-----
 BusinessLayer/Services/UserService/IUserService.cs     |  2 +-
 BusinessLayer/Services/UserService/UserService.cs      |  2 +-
 BusinessLayer/Utils/Ordering/OrderingManager.cs        |  6 +++---
 22 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/BusinessLayer/DTOs/Event/EventCreateDTO.cs b/BusinessLayer/DTOs/Event/EventCreateDTO.cs
index 5081225..4c0c7d9 100644
--- a/BusinessLayer/DTOs/Event/EventCreateDTO.cs
+++ b/BusinessLayer/DTOs/Event/EventCreateDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.Event
 {
-    public class EventCreateDTO
+    public record EventCreateDTO
     {
         [Required]
         public Guid CreatorId { get; set; }
diff --git a/BusinessLayer/DTOs/Event/EventDTO.cs b/BusinessLayer/DTOs/Event/EventDTO.cs
index 24379c5..ebcce05 100644
--- a/BusinessLayer/DTOs/Event/EventDTO.cs
+++ b/BusinessLayer/DTOs/Event/EventDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.Event
 {
-    public class EventDTO
+    public record EventDTO
     {
         public Guid Id { get; set; }
         public required string Title { get; set; }
diff --git a/BusinessLayer/DTOs/Event/EventInfoDTO.cs b/BusinessLayer/DTOs/Event/EventInfoDTO.cs
index 9fbc7b3..77e2276 100644
--- a/BusinessLayer/DTOs/Event/EventInfoDTO.cs
+++ b/BusinessLayer/DTOs/Event/EventInfoDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.Event
 {
-    public class EventInfoDTO
+    public record EventInfoDTO
     {
         public required string Title { get; set; }
         public DateTime Date { get; set; }
diff --git a/BusinessLayer/DTOs/Event/EventUpdateDTO.cs b/BusinessLayer/DTOs/Event/EventUpdateDTO.cs
index b86129b..18f93a7 100644
--- a/BusinessLayer/DTOs/Event/EventUpdateDTO.cs
+++ b/BusinessLayer/DTOs/Event/EventUpdateDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.Event
 {
-    public class EventUpdateDTO
+    public record EventUpdateDTO
     {
         [MaxLength(200)]
         public string? Title { get; set; }
diff --git a/BusinessLayer/DTOs/EventComment/EventCommentCreateDTO.cs b/BusinessLayer/DTOs/EventComment/EventCommentCreateDTO.cs
index e786c3e..7ecbcb3 100644
--- a/BusinessLayer/DTOs/EventComment/EventCommentCreateDTO.cs
+++ b/BusinessLayer/DTOs/EventComment/EventCommentCreateDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.EventComment
 {
-    public class EventCommentCreateDTO
+    public record EventCommentCreateDTO
     {
         [Required]
         public Guid PosterId { get; set; }
diff --git a/BusinessLayer/DTOs/EventComment/EventCommentDTO.cs b/BusinessLayer/DTOs/EventComment/EventCommentDTO.cs
index be0bd24..4272564 100644
--- a/BusinessLayer/DTOs/EventComment/EventCommentDTO.cs
+++ b/BusinessLayer/DTOs/EventComment/EventCommentDTO.cs
@@ -3,7 +3,7 @@ using BusinessLayer.DTOs.User;
 
 namespace BusinessLayer.DTOs.EventComment
 {
-    public class EventCommentDTO
+    public record EventCommentDTO
     {
         public Guid Id { get; set; }
         public UserDto? Poster { get; set; }
diff --git a/BusinessLayer/DTOs/EventComment/EventCommentUpdateDTO.cs b/BusinessLayer/DTOs/EventComment/EventCommentUpdateDTO.cs
index 6754d9d..eb7e2ac 100644
--- a/BusinessLayer/DTOs/EventComment/EventCommentUpdateDTO.cs
+++ b/BusinessLayer/DTOs/EventComment/EventCommentUpdateDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.EventComment
 {
-    public class EventCommentUpdateDTO
+    public record EventCommentUpdateDTO
     {
         [Required]
         [MaxLength(1800)]
diff --git a/BusinessLayer/DTOs/EventParticipant/EventParticipantCreateDTO.cs b/BusinessLayer/DTOs/EventParticipant/EventParticipantCreateDTO.cs
index 3b176a8..11dd75c 100644
--- a/BusinessLayer/DTOs/EventParticipant/EventParticipantCreateDTO.cs
+++ b/BusinessLayer/DTOs/EventParticipant/EventParticipantCreateDTO.cs
@@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
 
 namespace BusinessLayer.DTOs.EventParticipant
 {
-    public class EventParticipantCreateDTO
+    public record EventParticipantCreateDTO
     {
         [Required]
         public Guid UserId { get; set; }
diff --git a/BusinessLayer/DTOs/EventParticipant/EventParticipantDTO.cs b/BusinessLayer/DTOs/EventParticipant/EventParticipantDTO.cs
index 597327d..982dbc4 100644
--- a/BusinessLayer/DTOs/EventParticipant/EventParticipantDTO.cs
+++ b/BusinessLayer/DTOs/EventParticipant/EventParticipantDTO.cs
@@ -4,7 +4,7 @@ using DAL.Enums;
 
 namespace BusinessLayer.DTOs.EventParticipant
 {
-    public class EventParticipantDTO
+    public record EventParticipantDTO
     {
         public Guid Id { get; set; }
         public required UserDto User { get; set; }
diff --git a/BusinessLayer/DTOs/EventParticipant/EventParticipantUpdateDTO.cs b/BusinessLayer/DTOs/EventParticipant/EventParticipantUpdateDTO.cs
index 69f2298..5dec8f9 100644
--- a/BusinessLayer/DTOs/EventParticipant/EventParticipantUpdateDTO.cs
+++ b/BusinessLayer/DTOs/EventParticipant/EventParticipantUpdateDTO.cs
@@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations;
 
 namespace BusinessLayer.DTOs.EventParticipant
 {
-    public class EventParticipantUpdateDTO
+    public record EventParticipantUpdateDTO
     {
         [Required]
         public ParticipantType Attendance { get; set; }
diff --git a/BusinessLayer/DTOs/Review/ReviewDTO.cs b/BusinessLayer/DTOs/Review/ReviewDTO.cs
index e3483cb..de76c67 100644
--- a/BusinessLayer/DTOs/Review/ReviewDTO.cs
+++ b/BusinessLayer/DTOs/Review/ReviewDTO.cs
@@ -1,5 +1,4 @@
-using BusinessLayer.DTOs.Restaurant;
-using BusinessLayer.DTOs.User;
+using BusinessLayer.DTOs.User;
 
 namespace BusinessLayer.DTOs.Review
 {
diff --git a/BusinessLayer/DTOs/Review/ReviewDetailDTO.cs b/BusinessLayer/DTOs/Review/ReviewDetailDTO.cs
index 38d59cf..dc8eafe 100644
--- a/BusinessLayer/DTOs/Review/ReviewDetailDTO.cs
+++ b/BusinessLayer/DTOs/Review/ReviewDetailDTO.cs
@@ -3,7 +3,7 @@ using BusinessLayer.DTOs.User;
 
 namespace BusinessLayer.DTOs.Review
 {
-    public class ReviewDetailDTO
+    public record ReviewDetailDTO
     {
         public Guid Id { get; set; }
         public UserDto? Poster { get; set; }
diff --git a/BusinessLayer/DTOs/ReviewAggregate/ReviewAggregateDTO.cs b/BusinessLayer/DTOs/ReviewAggregate/ReviewAggregateDTO.cs
index 20f7c25..93be3a4 100644
--- a/BusinessLayer/DTOs/ReviewAggregate/ReviewAggregateDTO.cs
+++ b/BusinessLayer/DTOs/ReviewAggregate/ReviewAggregateDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.ReviewAggregate
 {
-    public class ReviewAggregateDTO
+    public record ReviewAggregateDTO
     {
         public Guid RestaurantId { get; set; }
         public RestaurantDto? Restaurant { get; set; }
diff --git a/BusinessLayer/DTOs/ReviewComment/ReviewCommentCreateDTO.cs b/BusinessLayer/DTOs/ReviewComment/ReviewCommentCreateDTO.cs
index 30fb014..766c7b7 100644
--- a/BusinessLayer/DTOs/ReviewComment/ReviewCommentCreateDTO.cs
+++ b/BusinessLayer/DTOs/ReviewComment/ReviewCommentCreateDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.ReviewComment
 {
-    public class ReviewCommentCreateDTO
+    public record ReviewCommentCreateDTO
     {
         [Required]
         public Guid PosterId { get; set; }
diff --git a/BusinessLayer/DTOs/ReviewComment/ReviewCommentDTO.cs b/BusinessLayer/DTOs/ReviewComment/ReviewCommentDTO.cs
index f04db4b..3640089 100644
--- a/BusinessLayer/DTOs/ReviewComment/ReviewCommentDTO.cs
+++ b/BusinessLayer/DTOs/ReviewComment/ReviewCommentDTO.cs
@@ -3,7 +3,7 @@ using BusinessLayer.DTOs.User;
 
 namespace BusinessLayer.DTOs.ReviewComment
 {
-    public class ReviewCommentDTO
+    public record ReviewCommentDTO
     {
         public Guid Id { get; set; }
         public UserDto? Poster { get; set; }
diff --git a/BusinessLayer/DTOs/ReviewComment/ReviewCommentUpdateDTO.cs b/BusinessLayer/DTOs/ReviewComment/ReviewCommentUpdateDTO.cs
index 6af02e9..03c872b 100644
--- a/BusinessLayer/DTOs/ReviewComment/ReviewCommentUpdateDTO.cs
+++ b/BusinessLayer/DTOs/ReviewComment/ReviewCommentUpdateDTO.cs
@@ -2,7 +2,7 @@
 
 namespace BusinessLayer.DTOs.ReviewComment
 {
-    public class ReviewCommentUpdateDTO
+    public record ReviewCommentUpdateDTO
     {
         [Required]
         [MaxLength(1800)]
diff --git a/BusinessLayer/DTOs/User/UserDetailDto.cs b/BusinessLayer/DTOs/User/UserDetailDto.cs
index d3781b1..f5b4693 100644
--- a/BusinessLayer/DTOs/User/UserDetailDto.cs
+++ b/BusinessLayer/DTOs/User/UserDetailDto.cs
@@ -2,7 +2,7 @@ using BusinessLayer.DTOs.Restaurant;
 
 namespace BusinessLayer.DTOs.User
 {
-    public class UserDetailDto
+    public record UserDetailDto
     {
         public Guid Id { get; set; }
         public required string Name { get; set; }
diff --git a/BusinessLayer/Services/EventCommentService/EventCommentService.cs b/BusinessLayer/Services/EventCommentService/EventCommentService.cs
index 942bbfe..4cce676 100644
--- a/BusinessLayer/Services/EventCommentService/EventCommentService.cs
+++ b/BusinessLayer/Services/EventCommentService/EventCommentService.cs
@@ -77,8 +77,8 @@ namespace BusinessLayer.Services.EventCommentService
 
             var result = await query.SingleOrDefaultAsync(c => c.Id == id && c.DeletedAt == null);
             if (result == null
-                || (includeUser && result.Poster.DeletedAt != null)
-                || (includeEvent && result.Event.DeletedAt != null))
+                || (includeUser && result.Poster!.DeletedAt != null)
+                || (includeEvent && result.Event!.DeletedAt != null))
             {
                 return null;
             }
diff --git a/BusinessLayer/Services/RestaurantService/RestaurantService.cs b/BusinessLayer/Services/RestaurantService/RestaurantService.cs
index dc68e93..5f88f28 100644
--- a/BusinessLayer/Services/RestaurantService/RestaurantService.cs
+++ b/BusinessLayer/Services/RestaurantService/RestaurantService.cs
@@ -12,7 +12,7 @@ namespace BusinessLayer.Services.RestaurantService
     public class RestaurantService(RestaurantDBContext dbContext) : BaseService(dbContext), IRestaurantService
     {
         private readonly RestaurantDBContext _dbContext = dbContext;
-        
+
         public async Task<List<RestaurantDto>> GetRestaurantsAsync(
             RestaurantFilter filter,
             RestaurantOrdering orderBy,
@@ -36,7 +36,7 @@ namespace BusinessLayer.Services.RestaurantService
                 .Include(r => r.RestaurantMaintainers)
                 .Include(r => r.Location)
                 .SingleOrDefaultAsync(r => r.Id == id);
-            
+
             if (restaurant is null || restaurant.DeletedAt is not null)
             {
                 return null;
@@ -48,12 +48,12 @@ namespace BusinessLayer.Services.RestaurantService
         public async Task<RestaurantDetailDto?> CreateRestaurantAsync(RestaurantCreateDto data)
         {
             var maintainer = await _dbContext.Users.FindAsync(data.MaintainerId);
-            
+
             if (maintainer is null || maintainer.DeletedAt is not null)
             {
                 return null;
             }
-            
+
             var restaurantId = Guid.NewGuid();
 
             var restaurant = new Restaurant
@@ -75,7 +75,7 @@ namespace BusinessLayer.Services.RestaurantService
                     Zipcode = data.Location.Zipcode
                 }
             };
-            
+
             await _dbContext.Restaurants.AddAsync(restaurant);
             maintainer.MaintainedRestaurants.Add(restaurant);
             await _dbContext.SaveChangesAsync();
diff --git a/BusinessLayer/Services/UserService/IUserService.cs b/BusinessLayer/Services/UserService/IUserService.cs
index ef7802e..1a8b49c 100644
--- a/BusinessLayer/Services/UserService/IUserService.cs
+++ b/BusinessLayer/Services/UserService/IUserService.cs
@@ -13,7 +13,7 @@ namespace BusinessLayer.Services.UserService
             int offset = 0,
             Guid[]? ids = null);
         public Task<UserDetailDto?> GetUserAsync(Guid id);
-        public Task<UserDetailDto?> CreateUserAsync(UserCreateDto restaurant);
+        public Task<UserDetailDto> CreateUserAsync(UserCreateDto restaurant);
         public Task<UserDetailDto?> UpdateUserAsync(
             Guid id,
             UserUpdateDto restaurant);
diff --git a/BusinessLayer/Services/UserService/UserService.cs b/BusinessLayer/Services/UserService/UserService.cs
index 5614c2f..95da007 100644
--- a/BusinessLayer/Services/UserService/UserService.cs
+++ b/BusinessLayer/Services/UserService/UserService.cs
@@ -41,7 +41,7 @@ namespace BusinessLayer.Services.UserService
             return user.Adapt<UserDetailDto>();
         }
 
-        public async Task<UserDetailDto?> CreateUserAsync(UserCreateDto data)
+        public async Task<UserDetailDto> CreateUserAsync(UserCreateDto data)
         {
             var user = new User
             {
diff --git a/BusinessLayer/Utils/Ordering/OrderingManager.cs b/BusinessLayer/Utils/Ordering/OrderingManager.cs
index 0c271fe..96c0a02 100644
--- a/BusinessLayer/Utils/Ordering/OrderingManager.cs
+++ b/BusinessLayer/Utils/Ordering/OrderingManager.cs
@@ -65,15 +65,15 @@ namespace BusinessLayer.Utils.Ordering
         }
 
         public static IOrderedQueryable<Event> ApplyOrdering(
-            this IQueryable<Event> query, 
+            this IQueryable<Event> query,
             EventOrdering orderBy)
         {
             return orderBy switch
             {
                 EventOrdering.DateAscending => query.OrderBy(e => e.Date),
                 EventOrdering.DateDescending => query.OrderByDescending(e => e.Date),
-                EventOrdering.RestaurantNameAscending => query.OrderBy(e => e.Restaurant.Name),
-                EventOrdering.RestaurantNameDescending => query.OrderByDescending(e => e.Restaurant.Name),
+                EventOrdering.RestaurantNameAscending => query.OrderBy(e => e.Restaurant!.Name),
+                EventOrdering.RestaurantNameDescending => query.OrderByDescending(e => e.Restaurant!.Name),
                 _ => query.OrderBy(e => e.Date)
             };
         }
-- 
GitLab


From 61c68696a077165cccfbe35df74e11be2c845ca7 Mon Sep 17 00:00:00 2001
From: Matej Vavrek <matvav13@gmail.com>
Date: Wed, 13 Nov 2024 00:28:59 +0100
Subject: [PATCH 3/5] Removed converter.cs, made sure all APIs use Models and
 are not as dependent on the BL DTOs.

---
 Api/Controllers/EventCommentController.cs     |  15 +-
 Api/Controllers/EventController.cs            |  24 +-
 Api/Controllers/EventParticipantController.cs |  32 +--
 Api/Controllers/LocationController.cs         |  30 +--
 Api/Controllers/RestaurantController.cs       |  21 +-
 .../ReviewAggregateResultController.cs        |   9 +-
 Api/Controllers/ReviewCommentController.cs    |  26 ++-
 Api/Controllers/ReviewController.cs           |  26 ++-
 Api/Controllers/UserController.cs             |  49 +++--
 Api/Models/Converter.cs                       | 205 ------------------
 Api/Models/Event/EventInfoModel.cs            |  11 +
 Api/Models/EventComment/EventCommentModel.cs  |  12 +-
 .../Restaurant/RestaurantDetailModel.cs       |   3 +-
 Api/Models/Restaurant/RestaurantModel.cs      |   6 +-
 Api/Models/Review/ReviewDetailModel.cs        |  22 ++
 Api/Models/Review/ReviewModel.cs              |   6 +-
 Api/Models/User/UserModel.cs                  |   1 -
 17 files changed, 184 insertions(+), 314 deletions(-)
 delete mode 100644 Api/Models/Converter.cs
 create mode 100644 Api/Models/Event/EventInfoModel.cs
 create mode 100644 Api/Models/Review/ReviewDetailModel.cs

diff --git a/Api/Controllers/EventCommentController.cs b/Api/Controllers/EventCommentController.cs
index a8f55be..ca56b60 100644
--- a/Api/Controllers/EventCommentController.cs
+++ b/Api/Controllers/EventCommentController.cs
@@ -3,6 +3,7 @@ using BusinessLayer.DTOs.EventComment;
 using BusinessLayer.Services.EventCommentService;
 using Microsoft.AspNetCore.Mvc;
 using BusinessLayer.Utils.Filters;
+using Mapster;
 
 namespace Api.Controllers
 {
@@ -26,13 +27,16 @@ namespace Api.Controllers
                 return NotFound();
             }
 
-            return Ok(comment);
+            return Ok(comment.Adapt<EventCommentModel>());
         }
 
         [HttpGet]
         public async Task<IActionResult> GetEventComments([FromQuery] EventCommentFilter filter, [FromQuery] int limit = 0, [FromQuery] int offset = 0)
         {
-            var comments = await _eventCommentService.GetCommentsAsync(filter, limit, offset, includeUser: true, includeEvent: true, includeChildren: true);
+            var comments = (await _eventCommentService
+                .GetCommentsAsync(filter, limit, offset, includeUser: true, includeEvent: true, includeChildren: true))
+                .Select(c => c.Adapt<EventCommentModel>())
+                .ToList();
             return Ok(comments);
         }
 
@@ -53,7 +57,10 @@ namespace Api.Controllers
                 return NotFound("Poster or Event not found, or parent comment does not exist.");
             }
 
-            return CreatedAtAction(nameof(GetEventCommentById), new { commentId = result.Id }, result);
+            return CreatedAtAction(
+                nameof(GetEventCommentById),
+                new { commentId = result.Id },
+                result.Adapt<EventCommentModel>());
         }
 
         [HttpPatch("{commentId:guid}")]
@@ -70,7 +77,7 @@ namespace Api.Controllers
                 return NotFound();
             }
 
-            return Ok(result);
+            return Ok(result.Adapt<EventCommentModel>());
         }
 
         [HttpDelete("{commentId:guid}")]
diff --git a/Api/Controllers/EventController.cs b/Api/Controllers/EventController.cs
index c1ec93f..4036e11 100644
--- a/Api/Controllers/EventController.cs
+++ b/Api/Controllers/EventController.cs
@@ -3,6 +3,7 @@ using BusinessLayer.DTOs.Event;
 using BusinessLayer.Services.EventService;
 using BusinessLayer.Utils.Filters;
 using BusinessLayer.Utils.Ordering;
+using Mapster;
 using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
@@ -27,14 +28,16 @@ namespace Api.Controllers
                 return NotFound();
             }
 
-            return Ok(eventEntity);
+            return Ok(eventEntity.Adapt<EventModel>());
         }
 
         [HttpGet]
         public async Task<IActionResult> GetEvents([FromQuery] EventFilter filter, EventOrdering eventOrder = EventOrdering.DateAscending, [FromQuery] int limit = 0, [FromQuery] int offset = 0)
         {
-            var events = await _eventService.GetEventsAsync(filter,eventOrder, limit, offset);
-            return Ok(events);
+            var events = await _eventService.GetEventsAsync(filter, eventOrder, limit, offset);
+            return Ok(events
+                .Select(e => e.Adapt<EventInfoModel>())
+                .ToList());
         }
 
         [HttpPost]
@@ -50,12 +53,13 @@ namespace Api.Controllers
             };
 
             var result = await _eventService.CreateEventAsync(createDTO);
-            if (result is null)
-            {
-                return NotFound("Creator or restaurant does not exist.");
-            }
 
-            return CreatedAtAction(nameof(GetEventById), new { eventId = result.Id }, result);
+            return result is null
+                ? NotFound("Creator or restaurant does not exist.")
+                : CreatedAtAction(
+                nameof(GetEventById),
+                new { eventId = result.Id },
+                result.Adapt<EventModel>());
         }
 
         [HttpPatch("{eventId:guid}")]
@@ -69,18 +73,20 @@ namespace Api.Controllers
             };
 
             var result = await _eventService.UpdateEventAsync(eventId, updateDTO);
+
             if (result is null)
             {
                 return NotFound();
             }
 
-            return Ok(result);
+            return Ok(result.Adapt<EventModel>());
         }
 
         [HttpDelete("{eventId:guid}")]
         public async Task<IActionResult> DeleteEvent([FromRoute] Guid eventId)
         {
             var success = await _eventService.DeleteEventAsync(eventId);
+
             if (!success)
             {
                 return NotFound();
diff --git a/Api/Controllers/EventParticipantController.cs b/Api/Controllers/EventParticipantController.cs
index 6888d6a..cd05a4b 100644
--- a/Api/Controllers/EventParticipantController.cs
+++ b/Api/Controllers/EventParticipantController.cs
@@ -2,6 +2,7 @@
 using BusinessLayer.DTOs.EventParticipant;
 using BusinessLayer.Services.EventParticipantService;
 using BusinessLayer.Utils.Filters;
+using Mapster;
 using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
@@ -26,14 +27,16 @@ namespace Api.Controllers
                 return NotFound();
             }
 
-            return Ok(participant);
+            return Ok(participant.Adapt<EventParticipantModel>());
         }
 
         [HttpGet]
         public async Task<IActionResult> GetEventParticipants([FromQuery] EventParticipantFilter filter, [FromQuery] int limit = 0, [FromQuery] int offset = 0)
         {
             var participants = await _eventParticipantService.GetParticipantsAsync(filter, limit, offset);
-            return Ok(participants);
+            return Ok(participants
+                .Select(p => p.Adapt<EventParticipantModel>())
+                .ToList());
         }
 
         [HttpPost]
@@ -47,16 +50,21 @@ namespace Api.Controllers
             };
 
             var result = await _eventParticipantService.CreateParticipantAsync(createDTO);
+
             if (result is null)
             {
                 return NotFound("User or event does not exist, or participant already exists.");
             }
 
-            return CreatedAtAction(nameof(GetEventParticipantById), new { userId = result.User.Id, eventId = result.Event.Id }, result);
+            return CreatedAtAction(
+                nameof(GetEventParticipantById),
+                new { userId = result.User.Id, eventId = result.Event.Id },
+                result.Adapt<EventParticipantModel>());
         }
 
         [HttpPatch("{participantId:guid}")]
-        public async Task<IActionResult> UpdateEventParticipant([FromRoute] Guid participantId, [FromBody] EventParticipantUpdateModel data)
+        public async Task<IActionResult> UpdateEventParticipant([FromRoute] Guid participantId,
+            [FromBody] EventParticipantUpdateModel data)
         {
             var updateDTO = new EventParticipantUpdateDTO
             {
@@ -64,24 +72,16 @@ namespace Api.Controllers
             };
 
             var result = await _eventParticipantService.UpdateParticipantAsync(participantId, updateDTO);
-            if (result is null)
-            {
-                return NotFound();
-            }
 
-            return Ok(result);
+            return result is null ? NotFound() : Ok(result.Adapt<EventParticipantModel>());
         }
 
         [HttpDelete("{participantId:guid}")]
         public async Task<IActionResult> DeleteEventParticipant([FromRoute] Guid participantId)
         {
-            var success = await _eventParticipantService.DeleteParticipantAsync(participantId);
-            if (!success)
-            {
-                return NotFound();
-            }
-
-            return Ok();
+            return await _eventParticipantService.DeleteParticipantAsync(participantId)
+                ? Ok()
+                : NotFound();
         }
     }
 }
diff --git a/Api/Controllers/LocationController.cs b/Api/Controllers/LocationController.cs
index 2d77d15..735a888 100644
--- a/Api/Controllers/LocationController.cs
+++ b/Api/Controllers/LocationController.cs
@@ -1,8 +1,10 @@
+using Api.Models.Location;
 using BusinessLayer.DTOs.Location;
 using BusinessLayer.Services.LocationService;
 using BusinessLayer.Utils.Filters;
 using BusinessLayer.Utils.Ordering;
 using DAL.Models;
+using Mapster;
 using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
@@ -18,11 +20,10 @@ namespace Api.Controllers
         public async Task<ActionResult<Location>> GetLocationById([FromRoute] Guid restaurantId)
         {
             var location = await _locationService.GetLocationAsync(restaurantId);
-            if (location == null)
-            {
-                return NotFound("Location not found.");
-            }
-            return Ok(location);
+
+            return location is null
+                ? NotFound("Location not found.")
+                : Ok(location.Adapt<LocationModel>());
         }
 
         [HttpGet]
@@ -39,14 +40,17 @@ namespace Api.Controllers
                 limit,
                 offset,
                 ids);
-            return Ok(locations);
+
+            return Ok(locations
+                .Select(l => l.Adapt<LocationModel>())
+                .ToList());
         }
 
         [HttpPatch]
         [Route("{restaurantId:guid}")]
         public async Task<IActionResult> UpdateLocation(
             [FromRoute] Guid restaurantId,
-            [FromBody] LocationUpdateDto data)
+            [FromBody] LocationUpdateModel data)
         {
             if (data.Country is null && data.City is null
                 && data.Address is null && data.Zipcode is null)
@@ -73,12 +77,12 @@ namespace Api.Controllers
             {
                 return BadRequest("Zipcode cannot be set to an empty string.");
             }
-            var location = await _locationService.UpdateLocationAsync(restaurantId, data);
-            if (location == null)
-            {
-                return NotFound("Location not found.");
-            }
-            return Ok(location);
+
+            var location = await _locationService.UpdateLocationAsync(restaurantId, data.Adapt<LocationUpdateDto>());
+
+            return location is null
+                ? NotFound("Location not found.")
+                : Ok(location.Adapt<LocationModel>());
         }
     }
 }
diff --git a/Api/Controllers/RestaurantController.cs b/Api/Controllers/RestaurantController.cs
index ddf4a8b..dffbce2 100644
--- a/Api/Controllers/RestaurantController.cs
+++ b/Api/Controllers/RestaurantController.cs
@@ -4,6 +4,8 @@ using BusinessLayer.Services.RestaurantMaintainerService;
 using BusinessLayer.Utils.Filters;
 using BusinessLayer.Utils.Ordering;
 using Microsoft.AspNetCore.Mvc;
+using Api.Models.Restaurant;
+using Mapster;
 
 namespace Api.Controllers
 {
@@ -22,7 +24,7 @@ namespace Api.Controllers
         {
             var restaurant = await _restaurantService.GetRestaurantAsync(restaurantId);
             return restaurant == null
-                ? Ok(restaurant)
+                ? Ok(restaurant.Adapt<RestaurantDetailModel>())
                 : NotFound("Restaurant not found");
         }
 
@@ -40,15 +42,18 @@ namespace Api.Controllers
                 limit,
                 offset,
                 ids);
-            return Ok(restaurants);
+
+            return Ok(restaurants
+                .Select(r => r.Adapt<RestaurantModel>())
+                .ToList());
         }
 
         [HttpPost]
-        public async Task<IActionResult> CreateRestaurant([FromBody] RestaurantCreateDto data)
+        public async Task<IActionResult> CreateRestaurant([FromBody] RestaurantCreateModel data)
         {
-            var restaurant = await _restaurantService.CreateRestaurantAsync(data);
+            var restaurant = await _restaurantService.CreateRestaurantAsync(data.Adapt<RestaurantCreateDto>());
             return restaurant == null
-                ? Ok(restaurant)
+                ? Ok(restaurant.Adapt<RestaurantDetailModel>())
                 : NotFound("Maintainer not found");
         }
 
@@ -56,7 +61,7 @@ namespace Api.Controllers
         [Route("{restaurantId:guid}")]
         public async Task<IActionResult> UpdateRestaurant(
             [FromRoute] Guid restaurantId,
-            [FromBody] RestaurantUpdateDto data)
+            [FromBody] RestaurantUpdateModel data)
         {
             if (data.Name is null && data.About is null
                                   && data.Email is null && data.Web is null
@@ -73,9 +78,9 @@ namespace Api.Controllers
                 return BadRequest("Category can't be set to empty string.");
             }
 
-            var restaurant = await _restaurantService.UpdateRestaurantAsync(restaurantId, data);
+            var restaurant = await _restaurantService.UpdateRestaurantAsync(restaurantId, data.Adapt<RestaurantUpdateDto>());
             return restaurant == null
-                ? Ok(restaurant)
+                ? Ok(restaurant.Adapt<RestaurantDetailModel>())
                 : NotFound("Restaurant not found");
         }
 
diff --git a/Api/Controllers/ReviewAggregateResultController.cs b/Api/Controllers/ReviewAggregateResultController.cs
index 7edab9d..959070b 100644
--- a/Api/Controllers/ReviewAggregateResultController.cs
+++ b/Api/Controllers/ReviewAggregateResultController.cs
@@ -1,4 +1,6 @@
-using BusinessLayer.Services.ReviewAggregateService;
+using Api.Models.ReviewAggregate;
+using BusinessLayer.Services.ReviewAggregateService;
+using Mapster;
 using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
@@ -21,14 +23,15 @@ namespace Api.Controllers
             var aggregate = await _service.GetAggregateByIdAsync(restaurantId);
             return aggregate is null
                 ? NotFound("Data not found, try again later.")
-                : Ok(aggregate);
+                : Ok(aggregate.Adapt<ReviewAggregateModel>());
         }
 
         [HttpGet]
         public async Task<IActionResult> GetAggregates([FromQuery] string orderBy = "",
             [FromQuery] int limit = 0, [FromQuery] int offset = 0)
         {
-            return Ok(await _service.GetAggregatesAsync(orderBy, limit, offset, false));
+            var aggregates = await _service.GetAggregatesAsync(orderBy, limit, offset, false);
+            return Ok(aggregates.Select(a => a.Adapt<ReviewAggregateModel>()).ToList());
         }
 
         // The other operations do not make much sense here. This entity is tied to restaurant.
diff --git a/Api/Controllers/ReviewCommentController.cs b/Api/Controllers/ReviewCommentController.cs
index a2cc685..b04bba0 100644
--- a/Api/Controllers/ReviewCommentController.cs
+++ b/Api/Controllers/ReviewCommentController.cs
@@ -1,6 +1,8 @@
-using BusinessLayer.DTOs.ReviewComment;
+using Api.Models.ReviewComment;
+using BusinessLayer.DTOs.ReviewComment;
 using BusinessLayer.Services.ReviewCommentService;
 using BusinessLayer.Utils.Filters;
+using Mapster;
 using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
@@ -24,35 +26,41 @@ namespace Api.Controllers
 
             return comment is null
                 ? NotFound("Comment does not exist.")
-                : Ok(comment);
+                : Ok(comment.Adapt<ReviewCommentModel>());
         }
 
         [HttpGet]
         public async Task<IActionResult> GetReviewComments([FromQuery] ReviewCommentFilter filter,
             [FromQuery] int limit = 0, [FromQuery] int offset = 0)
         {
-            return Ok(await _service.GetCommentsAsync(filter, limit, offset));
+            var comments = await _service.GetCommentsAsync(filter, limit, offset);
+            return Ok(comments
+                .Select(c => c.Adapt<ReviewCommentModel>())
+                .ToList());
         }
 
         [HttpPost]
-        public async Task<IActionResult> CreateReviewComment([FromBody] ReviewCommentCreateDTO data)
+        public async Task<IActionResult> CreateReviewComment([FromBody] ReviewCommentCreateModel data)
         {
-            var comment = await _service.CreateCommentAsync(data);
+            var comment = await _service.CreateCommentAsync(data.Adapt<ReviewCommentCreateDTO>());
 
             return comment is null
                 ? NotFound("The review or the poster of the comment was not found.")
-                : CreatedAtAction(nameof(CreateReviewComment), comment);
+                : CreatedAtAction(
+                    nameof(CreateReviewComment),
+                    new { commentId = comment.Id },
+                    comment.Adapt<ReviewCommentModel>());
         }
 
         [HttpPatch]
         [Route("{commentId:guid}")]
-        public async Task<IActionResult> UpdateReviewComment([FromRoute] Guid commentId, [FromBody] ReviewCommentUpdateDTO data)
+        public async Task<IActionResult> UpdateReviewComment([FromRoute] Guid commentId, [FromBody] ReviewCommentUpdateModel data)
         {
-            var comment = await _service.UpdateCommentAsync(commentId, data);
+            var comment = await _service.UpdateCommentAsync(commentId, data.Adapt<ReviewCommentUpdateDTO>());
 
             return comment is null
                 ? NotFound("The comment does not exist.")
-                : Ok(comment);
+                : Ok(comment.Adapt<ReviewCommentModel>());
         }
 
         /** 
diff --git a/Api/Controllers/ReviewController.cs b/Api/Controllers/ReviewController.cs
index 6095a25..d87c747 100644
--- a/Api/Controllers/ReviewController.cs
+++ b/Api/Controllers/ReviewController.cs
@@ -3,6 +3,7 @@ using BusinessLayer.DTOs.Review;
 using BusinessLayer.Services.ReviewService;
 using BusinessLayer.Utils.Filters;
 using BusinessLayer.Utils.Ordering;
+using Mapster;
 using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
@@ -28,7 +29,7 @@ namespace Api.Controllers
                 return NotFound();
             }
 
-            return Ok(review);
+            return Ok(review.Adapt<ReviewDetailModel>());
         }
 
         [HttpGet]
@@ -36,23 +37,30 @@ namespace Api.Controllers
             [FromQuery] ReviewOrdering orderBy, [FromQuery] int limit = 0,
             [FromQuery] int offset = 0)
         {
-            return Ok(await _service.GetReviewsAsync(filter, orderBy, limit, offset));
+            var reviews = await _service.GetReviewsAsync(filter, orderBy, limit, offset);
+
+            return Ok(reviews
+                .Select(r => r.Adapt<ReviewModel>())
+                .ToList());
         }
 
         [HttpPost]
-        public async Task<IActionResult> CreateReview([FromBody] ReviewCreateDTO data)
+        public async Task<IActionResult> CreateReview([FromBody] ReviewCreateModel data)
         {
-            var review = await _service.CreateReviewAsync(data);
+            var review = await _service.CreateReviewAsync(data.Adapt<ReviewCreateDTO>());
 
             return review is null
                 ? NotFound("User or Restaurant does not exist.")
-                : CreatedAtAction(nameof(CreateReview), review);
+                : CreatedAtAction(
+                    nameof(CreateReview),
+                    new { reviewId = review.Id },
+                    review.Adapt<ReviewDetailModel>());
         }
 
         [HttpPatch]
         [Route("{reviewId:guid}")]
         public async Task<IActionResult> UpdateReview([FromRoute] Guid reviewId,
-            [FromBody] ReviewUpdateDTO data)
+            [FromBody] ReviewUpdateModel data)
         {
             if (UpdateEmpty(data))
             {
@@ -64,11 +72,11 @@ namespace Api.Controllers
                 return BadRequest("Review content cannot be empty.");
             }
 
-            var review = await _service.UpdateReviewAsync(reviewId, data);
+            var review = await _service.UpdateReviewAsync(reviewId, data.Adapt<ReviewUpdateDTO>());
 
             return review is null
                 ? NotFound("Review does not exist.")
-                : Ok(review);
+                : Ok(review.Adapt<ReviewDetailModel>());
         }
 
         [HttpDelete]
@@ -82,7 +90,7 @@ namespace Api.Controllers
                 : NotFound("Review does not exist.");
         }
 
-        private static bool UpdateEmpty(ReviewUpdateDTO data)
+        private static bool UpdateEmpty(ReviewUpdateModel data)
         {
             return data.Content is null && data.FoodRating is null
                 && data.ServiceRating is null && data.EnvironmentRating is null
diff --git a/Api/Controllers/UserController.cs b/Api/Controllers/UserController.cs
index f1bca6a..fd386ac 100644
--- a/Api/Controllers/UserController.cs
+++ b/Api/Controllers/UserController.cs
@@ -1,7 +1,9 @@
-using BusinessLayer.DTOs.User;
+using Api.Models.User;
+using BusinessLayer.DTOs.User;
 using BusinessLayer.Services.UserService;
 using BusinessLayer.Utils.Filters;
 using BusinessLayer.Utils.Ordering;
+using Mapster;
 using Microsoft.AspNetCore.Mvc;
 
 namespace Api.Controllers
@@ -17,11 +19,10 @@ namespace Api.Controllers
         public async Task<IActionResult> GetUserById([FromRoute] Guid userId)
         {
             var user = await _userService.GetUserAsync(userId);
-            if (user == null)
-            {
-                return NotFound("User not found.");
-            }
-            return Ok(user);
+
+            return user is null
+                ? NotFound("User not found.")
+                : Ok(user.Adapt<UserDetailModel>());
         }
 
         [HttpGet]
@@ -38,21 +39,28 @@ namespace Api.Controllers
                 limit,
                 offset,
                 ids);
-            return Ok(users);
+
+            return Ok(users
+                .Select(u => u.Adapt<UserModel>())
+                .ToList());
         }
 
         [HttpPost]
-        public async Task<IActionResult> CreateUser([FromBody] UserCreateDto data)
+        public async Task<IActionResult> CreateUser([FromBody] UserCreateModel data)
         {
-            var user = await _userService.CreateUserAsync(data);
-            return CreatedAtAction(nameof(CreateUser), user);
+            var user = await _userService.CreateUserAsync(data.Adapt<UserCreateDto>());
+
+            return CreatedAtAction(
+                nameof(CreateUser),
+                new { userId = user.Id },
+                user.Adapt<UserDetailModel>());
         }
 
         [HttpPatch]
         [Route("{userId:guid}")]
         public async Task<IActionResult> UpdateUser(
             [FromRoute] Guid userId,
-            [FromBody] UserUpdateDto data)
+            [FromBody] UserUpdateModel data)
         {
             if (data.Name is null && data.Email is null)
             {
@@ -69,23 +77,20 @@ namespace Api.Controllers
                 return BadRequest("Email can't be set to empty string.");
             }
 
-            var user = await _userService.UpdateUserAsync(userId, data);
-            if (user == null)
-            {
-                return NotFound("User not found.");
-            }
-            return Ok(user);
+            var user = await _userService.UpdateUserAsync(userId, data.Adapt<UserUpdateDto>());
+
+            return user is null
+                ? NotFound("User not found.")
+                : Ok(user.Adapt<UserDetailModel>());
         }
 
         [HttpDelete]
         [Route("{userId:guid}")]
         public async Task<IActionResult> DeleteUser([FromRoute] Guid userId)
         {
-            if (!await _userService.DeleteUserAsync(userId))
-            {
-                return NotFound("User not found.");
-            }
-            return Ok();
+            return !await _userService.DeleteUserAsync(userId)
+                ? NotFound("User not found.")
+                : Ok();
         }
     }
 }
diff --git a/Api/Models/Converter.cs b/Api/Models/Converter.cs
deleted file mode 100644
index 6c872f1..0000000
--- a/Api/Models/Converter.cs
+++ /dev/null
@@ -1,205 +0,0 @@
-using Api.Models.Event;
-using Api.Models.EventComment;
-using Api.Models.EventParticipant;
-using Api.Models.Location;
-using Api.Models.Review;
-using Api.Models.ReviewAggregate;
-using Api.Models.ReviewComment;
-using Api.Models.Restaurant;
-using Api.Models.User;
-using System.Linq.Expressions;
-using BusinessLayer.Utils.Filters;
-
-namespace Api.Models
-{
-    public static class Converter
-    {
-        public static UserModel ToUserModel(DAL.Models.User user)
-        {
-            return new UserModel
-            {
-                Id = user.Id,
-                Name = user.Name,
-                Email = user.Email,
-                CreatedAt = user.CreatedAt.ToLocalTime(),
-                UpdatedAt = user.UpdatedAt.ToLocalTime(),
-                DeletedAt = user.DeletedAt?.ToLocalTime(),
-            };
-        }
-
-        public static UserDetailModel ToUserDetailModel(DAL.Models.User user)
-        {
-            return new UserDetailModel
-            {
-                Id = user.Id,
-                Name = user.Name,
-                Email = user.Email,
-                CreatedAt = user.CreatedAt.ToLocalTime(),
-                UpdatedAt = user.UpdatedAt.ToLocalTime(),
-                DeletedAt = user.DeletedAt?.ToLocalTime(),
-                MaintainedRestaurants = user.MaintainedRestaurants
-                                            .Where(r => r.DeletedAt is null)
-                                            .Select(ToRestaurantModel).ToList()
-            };
-        }
-
-        public static ReviewModel ToReviewModel(DAL.Models.Review review)
-        {
-            return new ReviewModel
-            {
-                Id = review.Id,
-                Poster = ToUserModel(review.Poster!),
-                RestaurantId = review.RestaurantId,
-                Content = review.Content,
-                FoodRating = review.FoodRating,
-                ServiceRating = review.ServiceRating,
-                EnvironmentRating = review.EnvironmentRating,
-                ServesFreeWater = review.ServesFreeWater,
-                TimeSpent = review.TimeSpent,
-                LeftTip = review.LeftTip,
-                CreatedAt = review.CreatedAt.ToLocalTime(),
-                UpdatedAt = review.UpdatedAt.ToLocalTime(),
-                DeletedAt = review.DeletedAt?.ToLocalTime(),
-            };
-        }
-
-        public static ReviewCommentModel ToReviewCommentModel(DAL.Models.ReviewComment comment)
-        {
-            return new ReviewCommentModel
-            {
-                Id = comment.Id,
-                Poster = ToUserModel(comment.Poster!),
-                ReviewId = comment.ReviewId,
-                ParentCommentId = comment.ParentCommentId,
-                Content = comment.Content,
-                CreatedAt = comment.CreatedAt.ToLocalTime(),
-                UpdatedAt = comment.UpdatedAt.ToLocalTime(),
-                DeletedAt = comment.DeletedAt?.ToLocalTime(),
-            };
-        }
-
-        public static ReviewAggregateModel ToReviewAggregateModel(DAL.Models.ReviewAggregateResult aggregate)
-        {
-            return new ReviewAggregateModel
-            {
-                RestaurantId = aggregate.RestaurantId,
-                FoodRating = aggregate.FoodRating,
-                EnvironmentRating = aggregate.EnvironmentRating,
-                ServiceRating = aggregate.ServiceRating,
-            };
-        }
-
-        public static Expression<Func<DAL.Models.User, bool>> ToUserFilterFunc(UserFilter filter)
-        {
-            return u => (filter.NameLike == null || u.Name.Contains(filter.NameLike))
-                      && (filter.EmailLike == null || u.Email.Contains(filter.EmailLike))
-                      && u.DeletedAt == null;
-        }
-
-        public static EventModel ToEventModel(DAL.Models.Event eventEntity)
-        {
-            return new EventModel
-            {
-                Id = eventEntity.Id,
-                Title = eventEntity.Title,
-                RestaurantId = eventEntity.RestaurantId,
-                Date = eventEntity.Date.ToLocalTime(),
-                Content = eventEntity.Content,
-                CreatedAt = eventEntity.CreatedAt.ToLocalTime(),
-                UpdatedAt = eventEntity.UpdatedAt.ToLocalTime(),
-                DeletedAt = eventEntity.DeletedAt?.ToLocalTime(),
-            };
-        }
-
-        public static EventCommentModel ToEventCommentModel(DAL.Models.EventComment comment)
-        {
-            return new EventCommentModel
-            {
-                Id = comment.Id,
-                PosterId = comment.PosterId,
-                Poster = comment.Poster!.Name,
-                EventId = comment.EventId,
-                ParentCommentId = comment.ParentCommentId,
-                Content = comment.Content,
-                CreatedAt = comment.CreatedAt.ToLocalTime(),
-                UpdatedAt = comment.UpdatedAt.ToLocalTime(),
-                DeletedAt = comment.DeletedAt?.ToLocalTime(),
-            };
-        }
-
-        public static EventParticipantModel ToEventParticipantModel(DAL.Models.EventParticipant participant)
-        {
-            return new EventParticipantModel
-            {
-                User = ToUserModel(participant.User!),
-                Event = ToEventModel(participant.Event!),
-                Attendance = participant.Attendance,
-                CreatedAt = participant.CreatedAt.ToLocalTime(),
-                UpdatedAt = participant.UpdatedAt.ToLocalTime(),
-                DeletedAt = participant.DeletedAt?.ToLocalTime(),
-            };
-        }
-
-        public static RestaurantModel ToRestaurantModel(DAL.Models.Restaurant restaurant)
-        {
-            return new RestaurantModel
-            {
-                Id = restaurant.Id,
-                Name = restaurant.Name,
-                About = restaurant.About,
-                Phone = restaurant.Phone,
-                Email = restaurant.Email,
-                Web = restaurant.Web,
-                Category = restaurant.Category,
-                ReviewAggregate = (restaurant.ReviewAggregate is null)
-                                   ? null
-                                   : ToReviewAggregateModel(restaurant.ReviewAggregate),
-                CreatedAt = restaurant.CreatedAt.ToLocalTime(),
-                UpdatedAt = restaurant.UpdatedAt.ToLocalTime(),
-                DeletedAt = restaurant.DeletedAt?.ToLocalTime(),
-            };
-        }
-
-        public static RestaurantDetailModel ToRestaurantDetailModel(DAL.Models.Restaurant restaurant)
-        {
-            return new RestaurantDetailModel
-            {
-                Id = restaurant.Id,
-                Name = restaurant.Name,
-                About = restaurant.About,
-                Phone = restaurant.Phone,
-                Email = restaurant.Email,
-                Web = restaurant.Web,
-                Category = restaurant.Category,
-                Location = ToLocationModel(restaurant.Location!),
-                ReviewAggregate = (restaurant.ReviewAggregate is null)
-                                    ? null
-                                    : ToReviewAggregateModel(restaurant.ReviewAggregate),
-                Maintainers = restaurant.RestaurantMaintainers
-                                .Where(u => u.DeletedAt is null)
-                                .Select(ToUserModel).ToList(),
-                Events = restaurant.Events
-                                .Where(e => e.DeletedAt is null)
-                                .Select(ToEventModel).ToList(),
-                CreatedAt = restaurant.CreatedAt.ToLocalTime(),
-                UpdatedAt = restaurant.UpdatedAt.ToLocalTime(),
-                DeletedAt = restaurant.DeletedAt?.ToLocalTime()
-            };
-        }
-
-        public static LocationModel ToLocationModel(DAL.Models.Location location)
-        {
-            return new LocationModel
-            {
-                RestaurantId = location.RestaurantId,
-                Country = location.Country,
-                City = location.City,
-                Address = location.Address,
-                ZipCode = location.Zipcode,
-                CreatedAt = location.CreatedAt,
-                UpdatedAt = location.UpdatedAt,
-                DeletedAt = location.DeletedAt
-            };
-        }
-    }
-}
diff --git a/Api/Models/Event/EventInfoModel.cs b/Api/Models/Event/EventInfoModel.cs
new file mode 100644
index 0000000..83fa124
--- /dev/null
+++ b/Api/Models/Event/EventInfoModel.cs
@@ -0,0 +1,11 @@
+using Api.Models.Restaurant;
+
+namespace Api.Models.Event
+{
+    public class EventInfoModel
+    {
+        public required string Title { get; set; }
+        public DateTime Date { get; set; }
+        public required RestaurantModel Restaurant { get; set; }
+    }
+}
diff --git a/Api/Models/EventComment/EventCommentModel.cs b/Api/Models/EventComment/EventCommentModel.cs
index 32d90f7..5ad3971 100644
--- a/Api/Models/EventComment/EventCommentModel.cs
+++ b/Api/Models/EventComment/EventCommentModel.cs
@@ -1,13 +1,17 @@
-namespace Api.Models.EventComment
+using Api.Models.Event;
+using Api.Models.User;
+
+namespace Api.Models.EventComment
 {
     public class EventCommentModel
     {
         public Guid Id { get; set; }
-        public Guid PosterId { get; set; }
-        public required string Poster { get; set; }
+        public UserModel? Poster { get; set; }
         public Guid EventId { get; set; }
-        public required string Content { get; set; }
+        public EventModel? Event { get; set; }
         public Guid? ParentCommentId { get; set; }
+        public List<EventCommentModel> ChildComments { get; set; } = new List<EventCommentModel>();
+        public required string Content { get; set; }
         public DateTime CreatedAt { get; set; }
         public DateTime UpdatedAt { get; set; }
         public DateTime? DeletedAt { get; set; }
diff --git a/Api/Models/Restaurant/RestaurantDetailModel.cs b/Api/Models/Restaurant/RestaurantDetailModel.cs
index 5937294..c8d1b48 100644
--- a/Api/Models/Restaurant/RestaurantDetailModel.cs
+++ b/Api/Models/Restaurant/RestaurantDetailModel.cs
@@ -16,8 +16,7 @@ namespace Api.Models.Restaurant
         public required string Category { get; set; }
         public required LocationModel Location { get; set; }
         public ReviewAggregateModel? ReviewAggregate { get; set; }
-        public required List<UserModel> Maintainers { get; set; }
-        public required List<EventModel> Events { get; set; }
+        public required List<UserModel> RestaurantMaintainers { get; set; }
         public DateTime CreatedAt { get; set; }
         public DateTime UpdatedAt { get; set; }
         public DateTime? DeletedAt { get; set; }
diff --git a/Api/Models/Restaurant/RestaurantModel.cs b/Api/Models/Restaurant/RestaurantModel.cs
index f03671f..9a3647b 100644
--- a/Api/Models/Restaurant/RestaurantModel.cs
+++ b/Api/Models/Restaurant/RestaurantModel.cs
@@ -1,3 +1,4 @@
+using Api.Models.Location;
 using Api.Models.Review;
 using Api.Models.ReviewAggregate;
 using Api.Models.User;
@@ -8,11 +9,8 @@ public class RestaurantModel
 {
     public Guid Id { get; set; }
     public required string Name { get; set; }
-    public string? About { get; set; }
-    public string? Phone { get; set; }
-    public string? Email { get; set; }
-    public string? Web { get; set; }
     public string? Category { get; set; }
+    public required LocationModel Location { get; set; }
     public ReviewAggregateModel? ReviewAggregate { get; set; }
     public DateTime CreatedAt { get; set; }
     public DateTime UpdatedAt { get; set; }
diff --git a/Api/Models/Review/ReviewDetailModel.cs b/Api/Models/Review/ReviewDetailModel.cs
new file mode 100644
index 0000000..68c5d60
--- /dev/null
+++ b/Api/Models/Review/ReviewDetailModel.cs
@@ -0,0 +1,22 @@
+using Api.Models.Restaurant;
+using Api.Models.User;
+
+namespace Api.Models.Review
+{
+    public class ReviewDetailModel
+    {
+        public Guid Id { get; set; }
+        public UserModel? Poster { get; set; }
+        public RestaurantModel? Restaurant { get; set; }
+        public required string Content { get; set; }
+        public uint FoodRating { get; set; }
+        public uint ServiceRating { get; set; }
+        public uint EnvironmentRating { get; set; }
+        public bool? ServesFreeWater { get; set; }
+        public float? TimeSpent { get; set; }
+        public bool? LeftTip { get; set; }
+        public DateTime CreatedAt { get; set; }
+        public DateTime UpdatedAt { get; set; }
+        public DateTime? DeletedAt { get; set; }
+    }
+}
diff --git a/Api/Models/Review/ReviewModel.cs b/Api/Models/Review/ReviewModel.cs
index 6b8c6af..4ab001f 100644
--- a/Api/Models/Review/ReviewModel.cs
+++ b/Api/Models/Review/ReviewModel.cs
@@ -1,4 +1,5 @@
 using Api.Models.User;
+using BusinessLayer.DTOs.User;
 
 namespace Api.Models.Review
 {
@@ -6,14 +7,9 @@ namespace Api.Models.Review
     {
         public Guid Id { get; set; }
         public UserModel? Poster { get; set; }
-        public Guid RestaurantId { get; set; }
-        public required string Content { get; set; }
         public uint FoodRating { get; set; }
         public uint ServiceRating { get; set; }
         public uint EnvironmentRating { get; set; }
-        public bool? ServesFreeWater { get; set; }
-        public float? TimeSpent { get; set; }
-        public bool? LeftTip { get; set; }
         public DateTime CreatedAt { get; set; }
         public DateTime UpdatedAt { get; set; }
         public DateTime? DeletedAt { get; set; }
diff --git a/Api/Models/User/UserModel.cs b/Api/Models/User/UserModel.cs
index 593f8a5..6fade8b 100644
--- a/Api/Models/User/UserModel.cs
+++ b/Api/Models/User/UserModel.cs
@@ -4,7 +4,6 @@
     {
         public Guid Id { get; set; }
         public required string Name { get; set; }
-        public required string Email { get; set; }
         public DateTime CreatedAt { get; set; }
         public DateTime UpdatedAt { get; set; }
         public DateTime? DeletedAt { get; set; }
-- 
GitLab


From 587bd7a75b24324c3a30a7b42d95447c0c2af94a Mon Sep 17 00:00:00 2001
From: Matej Vavrek <matvav13@gmail.com>
Date: Wed, 13 Nov 2024 00:29:06 +0100
Subject: [PATCH 4/5] Dotnet format

---
 DAL/Constants/Limits.cs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/DAL/Constants/Limits.cs b/DAL/Constants/Limits.cs
index 627a783..32fa5a7 100644
--- a/DAL/Constants/Limits.cs
+++ b/DAL/Constants/Limits.cs
@@ -8,6 +8,6 @@
         public const int ZipcodeLength = 5;
         public const int ShortTextLength = 255;
         public const int MediumTextLength = 1800;
-        public const int LongTextLength = 3600; 
+        public const int LongTextLength = 3600;
     }
 }
-- 
GitLab


From e1dd49c869b45eb2d698111644f1895fae6a97f0 Mon Sep 17 00:00:00 2001
From: Matej Vavrek <matvav13@gmail.com>
Date: Wed, 13 Nov 2024 22:18:09 +0100
Subject: [PATCH 5/5] Fixed error in UserController

---
 Api/Controllers/UserController.cs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Api/Controllers/UserController.cs b/Api/Controllers/UserController.cs
index fd386ac..2a96bc4 100644
--- a/Api/Controllers/UserController.cs
+++ b/Api/Controllers/UserController.cs
@@ -50,7 +50,9 @@ namespace Api.Controllers
         {
             var user = await _userService.CreateUserAsync(data.Adapt<UserCreateDto>());
 
-            return CreatedAtAction(
+            return user is null ?
+                BadRequest()
+                : CreatedAtAction(
                 nameof(CreateUser),
                 new { userId = user.Id },
                 user.Adapt<UserDetailModel>());
-- 
GitLab