From 09e06147e6fe9ab7709e11396d1f2fe93d0a8dfc Mon Sep 17 00:00:00 2001 From: MysticFragilist Date: Sat, 23 Mar 2024 00:33:10 -0400 Subject: [PATCH] fix swagger --- core/Controllers/EventsController.cs | 7 +------ core/Controllers/ModeratorEventsController.cs | 3 ++- core/Controllers/ModeratorUserController.cs | 2 +- core/Controllers/OrganizerEventsController.cs | 2 +- core/Data/Entities/Publication.cs | 2 +- core/Data/{Entities => Enums}/State.cs | 2 +- core/Data/Requests/EventRequestDTO.cs | 5 +---- core/Data/Responses/EventResponseDTO.cs | 2 +- core/Extensions/ExceptionMiddlewareExtensions.cs | 11 +++++++++++ core/Program.cs | 11 +++++++++-- core/Repositories/EventRepository.cs | 3 +-- core/Services/Abstractions/IEventService.cs | 2 +- core/Services/EventService.cs | 2 +- core/Services/Jobs/SetPublicationEventJob.cs | 5 +---- core/api.core.csproj | 3 ++- tests/Tests/Services/EventServiceTests.cs | 3 ++- 16 files changed, 37 insertions(+), 28 deletions(-) rename core/Data/{Entities => Enums}/State.cs (91%) create mode 100644 core/Extensions/ExceptionMiddlewareExtensions.cs diff --git a/core/Controllers/EventsController.cs b/core/Controllers/EventsController.cs index 8bb0492..7228706 100644 --- a/core/Controllers/EventsController.cs +++ b/core/Controllers/EventsController.cs @@ -1,17 +1,12 @@ -using api.core.data.entities; using api.core.Data; -using api.core.Data.Entities; -using api.core.Data.Exceptions; -using api.core.Data.requests; +using api.core.Data.Enums; using api.core.Data.Requests; using api.core.Data.Responses; using api.core.Misc; using api.core.services.abstractions; -using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.OutputCaching; -using Microsoft.Extensions.Logging; namespace api.core.controllers; diff --git a/core/Controllers/ModeratorEventsController.cs b/core/Controllers/ModeratorEventsController.cs index e80937a..16ac970 100644 --- a/core/Controllers/ModeratorEventsController.cs +++ b/core/Controllers/ModeratorEventsController.cs @@ -1,10 +1,11 @@ using api.core.controllers; -using api.core.Data.Entities; +using api.core.Data.Enums; using api.core.Data.Exceptions; using api.core.Data.Requests; using api.core.Data.Responses; using api.core.Misc; using api.core.services.abstractions; + using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; diff --git a/core/Controllers/ModeratorUserController.cs b/core/Controllers/ModeratorUserController.cs index b0c193c..6929b5a 100644 --- a/core/Controllers/ModeratorUserController.cs +++ b/core/Controllers/ModeratorUserController.cs @@ -29,7 +29,7 @@ public async Task CreateOrganizer([FromBody] UserCreateDTO organi Guid.TryParse(supabaseUser, out Guid userId); var created = userService.AddOrganizer(userId, organizer); var frontBaseUrl = Environment.GetEnvironmentVariable("FRONTEND_BASE_URL") ?? throw new Exception("FRONTEND_BASE_URL is not set"); - await emailService.SendEmailAsync( + await emailService.SendEmailAsync( organizer.Email, "Votre compte Hello!", new UserCreationModel diff --git a/core/Controllers/OrganizerEventsController.cs b/core/Controllers/OrganizerEventsController.cs index 677b696..bba2367 100644 --- a/core/Controllers/OrganizerEventsController.cs +++ b/core/Controllers/OrganizerEventsController.cs @@ -6,8 +6,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using api.core.Data.Entities; using api.core.Data.Requests; +using api.core.Data.Enums; namespace api.core.Controllers; diff --git a/core/Data/Entities/Publication.cs b/core/Data/Entities/Publication.cs index 125929f..9331377 100644 --- a/core/Data/Entities/Publication.cs +++ b/core/Data/Entities/Publication.cs @@ -3,7 +3,7 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using api.core.Data.Entities; +using api.core.Data.Enums; using Microsoft.EntityFrameworkCore; diff --git a/core/Data/Entities/State.cs b/core/Data/Enums/State.cs similarity index 91% rename from core/Data/Entities/State.cs rename to core/Data/Enums/State.cs index ec72fe2..36e8b0c 100644 --- a/core/Data/Entities/State.cs +++ b/core/Data/Enums/State.cs @@ -1,6 +1,6 @@ using System.Text.Json.Serialization; -namespace api.core.Data.Entities; +namespace api.core.Data.Enums; /// /// 1 - OnHold diff --git a/core/Data/Requests/EventRequestDTO.cs b/core/Data/Requests/EventRequestDTO.cs index f50182b..27936a7 100644 --- a/core/Data/Requests/EventRequestDTO.cs +++ b/core/Data/Requests/EventRequestDTO.cs @@ -1,7 +1,4 @@ -using api.core.data.entities; -using api.core.Data.Entities; - -namespace api.core.Data.requests; +namespace api.core.Data.requests; public class EventRequestDTO { diff --git a/core/Data/Responses/EventResponseDTO.cs b/core/Data/Responses/EventResponseDTO.cs index 23ec81e..d2c306a 100644 --- a/core/Data/Responses/EventResponseDTO.cs +++ b/core/Data/Responses/EventResponseDTO.cs @@ -1,7 +1,7 @@ using System.Collections; using api.core.data.entities; -using api.core.Data.Entities; +using api.core.Data.Enums; namespace api.core.Data.Responses; diff --git a/core/Extensions/ExceptionMiddlewareExtensions.cs b/core/Extensions/ExceptionMiddlewareExtensions.cs new file mode 100644 index 0000000..4cb9548 --- /dev/null +++ b/core/Extensions/ExceptionMiddlewareExtensions.cs @@ -0,0 +1,11 @@ +using api.core.Misc; + +namespace api.core.Extensions; + +public static class ExceptionMiddlewareExtensions +{ + public static IApplicationBuilder UseExceptionMiddleware(this IApplicationBuilder iBuilder) + { + return iBuilder.UseMiddleware(); + } +} diff --git a/core/Program.cs b/core/Program.cs index 144a421..06a3296 100644 --- a/core/Program.cs +++ b/core/Program.cs @@ -9,6 +9,7 @@ using Microsoft.OpenApi.Models; using api.core.Misc; using api.emails; +using System.Reflection; var builder = WebApplication.CreateBuilder(args); @@ -94,9 +95,14 @@ Id = "Bearer" } }, - new string[] {} + Array.Empty() } }); + options.UseInlineDefinitionsForEnums(); + + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + options.IncludeXmlComments(xmlPath); }); builder.Services.AddEmailService(builder.Configuration); @@ -112,7 +118,8 @@ app.UseSwagger(); app.UseSwaggerUI(); -app.UseMiddleware(); + +app.UseExceptionMiddleware(); // app.UseHttpsRedirection(); diff --git a/core/Repositories/EventRepository.cs b/core/Repositories/EventRepository.cs index 03fcd81..38ff7b2 100644 --- a/core/Repositories/EventRepository.cs +++ b/core/Repositories/EventRepository.cs @@ -54,8 +54,7 @@ public IEnumerable GetAll() .Include(x => x.Publication) .ThenInclude(x => x.Tags) .Include(x => x.Publication) - .ThenInclude(x => x.Organizer) - .ToList(); + .ThenInclude(x => x.Organizer); } public bool Update(Guid id, Event entity) diff --git a/core/Services/Abstractions/IEventService.cs b/core/Services/Abstractions/IEventService.cs index 5a1849e..7fbc5db 100644 --- a/core/Services/Abstractions/IEventService.cs +++ b/core/Services/Abstractions/IEventService.cs @@ -1,4 +1,4 @@ -using api.core.Data.Entities; +using api.core.Data.Enums; using api.core.Data.requests; using api.core.Data.Responses; diff --git a/core/Services/EventService.cs b/core/Services/EventService.cs index 5483188..ed3c83f 100644 --- a/core/Services/EventService.cs +++ b/core/Services/EventService.cs @@ -1,5 +1,5 @@ using api.core.data.entities; -using api.core.Data.Entities; +using api.core.Data.Enums; using api.core.Data.Exceptions; using api.core.Data.requests; using api.core.Data.Responses; diff --git a/core/Services/Jobs/SetPublicationEventJob.cs b/core/Services/Jobs/SetPublicationEventJob.cs index 2ea83a0..8191525 100644 --- a/core/Services/Jobs/SetPublicationEventJob.cs +++ b/core/Services/Jobs/SetPublicationEventJob.cs @@ -1,7 +1,4 @@ -using System.Reflection.Metadata; - -using api.core.Data.Entities; -using api.core.Misc; +using api.core.Misc; using api.core.services.abstractions; using Quartz; diff --git a/core/api.core.csproj b/core/api.core.csproj index 614c1e7..49d97c9 100644 --- a/core/api.core.csproj +++ b/core/api.core.csproj @@ -8,6 +8,7 @@ d65d8ed2-e38b-45b2-b24e-88385df1ce57 Linux true + true false false @@ -32,7 +33,7 @@ - + diff --git a/tests/Tests/Services/EventServiceTests.cs b/tests/Tests/Services/EventServiceTests.cs index 7dd3d28..f524953 100644 --- a/tests/Tests/Services/EventServiceTests.cs +++ b/tests/Tests/Services/EventServiceTests.cs @@ -1,5 +1,5 @@ using api.core.data.entities; -using api.core.Data.Entities; +using api.core.Data.Enums; using api.core.Data.Exceptions; using api.core.Data.requests; using api.core.repositories.abstractions; @@ -7,6 +7,7 @@ using api.emails.Models; using api.emails.Services.Abstractions; using api.files.Services.Abstractions; + using Microsoft.Extensions.Configuration; using Moq;