From 2ecd3ff8bf4e9bc5df9ac4382a4d1e4c945a54a7 Mon Sep 17 00:00:00 2001 From: StevanFreeborn Date: Tue, 21 Jun 2022 14:07:56 -0500 Subject: [PATCH] added xml comments to swagger. finished adding all filter query params to episode endpoint. --- .editorconfig | 3 ++ server/Models/EpisodeFilter.cs | 41 +++++++++++++++++++ .../Repositories/EpisodeRepository.cs | 31 ++++++++++++++ server/Program.cs | 9 +++- server/Properties/launchSettings.json | 1 - server/server.csproj | 1 + 6 files changed, 84 insertions(+), 2 deletions(-) diff --git a/.editorconfig b/.editorconfig index ab869c3..801f4f7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,3 +5,6 @@ dotnet_diagnostic.CS0472.severity = none # CS8604: Possible null reference argument. dotnet_diagnostic.CS8604.severity = none + +# CS1591: Missing XML comment for publicly visible type or member +dotnet_diagnostic.CS1591.severity = none diff --git a/server/Models/EpisodeFilter.cs b/server/Models/EpisodeFilter.cs index 2d7312b..c338856 100644 --- a/server/Models/EpisodeFilter.cs +++ b/server/Models/EpisodeFilter.cs @@ -8,8 +8,49 @@ namespace server.Models { public class EpisodeFilter { + /// + /// Use to filter episodes by season number. + /// public int? Season { get; set; } = null; + + /// + /// Use to filter episodes by those who have an air date on or after this value. + /// public DateTime? StartDate { get; set; } = null; + + /// + /// Use to filter episodes by those who have an air date on or before this value. + /// public DateTime? EndDate { get; set; } = null; + + /// + /// Use to filter episodes by episode title. + /// + public string? Title { get; set; } = null; + + /// + /// Use to filter episodes by those whose summary contains this value. + /// + public string? SummaryKeyword { get; set; } = null; + + /// + /// Use to filter episodes by director's name. + /// + public string? DirectedBy { get; set; } = null; + + /// + /// Use to filter episodes by writer's name. + /// + public string? WrittenBy { get; set; } = null; + + /// + /// Use to filter episodes by those who have millions of us viewers equal to or more than this value. + /// + public double? ViewersRangeStart { get; set; } = null; + + /// + /// Use to filter episodes by those who have millions of us viewers equal to or less than this value. + /// + public double? ViewersRangeEnd { get; set; } = null; } } diff --git a/server/Persistence/Repositories/EpisodeRepository.cs b/server/Persistence/Repositories/EpisodeRepository.cs index 275d996..274cbb2 100644 --- a/server/Persistence/Repositories/EpisodeRepository.cs +++ b/server/Persistence/Repositories/EpisodeRepository.cs @@ -1,6 +1,7 @@ using MongoDB.Driver; using MongoDB.Driver.Linq; using server.Models; +using System.Linq; namespace server.Persistence.Repositories { @@ -34,6 +35,36 @@ namespace server.Persistence.Repositories query = query.Where(episode => episode.AirDate <= filter.EndDate); } + if (filter?.Title != null) + { + query = query.Where(episode => episode.Title!.ToLower() == filter.Title.ToLower()); + } + + if (filter?.SummaryKeyword != null) + { + query = query.Where(episode => episode.Summary!.ToLower().Contains(filter.SummaryKeyword.ToLower())); + } + + if (filter?.DirectedBy != null) + { + query = query.Where(episode => episode.DirectedBy!.ToLower().Contains(filter.DirectedBy.ToLower())); + } + + if (filter?.WrittenBy != null) + { + query = query.Where(episode => episode.WrittenBy.Any(e => e.ToLower().Contains(filter.WrittenBy.ToLower()))); + } + + if (filter?.ViewersRangeStart != null) + { + query = query.Where(episode => episode.UsViewersInMillions >= filter.ViewersRangeStart); + } + + if (filter?.ViewersRangeEnd != null) + { + query = query.Where(episode => episode.UsViewersInMillions <= filter.ViewersRangeEnd); + } + return await query.ToListAsync(); } catch (Exception e) diff --git a/server/Program.cs b/server/Program.cs index 5c05cd5..eb82ced 100644 --- a/server/Program.cs +++ b/server/Program.cs @@ -7,6 +7,7 @@ using server.Options; using server.Persistence; using server.Persistence.Repositories; using server.Persistence.Seed; +using System.Reflection; if (args.Length == 2 && args[0].ToLower() == "seed") { @@ -41,7 +42,13 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.AddSwaggerGen(options => +{ + var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; + var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile); + + options.IncludeXmlComments(xmlPath); +}); builder.Services.ConfigureOptions(); diff --git a/server/Properties/launchSettings.json b/server/Properties/launchSettings.json index 7274ee1..d2eb249 100644 --- a/server/Properties/launchSettings.json +++ b/server/Properties/launchSettings.json @@ -11,7 +11,6 @@ "profiles": { "server": { "commandName": "Project", - "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" diff --git a/server/server.csproj b/server/server.csproj index f22ee52..907f33c 100644 --- a/server/server.csproj +++ b/server/server.csproj @@ -4,6 +4,7 @@ net6.0 enable enable + True