diff --git a/Api/Api.csproj b/Api/Api.csproj index ecba0e43ded49362cb1764758c21195d081d6843..cafa422ed7cca1ff4a6cc87411a46f0090d0e765 100644 --- a/Api/Api.csproj +++ b/Api/Api.csproj @@ -4,11 +4,11 @@ <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> <ItemGroup> - <PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="8.0.10" /> - <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10"> + <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> diff --git a/Api/Controllers/EventCommentController.cs b/Api/Controllers/EventCommentController.cs index ded9bf7d55f0435b7bf16ca2c708855777e1f89e..0ba337a349b77e544d63e5def5d90a37806adbfb 100644 --- a/Api/Controllers/EventCommentController.cs +++ b/Api/Controllers/EventCommentController.cs @@ -56,11 +56,6 @@ namespace Api.Controllers [HttpPost] public async Task<IActionResult> CreateEventComment([FromBody] EventCommentCreateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var poster = await _context.Users.FindAsync(data.PosterId); if (poster is null || poster.DeletedAt is not null) { diff --git a/Api/Controllers/EventController.cs b/Api/Controllers/EventController.cs index abe0435144395fdf6785f6c335906369ccdaf56c..7e88a90f03f3b394917bf6db1f09476d4605444c 100644 --- a/Api/Controllers/EventController.cs +++ b/Api/Controllers/EventController.cs @@ -24,11 +24,11 @@ namespace Api.Controllers { var eventEntity = await _context.Events .Include(e => e.Restaurant) - .SingleOrDefaultAsync(e => e.Id == eventId); + .SingleOrDefaultAsync(e => e.Id == eventId + && e.DeletedAt == null + && e.Restaurant!.DeletedAt == null); - if (eventEntity is null - || eventEntity.DeletedAt is not null - || eventEntity.Restaurant.DeletedAt is not null) + if (eventEntity is null) { return NotFound(); } @@ -57,11 +57,6 @@ namespace Api.Controllers [HttpPost] public async Task<IActionResult> CreateEvent([FromBody] EventCreateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var user = await _context.Users.FindAsync(data.CreatorId); if (user == null) @@ -107,11 +102,6 @@ namespace Api.Controllers [Route("{eventId:guid}")] public async Task<IActionResult> UpdateEvent([FromRoute] Guid eventId, [FromBody] EventUpdateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var eventEntity = await _context.Events.FindAsync(eventId); if (eventEntity is null || eventEntity.DeletedAt is not null) diff --git a/Api/Controllers/EventParticipantController.cs b/Api/Controllers/EventParticipantController.cs index ad4ad437f43b93baa18515e3d6ba5a03023cad47..29364ad0177aef6401240701acf0fc113457bb9e 100644 --- a/Api/Controllers/EventParticipantController.cs +++ b/Api/Controllers/EventParticipantController.cs @@ -46,7 +46,7 @@ namespace Api.Controllers .Include(p => p.User) .Include(p => p.Event) .Where(filterFunc) - .OrderBy(p => p.User.Name) + .OrderBy(p => p.User!.Name) .Skip(offset); var participants = limit > 0 @@ -59,11 +59,6 @@ namespace Api.Controllers [HttpPost] public async Task<IActionResult> CreateEventParticipant([FromBody] EventParticipantCreateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var user = await _context.Users.FindAsync(data.UserId); if (user is null) { @@ -119,11 +114,6 @@ namespace Api.Controllers [Route("{participantId:guid}")] public async Task<IActionResult> UpdateEventParticipant([FromRoute] Guid participantId, [FromBody] EventParticipantUpdateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var participant = await _context.EventParticipants.FindAsync(participantId); if (participant is null) diff --git a/Api/Controllers/LocationController.cs b/Api/Controllers/LocationController.cs index ed28ef8e8fd924475a0a0e2c41ae199b7ff3c484..82b9cbadb12c228359a8f7c48f1fa393becbb2f6 100644 --- a/Api/Controllers/LocationController.cs +++ b/Api/Controllers/LocationController.cs @@ -19,7 +19,7 @@ namespace Api.Controllers } [HttpGet] - [Route("locationId:guid")] + [Route("{restaurantId:guid}")] public async Task<ActionResult<Location>> GetLocationById([FromRoute] Guid restaurantId) { var locationEntity = await _context.Locations.FindAsync(restaurantId); @@ -61,11 +61,6 @@ namespace Api.Controllers public async Task<IActionResult> UpdateLocation([FromRoute] Guid restaurantId, [FromBody] LocationUpdateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - if (data.Country is null && data.City is null && data.Address is null && data.Zipcode is null) { diff --git a/Api/Controllers/RestaurantController.cs b/Api/Controllers/RestaurantController.cs index 9ddaf713eeef254a15b94935685397605b39aba9..f6352f55351231be086106babf171aadc1dedd8f 100644 --- a/Api/Controllers/RestaurantController.cs +++ b/Api/Controllers/RestaurantController.cs @@ -63,11 +63,6 @@ namespace Api.Controllers [HttpPost] public async Task<IActionResult> CreateRestaurant([FromBody] RestaurantCreateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var maintainer = await _context.Users.FindAsync(data.MaintainerId); if (maintainer is null || maintainer.DeletedAt is not null) @@ -86,7 +81,7 @@ namespace Api.Controllers Web = data.Web, Phone = data.Phone, Category = data.Category, - RestaurantMaintainers = new List<User>() { maintainer }, + RestaurantMaintainers = [maintainer], Location = new Location { RestaurantId = restaurantId, @@ -108,11 +103,6 @@ namespace Api.Controllers [Route("{restaurantId:guid}")] public async Task<IActionResult> UpdateRestaurant([FromRoute] Guid restaurantId, [FromBody] RestaurantUpdateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - if (data.Name is null && data.About is null && data.Email is null && data.Web is null && data.Phone is null && data.Category is null) diff --git a/Api/Controllers/ReviewAggregateController.cs b/Api/Controllers/ReviewAggregateController.cs index a454891f8dd5dccdf44712e05afc98c7190adb36..a801930bfc2d108aceca9f253665c6ea6947099c 100644 --- a/Api/Controllers/ReviewAggregateController.cs +++ b/Api/Controllers/ReviewAggregateController.cs @@ -22,7 +22,7 @@ namespace Api.Controllers public async Task<IActionResult> GetAggregateForRestaurant([FromRoute] Guid restaurantId) { var aggregate = await _context.ReviewAggregate.FindAsync(restaurantId); - if (aggregate is null || aggregate.Restaurant.DeletedAt is not null) + if (aggregate is null || aggregate.Restaurant!.DeletedAt is not null) { return NotFound(); } @@ -57,7 +57,7 @@ namespace Api.Controllers : await baseAggregatesQuery.Skip(offset).ToListAsync(); return Ok(aggregates - .Where(r => r.Restaurant.DeletedAt is null) + .Where(r => r.Restaurant!.DeletedAt is null) .Select(Converter.ToReviewAggregateModel) .ToList()); } diff --git a/Api/Controllers/ReviewCommentController.cs b/Api/Controllers/ReviewCommentController.cs index 647d8d62cffd4b5bcce0e6acbf11137eeef9fa90..1a3e9bced3356457a668332f9219bf57bafe3f9b 100644 --- a/Api/Controllers/ReviewCommentController.cs +++ b/Api/Controllers/ReviewCommentController.cs @@ -24,16 +24,16 @@ namespace Api.Controllers { var comment = await _context.ReviewComments .Include(r => r.Poster) - .FirstOrDefaultAsync(r => r.Id == commentId); + .FirstOrDefaultAsync(r => r.Id == commentId + && r.DeletedAt == null + && r.Poster!.DeletedAt == null); - if (comment is null - || comment.DeletedAt is not null - || comment.Poster.DeletedAt is not null) + if (comment is null) { return NotFound(); } - if (comment.ParentCommentId is not null && comment.ParentComment.DeletedAt is not null) + if (comment.ParentCommentId is not null && comment.ParentComment!.DeletedAt is not null) { return NotFound(); } @@ -62,11 +62,6 @@ namespace Api.Controllers [HttpPost] public async Task<IActionResult> CreateReviewComment([FromBody] ReviewCommentCreateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var poster = await _context.Users.FindAsync(data.PosterId); if (poster is null || poster.DeletedAt is not null) @@ -112,11 +107,6 @@ namespace Api.Controllers [Route("{commentId:guid}")] public async Task<IActionResult> UpdateReviewComment([FromRoute] Guid commentId, [FromBody] ReviewCommentUpdateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var comment = await _context.ReviewComments.FindAsync(commentId); if (comment is null || comment.DeletedAt is not null) diff --git a/Api/Controllers/ReviewController.cs b/Api/Controllers/ReviewController.cs index a078f2f8d0a5b5237b1aecea3a550176e8ff41aa..928f8ec3d6c2bc855b765473cea7ec6ca38f06fa 100644 --- a/Api/Controllers/ReviewController.cs +++ b/Api/Controllers/ReviewController.cs @@ -27,7 +27,7 @@ namespace Api.Controllers .SingleOrDefaultAsync(r => r.Id == reviewId); if (review is null || review.DeletedAt is not null - || review.Poster.DeletedAt is not null) + || review.Poster!.DeletedAt is not null) { return NotFound(); } @@ -72,11 +72,6 @@ namespace Api.Controllers [HttpPost] public async Task<IActionResult> CreateReview([FromBody] ReviewCreateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var user = await _context.Users.FindAsync(data.PosterId); if (user is null || user.DeletedAt is not null) @@ -118,11 +113,6 @@ namespace Api.Controllers public async Task<IActionResult> UpdateReview([FromRoute] Guid reviewId, [FromBody] ReviewUpdateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - if (UpdateEmpty(data)) { return BadRequest("No data sent."); diff --git a/Api/Controllers/UserController.cs b/Api/Controllers/UserController.cs index 29023ba06fa251ffafa272c56b0ca4c0214f713e..c3b1330ab6aa1a3957b18f85a02a5ab29b8dd0eb 100644 --- a/Api/Controllers/UserController.cs +++ b/Api/Controllers/UserController.cs @@ -67,11 +67,6 @@ namespace Api.Controllers [HttpPost] public async Task<IActionResult> CreateUser([FromBody] UserCreateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - var user = new User { Id = Guid.NewGuid(), @@ -88,10 +83,6 @@ namespace Api.Controllers [Route("{userId:guid}")] public async Task<IActionResult> UpdateUser([FromRoute] Guid userId, [FromBody] UserUpdateModel data) { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } if (data.Name is null && data.Email is null) { return BadRequest("No data was provided."); diff --git a/Api/Models/Converter.cs b/Api/Models/Converter.cs index 7a8d20008e2195d696604af67ba1da5c1a977b0a..122058ae6f692ace62f4e604f29c84905094d891 100644 --- a/Api/Models/Converter.cs +++ b/Api/Models/Converter.cs @@ -47,7 +47,7 @@ namespace Api.Models return new ReviewModel { Id = review.Id, - Poster = ToUserModel(review.Poster), + Poster = ToUserModel(review.Poster!), RestaurantId = review.RestaurantId, Content = review.Content, FoodRating = review.FoodRating, @@ -67,7 +67,7 @@ namespace Api.Models return new ReviewCommentModel { Id = comment.Id, - Poster = ToUserModel(comment.Poster), + Poster = ToUserModel(comment.Poster!), ReviewId = comment.ReviewId, ParentCommentId = comment.ParentCommentId, Content = comment.Content, @@ -94,7 +94,7 @@ namespace Api.Models && (filter.ReviewId == null || c.ReviewId == filter.ReviewId) && (filter.ParentCommentId == null || c.ParentCommentId == filter.ParentCommentId) && c.DeletedAt == null && (c.ParentComment == null || c.ParentComment.DeletedAt == null) - && c.Poster.DeletedAt == null; + && (c.Poster == null || c.Poster!.DeletedAt == null); } public static Expression<Func<DAL.Models.User, bool>> ToUserFilterFunc(UserFilter filter) @@ -114,7 +114,7 @@ namespace Api.Models && (filter.EnvLessEqual == null || r.EnvironmentRating <= filter.EnvLessEqual) && (filter.ServiceGreaterEqual == null || r.ServiceRating >= filter.ServiceGreaterEqual) && (filter.ServiceLessEqual == null || r.ServiceRating <= filter.ServiceLessEqual) - && r.DeletedAt == null && r.Poster.DeletedAt == null; + && r.DeletedAt == null && ( r.Poster != null || r.Poster!.DeletedAt == null ); } // EVENT @@ -138,7 +138,7 @@ namespace Api.Models return e => (filter.RestaurantId == null || e.RestaurantId == filter.RestaurantId) && (filter.DateFrom == null || e.Date >= filter.DateFrom) && (filter.DateTo == null || e.Date <= filter.DateTo) - && e.DeletedAt == null && e.Restaurant.DeletedAt == null; + && e.DeletedAt == null && (e.Restaurant == null || e.Restaurant.DeletedAt == null); } // EVENT COMMENT @@ -148,7 +148,7 @@ namespace Api.Models { Id = comment.Id, PosterId = comment.PosterId, - Poster = comment.Poster.Name, + Poster = comment.Poster!.Name, EventId = comment.EventId, ParentCommentId = comment.ParentCommentId, Content = comment.Content, @@ -175,8 +175,8 @@ namespace Api.Models { return new EventParticipantModel { - User = ToUserModel(participant.User), - Event = ToEventModel(participant.Event), + User = ToUserModel(participant.User!), + Event = ToEventModel(participant.Event!), Attendance = participant.Attendance, CreatedAt = participant.CreatedAt.ToLocalTime(), UpdatedAt = participant.UpdatedAt.ToLocalTime(), @@ -189,8 +189,8 @@ namespace Api.Models return p => (filter.UserId == null || p.UserId == filter.UserId) && (filter.EventId == null || p.EventId == filter.EventId) && p.DeletedAt == null - && p.User.DeletedAt == null - && p.Event.DeletedAt == null; + && (p.User == null || p.User.DeletedAt == null) + && (p.Event == null || p.Event.DeletedAt == null); } public static RestaurantModel ToRestaurantModel(DAL.Models.Restaurant restaurant) @@ -224,7 +224,7 @@ namespace Api.Models Email = restaurant.Email, Web = restaurant.Web, Category = restaurant.Category, - Location = ToLocationModel(restaurant.Location), + Location = ToLocationModel(restaurant.Location!), ReviewAggregate = (restaurant.ReviewAggregate is null) ? null : ToReviewAggregateModel(restaurant.ReviewAggregate), diff --git a/Api/Models/Event/EventCreateModel.cs b/Api/Models/Event/EventCreateModel.cs index cdba73eb8c2bc9eadd7a864bc6c58de13709fda2..87317e1587a129aaa1a834624ff772abd82242cb 100644 --- a/Api/Models/Event/EventCreateModel.cs +++ b/Api/Models/Event/EventCreateModel.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.Event { @@ -8,8 +9,8 @@ namespace Api.Models.Event public Guid CreatorId { get; set; } [Required] - [MaxLength(100)] - public string Title { get; set; } + [MaxLength(Limits.TitleLength)] + public required string Title { get; set; } [Required] public Guid RestaurantId { get; set; } @@ -18,7 +19,7 @@ namespace Api.Models.Event public DateTime Date { get; set; } [Required] - [MaxLength(3600)] - public string Content { get; set; } + [MaxLength(Limits.LongTextLength)] + public required string Content { get; set; } } } diff --git a/Api/Models/Event/EventModel.cs b/Api/Models/Event/EventModel.cs index 4053d7e546b20bb44156a9f68b03db54297be723..b9333c6f9f2f9c9247b5ed41b5fcbefa22f9f7c4 100644 --- a/Api/Models/Event/EventModel.cs +++ b/Api/Models/Event/EventModel.cs @@ -1,15 +1,12 @@ -using Api.Models.EventComment; -using Api.Models.EventParticipant; - -namespace Api.Models.Event +namespace Api.Models.Event { public class EventModel { public Guid Id { get; set; } - public string Title { get; set; } + public required string Title { get; set; } public Guid RestaurantId { get; set; } public DateTime Date { get; set; } - public string Content { get; set; } + 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/Event/EventUpdateModel.cs b/Api/Models/Event/EventUpdateModel.cs index 5cda26575be2ec9bc3b0b9f8d3b97371861a5e50..c5dc2a07daf6e759a890ed9de3f19d64b95dfd7b 100644 --- a/Api/Models/Event/EventUpdateModel.cs +++ b/Api/Models/Event/EventUpdateModel.cs @@ -1,13 +1,14 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.Event { public class EventUpdateModel { - public string Title { get; set; } + public required string Title { get; set; } - [MaxLength(3200)] - public string Content { get; set; } + [MaxLength(Limits.LongTextLength)] + public required string Content { get; set; } public DateTime? Date { get; set; } } diff --git a/Api/Models/EventComment/EventCommentCreateModel.cs b/Api/Models/EventComment/EventCommentCreateModel.cs index 5893d32858483e1c87ea8da02815779f23941c4f..f1e5eb1f98a835683a54b4a3aeb1ed0c864037d4 100644 --- a/Api/Models/EventComment/EventCommentCreateModel.cs +++ b/Api/Models/EventComment/EventCommentCreateModel.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.EventComment { @@ -11,8 +12,8 @@ namespace Api.Models.EventComment public Guid EventId { get; set; } [Required] - [MaxLength(1800)] - public string Content { get; set; } + [MaxLength(Limits.MediumTextLength)] + public required string Content { get; set; } public Guid? ParentCommentId { get; set; } } diff --git a/Api/Models/EventComment/EventCommentModel.cs b/Api/Models/EventComment/EventCommentModel.cs index 202497771e257202e83c310214dfa4c5bb377b51..32d90f745654469826fc014fdcd45c6d444a5751 100644 --- a/Api/Models/EventComment/EventCommentModel.cs +++ b/Api/Models/EventComment/EventCommentModel.cs @@ -4,9 +4,9 @@ { public Guid Id { get; set; } public Guid PosterId { get; set; } - public string Poster { get; set; } + public required string Poster { get; set; } public Guid EventId { get; set; } - public string Content { get; set; } + public required string Content { get; set; } public Guid? ParentCommentId { get; set; } public DateTime CreatedAt { get; set; } public DateTime UpdatedAt { get; set; } diff --git a/Api/Models/EventComment/EventCommentUpdateModel.cs b/Api/Models/EventComment/EventCommentUpdateModel.cs index e0baaf6e02ec79665e65c02eb59549b684dc3c58..839096d1eeca1a21a1aa879f607727d28f204c33 100644 --- a/Api/Models/EventComment/EventCommentUpdateModel.cs +++ b/Api/Models/EventComment/EventCommentUpdateModel.cs @@ -1,10 +1,11 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.EventComment { public class EventCommentUpdateModel { - [MaxLength(1800)] - public string Content { get; set; } + [MaxLength(Limits.MediumTextLength)] + public required string Content { get; set; } } } diff --git a/Api/Models/EventParticipant/EventParticipantModel.cs b/Api/Models/EventParticipant/EventParticipantModel.cs index 91882b010ca33d178c7e4b65d88f56036738c1b5..fb6e4d80d75919cbc74ae5362ed84fec633ada3b 100644 --- a/Api/Models/EventParticipant/EventParticipantModel.cs +++ b/Api/Models/EventParticipant/EventParticipantModel.cs @@ -6,8 +6,8 @@ namespace Api.Models.EventParticipant { public class EventParticipantModel { - public UserModel User { get; set; } - public EventModel Event { get; set; } + public required UserModel User { get; set; } + public required EventModel Event { get; set; } public ParticipantType Attendance { get; set; } public DateTime CreatedAt { get; set; } public DateTime UpdatedAt { get; set; } diff --git a/Api/Models/Location/LocationCreateModel.cs b/Api/Models/Location/LocationCreateModel.cs index 305a07cff1b9a15efc9e2c6efb6867a8802e2c3f..dbf22ab714abcc94af94620483c3fdfe07ba83b0 100644 --- a/Api/Models/Location/LocationCreateModel.cs +++ b/Api/Models/Location/LocationCreateModel.cs @@ -1,3 +1,4 @@ +using DAL.Constants; using System.ComponentModel.DataAnnotations; namespace Api.Models.Location; @@ -5,17 +6,17 @@ namespace Api.Models.Location; public class LocationCreateModel { [Required] - [MaxLength(255)] - public string Country { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Country { get; set; } [Required] - [MaxLength(255)] - public string City { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string City { get; set; } [Required] - [MaxLength(255)] - public string Address { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Address { get; set; } - [MaxLength(5)] - public string Zipcode { get; set; } + [MaxLength(Limits.ZipcodeLength)] + public required string Zipcode { get; set; } } \ No newline at end of file diff --git a/Api/Models/Location/LocationModel.cs b/Api/Models/Location/LocationModel.cs index e576b653b8d73c733e2cea6a7c387c2f203346c0..a39923aeeee9a3943a66792ca615677bfe188aec 100644 --- a/Api/Models/Location/LocationModel.cs +++ b/Api/Models/Location/LocationModel.cs @@ -3,9 +3,9 @@ namespace Api.Models.Location; public class LocationModel { public Guid RestaurantId { get; set; } - public string Country { get; set; } - public string City { get; set; } - public string Address { get; set; } + public required string Country { get; set; } + public required string City { get; set; } + public required string Address { get; set; } public string? ZipCode { get; set; } public DateTime CreatedAt { get; set; } public DateTime UpdatedAt { get; set; } diff --git a/Api/Models/Location/LocationUpdateModel.cs b/Api/Models/Location/LocationUpdateModel.cs index 74dce607cc464d08624253b88116c93b1345da7c..dc589c0b48ea329933ff4535ad060613293e09ab 100644 --- a/Api/Models/Location/LocationUpdateModel.cs +++ b/Api/Models/Location/LocationUpdateModel.cs @@ -1,18 +1,19 @@ +using DAL.Constants; using System.ComponentModel.DataAnnotations; namespace Api.Models.Location; public class LocationUpdateModel { - [MaxLength(255)] + [MaxLength(Limits.ShortTextLength)] public string? Country { get; set; } - [MaxLength(255)] + [MaxLength(Limits.ShortTextLength)] public string? City { get; set; } - [MaxLength(255)] + [MaxLength(Limits.ShortTextLength)] public string? Address { get; set; } - [MaxLength(5)] + [MaxLength(Limits.ZipcodeLength)] public string? Zipcode { get; set; } } \ No newline at end of file diff --git a/Api/Models/Restaurant/RestaurantCreateModel.cs b/Api/Models/Restaurant/RestaurantCreateModel.cs index e40553a17d46978b4cf3f412f5c945252c44f2f5..68e9690f1ac6139cf5f8bcd01e6aca39bb8a5499 100644 --- a/Api/Models/Restaurant/RestaurantCreateModel.cs +++ b/Api/Models/Restaurant/RestaurantCreateModel.cs @@ -1,7 +1,6 @@ using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; using Api.Models.Location; -using DAL.Models; +using DAL.Constants; namespace Api.Models.Restaurant; @@ -11,10 +10,10 @@ public class RestaurantCreateModel public Guid MaintainerId { get; set; } [Required] - [MaxLength(255)] - public string Name { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Name { get; set; } - [MaxLength(3600)] + [MaxLength(Limits.LongTextLength)] public string? About { get; set; } [Phone] @@ -27,9 +26,9 @@ public class RestaurantCreateModel public string? Web { get; set; } [Required] - [MaxLength(255)] - public string Category { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Category { get; set; } [Required] - public LocationCreateModel Location { get; set; } + public required LocationCreateModel Location { get; set; } } \ No newline at end of file diff --git a/Api/Models/Restaurant/RestaurantDetailModel.cs b/Api/Models/Restaurant/RestaurantDetailModel.cs index 99bc3d8913d9fd85bb3464bf797b10d727649dad..5937294014fe6663b5316a6782ecb7858aa71b07 100644 --- a/Api/Models/Restaurant/RestaurantDetailModel.cs +++ b/Api/Models/Restaurant/RestaurantDetailModel.cs @@ -8,16 +8,16 @@ namespace Api.Models.Restaurant public class RestaurantDetailModel { public Guid Id { get; set; } - public string Name { 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 LocationModel Location { get; set; } + public required string Category { get; set; } + public required LocationModel Location { get; set; } public ReviewAggregateModel? ReviewAggregate { get; set; } - public List<UserModel> Maintainers { get; set; } - public List<EventModel> Events { get; set; } + public required List<UserModel> Maintainers { get; set; } + public required List<EventModel> Events { 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 933a56cb31fc9008f520f893e185afe7f6b1188f..f03671f9fca451a5ff085d78b8d6b249e73d009f 100644 --- a/Api/Models/Restaurant/RestaurantModel.cs +++ b/Api/Models/Restaurant/RestaurantModel.cs @@ -7,7 +7,7 @@ namespace Api.Models.Restaurant; public class RestaurantModel { public Guid Id { get; set; } - public string Name { get; set; } + public required string Name { get; set; } public string? About { get; set; } public string? Phone { get; set; } public string? Email { get; set; } diff --git a/Api/Models/Restaurant/RestaurantUpdateModel.cs b/Api/Models/Restaurant/RestaurantUpdateModel.cs index e68e336bad70046643ee8340317c8432ae680e94..b93df600bb41d30b49758c66c783e68f97078639 100644 --- a/Api/Models/Restaurant/RestaurantUpdateModel.cs +++ b/Api/Models/Restaurant/RestaurantUpdateModel.cs @@ -1,13 +1,14 @@ +using DAL.Constants; using System.ComponentModel.DataAnnotations; namespace Api.Models.Restaurant; public class RestaurantUpdateModel { - [MaxLength(255)] + [MaxLength(Limits.ShortTextLength)] public string? Name { get; set; } - [MaxLength(3600)] + [MaxLength(Limits.LongTextLength)] public string? About { get; set; } [Phone] @@ -19,6 +20,6 @@ public class RestaurantUpdateModel [Url] public string? Web { get; set; } - [MaxLength(255)] + [MaxLength(Limits.ShortTextLength)] public string? Category { get; set; } } \ No newline at end of file diff --git a/Api/Models/Review/ReviewCreateModel.cs b/Api/Models/Review/ReviewCreateModel.cs index 6e7d3e2ef673c3f29650462d8586642f0e4ed008..8dd054482209beb577fc7e1b1d17d626395e33ab 100644 --- a/Api/Models/Review/ReviewCreateModel.cs +++ b/Api/Models/Review/ReviewCreateModel.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.Review { @@ -9,16 +10,16 @@ namespace Api.Models.Review [Required] public Guid RestaurantId { get; set; } [Required] - [MaxLength(3600)] - public string Content { get; set; } + [MaxLength(Limits.LongTextLength)] + public required string Content { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint FoodRating { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint ServiceRating { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint EnvironmentRating { get; set; } public bool? ServesFreeWater { get; set; } public float? TimeSpent { get; set; } diff --git a/Api/Models/Review/ReviewFilter.cs b/Api/Models/Review/ReviewFilter.cs index 43b8759980c1c349d48a01b6252613b059738b52..bfa444c165e8542d7a0c6f6f6719bb99c993d552 100644 --- a/Api/Models/Review/ReviewFilter.cs +++ b/Api/Models/Review/ReviewFilter.cs @@ -4,7 +4,6 @@ { public Guid? PosterId { get; set; } public Guid? RestaurantId { get; set; } - public uint? FoodGreaterEqual { get; set; } public uint? FoodLessEqual { get; set; } public uint? EnvGreaterEqual { get; set; } diff --git a/Api/Models/Review/ReviewModel.cs b/Api/Models/Review/ReviewModel.cs index 0328719935d343b9f04f53231ee3515c5d61fa61..6b8c6af0162b9770146e2a80845f3c21285577c3 100644 --- a/Api/Models/Review/ReviewModel.cs +++ b/Api/Models/Review/ReviewModel.cs @@ -5,9 +5,9 @@ namespace Api.Models.Review public class ReviewModel { public Guid Id { get; set; } - public UserModel Poster { get; set; } + public UserModel? Poster { get; set; } public Guid RestaurantId { get; set; } - public string Content { get; set; } + public required string Content { get; set; } public uint FoodRating { get; set; } public uint ServiceRating { get; set; } public uint EnvironmentRating { get; set; } diff --git a/Api/Models/Review/ReviewUpdateModel.cs b/Api/Models/Review/ReviewUpdateModel.cs index a47dbde3c5f250cded2eab9ff205da1f5c3ead81..5bd9d36f241d7770c599beb8edae3a279cf9716c 100644 --- a/Api/Models/Review/ReviewUpdateModel.cs +++ b/Api/Models/Review/ReviewUpdateModel.cs @@ -1,16 +1,17 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.Review { public class ReviewUpdateModel { - [MaxLength(3600)] - public string Content { get; set; } - [Range(1, 10)] + [MaxLength(Limits.LongTextLength)] + public string? Content { get; set; } + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint? FoodRating { get; set; } - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint? ServiceRating { get; set; } - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint? EnvironmentRating { get; set; } public bool? ServesFreeWater { get; set; } public float? TimeSpent { get; set; } diff --git a/Api/Models/ReviewComment/ReviewCommentCreateModel.cs b/Api/Models/ReviewComment/ReviewCommentCreateModel.cs index 206aa0010419bf2608406aad3a284094f5bdd712..abe51ede937dfbbed1c692362b7d08356ba837cd 100644 --- a/Api/Models/ReviewComment/ReviewCommentCreateModel.cs +++ b/Api/Models/ReviewComment/ReviewCommentCreateModel.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.ReviewComment { @@ -10,7 +11,7 @@ namespace Api.Models.ReviewComment public Guid ReviewId { get; set; } public Guid? ParentCommentId { get; set; } [Required] - [MaxLength(1800)] - public string Content { get; set; } + [MaxLength(Limits.MediumTextLength)] + public required string Content { get; set; } } } diff --git a/Api/Models/ReviewComment/ReviewCommentModel.cs b/Api/Models/ReviewComment/ReviewCommentModel.cs index 0074241154d2be6bf5cfd5158e415044dc2977a7..2211b582d78a558eaa10abb953e0758e4904e83a 100644 --- a/Api/Models/ReviewComment/ReviewCommentModel.cs +++ b/Api/Models/ReviewComment/ReviewCommentModel.cs @@ -5,10 +5,10 @@ namespace Api.Models.ReviewComment public class ReviewCommentModel { public Guid Id { get; set; } - public UserModel Poster { get; set; } + public UserModel? Poster { get; set; } public Guid ReviewId { get; set; } public Guid? ParentCommentId { get; set; } - public string Content { get; set; } + 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/ReviewComment/ReviewCommentUpdateModel.cs b/Api/Models/ReviewComment/ReviewCommentUpdateModel.cs index 6df1a551c8d30d1b0c3770659714cd5ca87729b2..c0e578c0c14cd38a9d544a3dfe464803bdb30a9a 100644 --- a/Api/Models/ReviewComment/ReviewCommentUpdateModel.cs +++ b/Api/Models/ReviewComment/ReviewCommentUpdateModel.cs @@ -1,11 +1,12 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.ReviewComment { public class ReviewCommentUpdateModel { [Required] - [MaxLength(1800)] - public string Content { get; set; } + [MaxLength(Limits.MediumTextLength)] + public required string Content { get; set; } } } diff --git a/Api/Models/User/UserCreateModel.cs b/Api/Models/User/UserCreateModel.cs index ea88ffaf51fca04fdfe1fd107f1365f91cc41ffb..b62a1fc6825186c654dc05c528b8b4986643dbe9 100644 --- a/Api/Models/User/UserCreateModel.cs +++ b/Api/Models/User/UserCreateModel.cs @@ -1,14 +1,15 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.User { public class UserCreateModel { [Required] - [MaxLength(255)] - public string Name { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Name { get; set; } [Required] [EmailAddress] - public string Email { get; set; } + public required string Email { get; set; } } } diff --git a/Api/Models/User/UserDetailModel.cs b/Api/Models/User/UserDetailModel.cs index ebf706fea119cf697fdfd9aaeda5ce36f48a685e..8a142a5feaeb405b145b46fa41281e6f721c4c4c 100644 --- a/Api/Models/User/UserDetailModel.cs +++ b/Api/Models/User/UserDetailModel.cs @@ -5,11 +5,11 @@ namespace Api.Models.User public class UserDetailModel { public Guid Id { get; set; } - public string Name { get; set; } - public string Email { 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; } - public List<RestaurantModel> MaintainedRestaurants { get; set; } + public required List<RestaurantModel> MaintainedRestaurants { get; set; } } } diff --git a/Api/Models/User/UserModel.cs b/Api/Models/User/UserModel.cs index 6873ae5962011252b70c44f78206be2c5b266ff8..593f8a518026afc0410531c3a4959f28c39d8a92 100644 --- a/Api/Models/User/UserModel.cs +++ b/Api/Models/User/UserModel.cs @@ -3,8 +3,8 @@ public class UserModel { public Guid Id { get; set; } - public string Name { get; set; } - public string Email { 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; } diff --git a/Api/Models/User/UserUpdateModel.cs b/Api/Models/User/UserUpdateModel.cs index ac61716b74b346b32ec4b8e8ff8752a99a1e5a23..852022b502213aacdd230f1e0ad420d0e8e8902d 100644 --- a/Api/Models/User/UserUpdateModel.cs +++ b/Api/Models/User/UserUpdateModel.cs @@ -1,10 +1,11 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; namespace Api.Models.User { public class UserUpdateModel { - [MaxLength(255)] + [MaxLength(Limits.ShortTextLength)] public string? Name { get; set; } [EmailAddress] public string? Email { get; set; } diff --git a/Api/Program.cs b/Api/Program.cs index 1c1c489ad79c39ba7f25878873e3c50f3c8f3c06..9f7fb9330bd2fd1b750081e9efdd06ec29e6cae3 100644 --- a/Api/Program.cs +++ b/Api/Program.cs @@ -5,18 +5,12 @@ using Microsoft.OpenApi.Models; var builder = WebApplication.CreateBuilder(args); -var envName = builder.Environment.EnvironmentName; -IConfigurationRoot configuration = new ConfigurationBuilder() - .SetBasePath(AppDomain.CurrentDomain.BaseDirectory) - .AddJsonFile("appsettings.json") - .AddJsonFile($"appsettings.{envName}.json", optional: true, reloadOnChange: true) - .Build(); - builder.Services.AddLogging(); // Add services to the container. builder.Services.AddDbContextFactory<RestaurantDBContext>(options => - options.UseLazyLoadingProxies().UseSqlServer(configuration.GetConnectionString("MSSQL")) + options.UseSqlServer( + builder.Configuration.GetConnectionString("MSSQL")) ); builder.Services.AddControllers(); @@ -48,7 +42,7 @@ builder.Services.AddSwaggerGen(c => Id = "Bearer" } }, - new string[] {} + Array.Empty<string> () } }); }); diff --git a/DAL/Constants/Limits.cs b/DAL/Constants/Limits.cs new file mode 100644 index 0000000000000000000000000000000000000000..627a783d09ed72e1bd331ddffc0f1ead3c74015f --- /dev/null +++ b/DAL/Constants/Limits.cs @@ -0,0 +1,13 @@ +namespace DAL.Constants +{ + public static class Limits + { + public const int MinimumRating = 1; + public const int MaximumRating = 10; + public const int TitleLength = 100; + public const int ZipcodeLength = 5; + public const int ShortTextLength = 255; + public const int MediumTextLength = 1800; + public const int LongTextLength = 3600; + } +} diff --git a/DAL/Models/CommentBase.cs b/DAL/Models/CommentBase.cs index 80e48cb6b6553fcc433940ab527825a4f9765eb7..e078e9b6873e59b508c661cd89d94eeb3f9883c3 100644 --- a/DAL/Models/CommentBase.cs +++ b/DAL/Models/CommentBase.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace DAL.Models @@ -9,10 +10,10 @@ namespace DAL.Models public Guid PosterId { get; set; } [ForeignKey(nameof(PosterId))] - public virtual User Poster { get; set; } + public virtual User? Poster { get; set; } [Required] - [MaxLength(1800)] - public string Content { get; set; } + [MaxLength(Limits.MediumTextLength)] + public required string Content { get; set; } } } diff --git a/DAL/Models/Event.cs b/DAL/Models/Event.cs index a0b42cb293dacef40eace85bba1b68584a16202f..b409321e25f3742adcfffad8391ee78020b2d14f 100644 --- a/DAL/Models/Event.cs +++ b/DAL/Models/Event.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; +using DAL.Constants; namespace DAL.Models { @@ -7,8 +8,8 @@ namespace DAL.Models public class Event : BaseEntity { [Required] - [MaxLength(100)] - public string Title { get; set; } + [MaxLength(Limits.TitleLength)] + public required string Title { get; set; } [Required] public Guid RestaurantId { get; set; } @@ -17,15 +18,15 @@ namespace DAL.Models public DateTime Date { get; set; } [Required] - [MaxLength(3600)] - public string Content { get; set; } + [MaxLength(Limits.LongTextLength)] + public required string Content { get; set; } [ForeignKey(nameof(RestaurantId))] - public virtual Restaurant Restaurant { get; set; } + public virtual Restaurant? Restaurant { get; set; } - public virtual ICollection<EventParticipant> Participants { get; set; } + public virtual ICollection<EventParticipant> Participants { get; set; } = []; - public virtual ICollection<EventComment> Comments { get; set; } + public virtual ICollection<EventComment> Comments { get; set; } = []; } } diff --git a/DAL/Models/EventComment.cs b/DAL/Models/EventComment.cs index bb20e7abfe04793f3b829d31de68f6ddc2d2e072..14d32ae1c66497787191bdf3bd7340a4cd2024de 100644 --- a/DAL/Models/EventComment.cs +++ b/DAL/Models/EventComment.cs @@ -5,24 +5,18 @@ namespace DAL.Models { public class EventComment : CommentBase { - [Required] - public Guid PosterId { get; set; } - public Guid? ParentCommentId { get; set; } [Required] public Guid EventId { get; set; } - [ForeignKey(nameof(PosterId))] - public virtual User Poster { get; set; } - [ForeignKey(nameof(ParentCommentId))] - public virtual EventComment ParentComment { get; set; } + public virtual EventComment? ParentComment { get; set; } [ForeignKey(nameof(EventId))] - public virtual Event Event { get; set; } + public virtual Event? Event { get; set; } - public virtual List<EventComment> ChildComments { get; set; } + public virtual List<EventComment> ChildComments { get; set; } = []; } } diff --git a/DAL/Models/EventParticipant.cs b/DAL/Models/EventParticipant.cs index a7889f1fe675eb5cb270e9144a88fd53d2d8ab84..fa122dbd266a023268cc35458787fc8aca1b76bb 100644 --- a/DAL/Models/EventParticipant.cs +++ b/DAL/Models/EventParticipant.cs @@ -18,9 +18,9 @@ namespace DAL.Models public ParticipantType Attendance { get; set; } [ForeignKey(nameof(UserId))] - public virtual User User { get; set; } + public virtual User? User { get; set; } [ForeignKey(nameof(EventId))] - public virtual Event Event { get; set; } + public virtual Event? Event { get; set; } } } diff --git a/DAL/Models/Location.cs b/DAL/Models/Location.cs index 9084ab9d265f032cdebb574e0a132b14671f0c08..614cef57a630e989155b3e6a819c44f8ea89ae3a 100644 --- a/DAL/Models/Location.cs +++ b/DAL/Models/Location.cs @@ -1,3 +1,4 @@ +using DAL.Constants; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -9,20 +10,20 @@ public class Location : LifeCycleEntity public Guid RestaurantId { get; set; } [ForeignKey(nameof(RestaurantId))] - public virtual Restaurant Restaurant { get; set; } + public virtual Restaurant? Restaurant { get; set; } [Required] - [MaxLength(255)] - public string Country { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Country { get; set; } [Required] - [MaxLength(255)] - public string City { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string City { get; set; } [Required] - [MaxLength(255)] - public string Address { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Address { get; set; } - [MaxLength(5)] - public string Zipcode { get; set; } + [MaxLength(Limits.ZipcodeLength)] + public required string Zipcode { get; set; } } \ No newline at end of file diff --git a/DAL/Models/Restaurant.cs b/DAL/Models/Restaurant.cs index f1632259bab0af224ae4adf872fa644fdc599f69..065dd4fa4cce3a55a01518df6c7f8e61a02526e8 100644 --- a/DAL/Models/Restaurant.cs +++ b/DAL/Models/Restaurant.cs @@ -1,23 +1,23 @@ +using DAL.Constants; using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; namespace DAL.Models; public class Restaurant : BaseEntity { - public virtual Location Location { get; set; } + public virtual Location? Location { get; set; } - public virtual ICollection<User> RestaurantMaintainers { get; set; } - public virtual ICollection<Review> Reviews { get; set; } - public virtual ICollection<Event> Events { get; set; } + public virtual ICollection<User> RestaurantMaintainers { get; set; } = []; + public virtual ICollection<Review> Reviews { get; set; } = []; + public virtual ICollection<Event> Events { get; set; } = []; - public virtual ReviewAggregate ReviewAggregate { get; set; } + public virtual ReviewAggregate? ReviewAggregate { get; set; } [Required] - [MaxLength(255)] - public string Name { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Name { get; set; } - [MaxLength(3600)] + [MaxLength(Limits.LongTextLength)] public string? About { get; set; } [Phone] @@ -29,6 +29,6 @@ public class Restaurant : BaseEntity [Url] public string? Web { get; set; } - [MaxLength(255)] - public string Category { get; set; } + [MaxLength(Limits.ShortTextLength)] + public required string Category { get; set; } } \ No newline at end of file diff --git a/DAL/Models/Review.cs b/DAL/Models/Review.cs index fe2ca1fd52baa74aeaccc2b0ec0cbfdd4e62d1a1..b73461cf7189b5992abb61506fcb21f9fe5f2ec6 100644 --- a/DAL/Models/Review.cs +++ b/DAL/Models/Review.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using DAL.Constants; +using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -9,29 +10,29 @@ namespace DAL.Models { public Guid PosterId { get; set; } [ForeignKey(nameof(PosterId))] - public virtual User Poster { get; set; } + public virtual User? Poster { get; set; } public Guid RestaurantId { get; set; } [ForeignKey(nameof(RestaurantId))] - public virtual Restaurant Restaurant { get; set; } + public virtual Restaurant? Restaurant { get; set; } [Required] - [MaxLength(3600)] - public string Content { get; set; } + [MaxLength(Limits.LongTextLength)] + public required string Content { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint FoodRating { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint ServiceRating { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint EnvironmentRating { get; set; } public bool? ServesFreeWater { get; set; } public float? TimeSpent { get; set; } public bool? LeftTip { get; set; } - public virtual List<ReviewComment> Comments { get; set; } + public virtual List<ReviewComment> Comments { get; set; } = []; } } diff --git a/DAL/Models/ReviewAggregate.cs b/DAL/Models/ReviewAggregate.cs index 16799342e7e7455e28b2632fd304cb592581e229..2b274496eee7c8f053e3a71cbaf20688f9ea0087 100644 --- a/DAL/Models/ReviewAggregate.cs +++ b/DAL/Models/ReviewAggregate.cs @@ -1,4 +1,5 @@ -using System.ComponentModel.DataAnnotations; +using DAL.Constants; +using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace DAL.Models @@ -9,18 +10,18 @@ namespace DAL.Models public Guid RestaurantId { get; set; } [ForeignKey(nameof(RestaurantId))] - public virtual Restaurant Restaurant { get; set; } + public virtual Restaurant? Restaurant { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint FoodRating { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint ServiceRating { get; set; } [Required] - [Range(1, 10)] + [Range(Limits.MinimumRating, Limits.MaximumRating)] public uint EnvironmentRating { get; set; } } } diff --git a/DAL/Models/ReviewComment.cs b/DAL/Models/ReviewComment.cs index ad1758812afde1806260a738e6ac2acb4d6f102d..bcea0a2729a08ccd7c673d82b91a6b327ca9ad11 100644 --- a/DAL/Models/ReviewComment.cs +++ b/DAL/Models/ReviewComment.cs @@ -1,5 +1,4 @@ using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace DAL.Models @@ -10,13 +9,13 @@ namespace DAL.Models public Guid ReviewId { get; set; } [ForeignKey(nameof(ReviewId))] - public virtual Review Review { get; set; } + public virtual Review? Review { get; set; } public Guid? ParentCommentId { get; set; } [ForeignKey(nameof(ParentCommentId))] - public virtual ReviewComment ParentComment { get; set; } + public virtual ReviewComment? ParentComment { get; set; } - public virtual List<ReviewComment> ChildComments { get; set; } + public virtual List<ReviewComment> ChildComments { get; set; } = []; } } diff --git a/DAL/Models/User.cs b/DAL/Models/User.cs index f7fc1185b17961a3b71bd0f59e6144a3e52ed41c..8a1accb9b9304bb1cc550ea0c8ee82cafd20d10e 100644 --- a/DAL/Models/User.cs +++ b/DAL/Models/User.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using DAL.Constants; +using Microsoft.EntityFrameworkCore; using System.ComponentModel.DataAnnotations; namespace DAL.Models @@ -7,12 +8,12 @@ namespace DAL.Models public class User : BaseEntity { [Required] - [MaxLength(255)] - public string Name { get; set; } = string.Empty; + [MaxLength(Limits.ShortTextLength)] + public required string Name { get; set; } [Required] [EmailAddress] - public string Email { get; set; } = string.Empty; + public required string Email { get; set; } public string? AvatarUrl { get; set; } - public virtual ICollection<Restaurant> MaintainedRestaurants { get; set; } + public virtual ICollection<Restaurant> MaintainedRestaurants { get; set; } = []; } } diff --git a/MVC/MVC.csproj b/MVC/MVC.csproj index d7735b708e70eae6468ae4d8cef1cf0e4c54cf59..2eebefecf2b555249bc5be0d910baa5e79c96ad2 100644 --- a/MVC/MVC.csproj +++ b/MVC/MVC.csproj @@ -4,6 +4,7 @@ <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> + <TreatWarningsAsErrors>true</TreatWarningsAsErrors> </PropertyGroup> <ItemGroup>