diff --git a/.github/delete.jpg b/.github/delete.jpg deleted file mode 100644 index 0291a8f..0000000 Binary files a/.github/delete.jpg and /dev/null differ diff --git a/.github/get.jpg b/.github/get.jpg deleted file mode 100644 index 31de135..0000000 Binary files a/.github/get.jpg and /dev/null differ diff --git a/.github/getSingle.jpg b/.github/getSingle.jpg deleted file mode 100644 index d64b119..0000000 Binary files a/.github/getSingle.jpg and /dev/null differ diff --git a/.github/patch.jpg b/.github/patch.jpg deleted file mode 100644 index d418fd2..0000000 Binary files a/.github/patch.jpg and /dev/null differ diff --git a/.github/post.jpg b/.github/post.jpg deleted file mode 100644 index 53acd87..0000000 Binary files a/.github/post.jpg and /dev/null differ diff --git a/.github/put.jpg b/.github/put.jpg deleted file mode 100644 index 6ce793c..0000000 Binary files a/.github/put.jpg and /dev/null differ diff --git a/.github/versions.jpg b/.github/versions.jpg deleted file mode 100644 index 289a4b5..0000000 Binary files a/.github/versions.jpg and /dev/null differ diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml deleted file mode 100644 index 4379c5c..0000000 --- a/.github/workflows/dotnetcore.yml +++ /dev/null @@ -1,17 +0,0 @@ -name: .NET Core - -on: [push] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Setup .NET Core - uses: actions/setup-dotnet@v2 - with: - dotnet-version: '7.0.x' - - name: Build with dotnet - run: dotnet build --configuration Release diff --git a/SampleWebApiAspNetCore/Dtos/FoodCreateDto.cs b/SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodCreateDto.cs similarity index 51% rename from SampleWebApiAspNetCore/Dtos/FoodCreateDto.cs rename to SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodCreateDto.cs index 697dba7..f572d53 100644 --- a/SampleWebApiAspNetCore/Dtos/FoodCreateDto.cs +++ b/SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodCreateDto.cs @@ -1,6 +1,11 @@ -using System.ComponentModel.DataAnnotations; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace SampleWebApiAspNetCore.Dtos +namespace SampleWebApiAspNetCore.Domain.DataTransferObjects.Dtos { public class FoodCreateDto { diff --git a/SampleWebApiAspNetCore/Dtos/FoodDto.cs b/SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodDto.cs similarity index 57% rename from SampleWebApiAspNetCore/Dtos/FoodDto.cs rename to SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodDto.cs index 997c27e..93484b2 100644 --- a/SampleWebApiAspNetCore/Dtos/FoodDto.cs +++ b/SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodDto.cs @@ -1,4 +1,10 @@ -namespace SampleWebApiAspNetCore.Dtos +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SampleWebApiAspNetCore.Domain.DataTransferObjects.Dtos { public class FoodDto { diff --git a/SampleWebApiAspNetCore/Dtos/FoodUpdateDto.cs b/SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodUpdateDto.cs similarity index 54% rename from SampleWebApiAspNetCore/Dtos/FoodUpdateDto.cs rename to SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodUpdateDto.cs index 232b6bb..e6e0b97 100644 --- a/SampleWebApiAspNetCore/Dtos/FoodUpdateDto.cs +++ b/SampleWebApiAspNetCore.Domain/DataTransferObjects/Dtos/FoodUpdateDto.cs @@ -1,5 +1,10 @@ - -namespace SampleWebApiAspNetCore.Dtos +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SampleWebApiAspNetCore.Domain.DataTransferObjects.Dtos { public class FoodUpdateDto { diff --git a/SampleWebApiAspNetCore/Entities/FoodEntity.cs b/SampleWebApiAspNetCore.Domain/Entities/FoodEntity.cs similarity index 59% rename from SampleWebApiAspNetCore/Entities/FoodEntity.cs rename to SampleWebApiAspNetCore.Domain/Entities/FoodEntity.cs index fc03b43..3fcae78 100644 --- a/SampleWebApiAspNetCore/Entities/FoodEntity.cs +++ b/SampleWebApiAspNetCore.Domain/Entities/FoodEntity.cs @@ -1,4 +1,10 @@ -namespace SampleWebApiAspNetCore.Entities +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SampleWebApiAspNetCore.Domain.Entities { public class FoodEntity { diff --git a/SampleWebApiAspNetCore/Models/LinkDto.cs b/SampleWebApiAspNetCore.Domain/Models/LinkDto.cs similarity index 65% rename from SampleWebApiAspNetCore/Models/LinkDto.cs rename to SampleWebApiAspNetCore.Domain/Models/LinkDto.cs index 3169f93..e0a9b8a 100644 --- a/SampleWebApiAspNetCore/Models/LinkDto.cs +++ b/SampleWebApiAspNetCore.Domain/Models/LinkDto.cs @@ -1,4 +1,10 @@ -namespace SampleWebApiAspNetCore.Models +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SampleWebApiAspNetCore.Domain.Models { public class LinkDto { @@ -13,4 +19,4 @@ public LinkDto(string href, string rel, string method) Method = method; } } -} \ No newline at end of file +} diff --git a/SampleWebApiAspNetCore/Models/QueryParameters.cs b/SampleWebApiAspNetCore.Domain/Models/QueryParameters.cs similarity index 68% rename from SampleWebApiAspNetCore/Models/QueryParameters.cs rename to SampleWebApiAspNetCore.Domain/Models/QueryParameters.cs index 4df17ba..ed6343b 100644 --- a/SampleWebApiAspNetCore/Models/QueryParameters.cs +++ b/SampleWebApiAspNetCore.Domain/Models/QueryParameters.cs @@ -1,5 +1,4 @@ - -namespace SampleWebApiAspNetCore.Models +namespace SampleWebApiAspNetCore.Domain.Models { public class QueryParameters { @@ -16,5 +15,10 @@ public int PageCount public string? Query { get; set; } = ""; public string OrderBy { get; set; } = "Name"; + public bool IsDescending { get; set; } = false; + public bool HasQuery + { + get { return !string.IsNullOrEmpty(Query);} + } } -} \ No newline at end of file +} diff --git a/SampleWebApiAspNetCore.Domain/SampleWebApiAspNetCore.Domain.csproj b/SampleWebApiAspNetCore.Domain/SampleWebApiAspNetCore.Domain.csproj new file mode 100644 index 0000000..283adbc --- /dev/null +++ b/SampleWebApiAspNetCore.Domain/SampleWebApiAspNetCore.Domain.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/SampleWebApiAspNetCore/Helpers/CorsExtension.cs b/SampleWebApiAspNetCore.Service/Helpers/CorsExtension.cs similarity index 77% rename from SampleWebApiAspNetCore/Helpers/CorsExtension.cs rename to SampleWebApiAspNetCore.Service/Helpers/CorsExtension.cs index 066162c..a1b1beb 100644 --- a/SampleWebApiAspNetCore/Helpers/CorsExtension.cs +++ b/SampleWebApiAspNetCore.Service/Helpers/CorsExtension.cs @@ -1,6 +1,11 @@ using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace SampleWebApiAspNetCore.Helpers +namespace SampleWebApiAspNetCore.Service.Helpers { public static class CorsExtension { diff --git a/SampleWebApiAspNetCore/Helpers/DynamicExtensions.cs b/SampleWebApiAspNetCore.Service/Helpers/DynamicExtensions.cs similarity index 79% rename from SampleWebApiAspNetCore/Helpers/DynamicExtensions.cs rename to SampleWebApiAspNetCore.Service/Helpers/DynamicExtensions.cs index e284883..960d0b2 100644 --- a/SampleWebApiAspNetCore/Helpers/DynamicExtensions.cs +++ b/SampleWebApiAspNetCore.Service/Helpers/DynamicExtensions.cs @@ -1,8 +1,12 @@ +using System; using System.Collections.Generic; using System.ComponentModel; using System.Dynamic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace SampleWebApiAspNetCore.Models +namespace SampleWebApiAspNetCore.Service.Helpers { public static class DynamicExtensions { @@ -18,4 +22,4 @@ public static dynamic ToDynamic(this object value) return expando as ExpandoObject; } } -} \ No newline at end of file +} diff --git a/SampleWebApiAspNetCore/Helpers/ExceptionExtension.cs b/SampleWebApiAspNetCore.Service/Helpers/ExceptionExtension.cs similarity index 82% rename from SampleWebApiAspNetCore/Helpers/ExceptionExtension.cs rename to SampleWebApiAspNetCore.Service/Helpers/ExceptionExtension.cs index d2eff76..7dfbb80 100644 --- a/SampleWebApiAspNetCore/Helpers/ExceptionExtension.cs +++ b/SampleWebApiAspNetCore.Service/Helpers/ExceptionExtension.cs @@ -1,6 +1,9 @@ -using Microsoft.AspNetCore.Diagnostics; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Logging; +using Microsoft.AspNetCore.Diagnostics; +using Microsoft.AspNetCore.Http; -namespace SampleWebApiAspNetCore.Helpers +namespace SampleWebApiAspNetCore.Service.Helpers { public static class ExceptionExtension { diff --git a/SampleWebApiAspNetCore/Helpers/QueryParametersExtensions.cs b/SampleWebApiAspNetCore.Service/Helpers/QueryParametersExtensions.cs similarity index 91% rename from SampleWebApiAspNetCore/Helpers/QueryParametersExtensions.cs rename to SampleWebApiAspNetCore.Service/Helpers/QueryParametersExtensions.cs index fce6c9b..4ce5f49 100644 --- a/SampleWebApiAspNetCore/Helpers/QueryParametersExtensions.cs +++ b/SampleWebApiAspNetCore.Service/Helpers/QueryParametersExtensions.cs @@ -1,6 +1,8 @@ -using SampleWebApiAspNetCore.Models; + -namespace SampleWebApiAspNetCore.Helpers +using SampleWebApiAspNetCore.Domain.Models; + +namespace SampleWebApiAspNetCore.Service.Helpers { public static class QueryParametersExtensions { @@ -33,4 +35,4 @@ public static bool IsDescending(this QueryParameters queryParameters) return false; } } -} \ No newline at end of file +} diff --git a/SampleWebApiAspNetCore/Helpers/SeedDataExtension.cs b/SampleWebApiAspNetCore.Service/Helpers/SeedDataExtension.cs similarity index 57% rename from SampleWebApiAspNetCore/Helpers/SeedDataExtension.cs rename to SampleWebApiAspNetCore.Service/Helpers/SeedDataExtension.cs index acbc871..3ecf962 100644 --- a/SampleWebApiAspNetCore/Helpers/SeedDataExtension.cs +++ b/SampleWebApiAspNetCore.Service/Helpers/SeedDataExtension.cs @@ -1,7 +1,14 @@ -using SampleWebApiAspNetCore.Repositories; -using SampleWebApiAspNetCore.Services; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; +using SampleWebApiAspNetCore.Data; +using SampleWebApiAspNetCore.Service.Services.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace SampleWebApiAspNetCore.Helpers +namespace SampleWebApiAspNetCore.Service.Helpers { public static class SeedDataExtension { diff --git a/SampleWebApiAspNetCore/Helpers/VersioningExtension.cs b/SampleWebApiAspNetCore.Service/Helpers/VersioningExtension.cs similarity index 65% rename from SampleWebApiAspNetCore/Helpers/VersioningExtension.cs rename to SampleWebApiAspNetCore.Service/Helpers/VersioningExtension.cs index a3d80d1..e485907 100644 --- a/SampleWebApiAspNetCore/Helpers/VersioningExtension.cs +++ b/SampleWebApiAspNetCore.Service/Helpers/VersioningExtension.cs @@ -1,8 +1,13 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Versioning; using Microsoft.Extensions.DependencyInjection; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace SampleWebApiAspNetCore.Helpers +namespace SampleWebApiAspNetCore.Service.Helpers { public static class VersioningExtension { @@ -18,15 +23,13 @@ public static void AddVersioning(this IServiceCollection services) new HeaderApiVersionReader("x-api-version"), new MediaTypeApiVersionReader("x-api-version")); }); - services.AddVersionedApiExplorer( - options => - { - options.GroupNameFormat = "'v'VVV"; - - // note: this option is only necessary when versioning by url segment. the SubstitutionFormat - // can also be used to control the format of the API version in route templates - options.SubstituteApiVersionInUrl = true; - }); + services.AddApiVersioning(x => + { + x.DefaultApiVersion = new ApiVersion(1, 0); + x.AssumeDefaultVersionWhenUnspecified = true; + x.ReportApiVersions = true; + //x.ApiVersionReader = new HeaderApiVersionReader("x-api-version"); + }); } } } diff --git a/SampleWebApiAspNetCore/MappingProfiles/FoodMappings.cs b/SampleWebApiAspNetCore.Service/Mapper/FoodMappings.cs similarity index 67% rename from SampleWebApiAspNetCore/MappingProfiles/FoodMappings.cs rename to SampleWebApiAspNetCore.Service/Mapper/FoodMappings.cs index 42cdbed..6e49c45 100644 --- a/SampleWebApiAspNetCore/MappingProfiles/FoodMappings.cs +++ b/SampleWebApiAspNetCore.Service/Mapper/FoodMappings.cs @@ -1,8 +1,8 @@ using AutoMapper; -using SampleWebApiAspNetCore.Dtos; -using SampleWebApiAspNetCore.Entities; +using SampleWebApiAspNetCore.Domain.DataTransferObjects.Dtos; +using SampleWebApiAspNetCore.Domain.Entities; -namespace SampleWebApiAspNetCore.MappingProfiles +namespace SampleWebApiAspNetCore.Service.Mapper { public class FoodMappings : Profile { diff --git a/SampleWebApiAspNetCore.Service/SampleWebApiAspNetCore.Service.csproj b/SampleWebApiAspNetCore.Service/SampleWebApiAspNetCore.Service.csproj new file mode 100644 index 0000000..e7d1402 --- /dev/null +++ b/SampleWebApiAspNetCore.Service/SampleWebApiAspNetCore.Service.csproj @@ -0,0 +1,26 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + + + diff --git a/SampleWebApiAspNetCore/Services/LinkService.cs b/SampleWebApiAspNetCore.Service/Services/Implementations/LinkService.cs similarity index 96% rename from SampleWebApiAspNetCore/Services/LinkService.cs rename to SampleWebApiAspNetCore.Service/Services/Implementations/LinkService.cs index 38ad422..93c42c1 100644 --- a/SampleWebApiAspNetCore/Services/LinkService.cs +++ b/SampleWebApiAspNetCore.Service/Services/Implementations/LinkService.cs @@ -1,11 +1,12 @@ using Microsoft.AspNetCore.Mvc; -using SampleWebApiAspNetCore.Models; -using SampleWebApiAspNetCore.Helpers; -using System.Reflection; -using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.AspNetCore.Mvc.Infrastructure; +using Microsoft.AspNetCore.Mvc.Routing; +using SampleWebApiAspNetCore.Domain.Models; +using SampleWebApiAspNetCore.Service.Helpers; +using SampleWebApiAspNetCore.Service.Services.Interfaces; +using System.Reflection; -namespace SampleWebApiAspNetCore.Services +namespace SampleWebApiAspNetCore.Service.Services.Implementations { public class LinkService : ILinkService { diff --git a/SampleWebApiAspNetCore/Services/SeedDataService.cs b/SampleWebApiAspNetCore.Service/Services/Implementations/SeedDataService.cs similarity index 68% rename from SampleWebApiAspNetCore/Services/SeedDataService.cs rename to SampleWebApiAspNetCore.Service/Services/Implementations/SeedDataService.cs index 2ac7cc4..938f7b1 100644 --- a/SampleWebApiAspNetCore/Services/SeedDataService.cs +++ b/SampleWebApiAspNetCore.Service/Services/Implementations/SeedDataService.cs @@ -1,7 +1,13 @@ -using SampleWebApiAspNetCore.Entities; -using SampleWebApiAspNetCore.Repositories; +using SampleWebApiAspNetCore.Data; +using SampleWebApiAspNetCore.Domain.Entities; +using SampleWebApiAspNetCore.Service.Services.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace SampleWebApiAspNetCore.Services +namespace SampleWebApiAspNetCore.Service.Services.Implementations { public class SeedDataService : ISeedDataService { diff --git a/SampleWebApiAspNetCore/Services/ILinkService.cs b/SampleWebApiAspNetCore.Service/Services/Interfaces/ILinkService.cs similarity index 73% rename from SampleWebApiAspNetCore/Services/ILinkService.cs rename to SampleWebApiAspNetCore.Service/Services/Interfaces/ILinkService.cs index 053954f..927ac80 100644 --- a/SampleWebApiAspNetCore/Services/ILinkService.cs +++ b/SampleWebApiAspNetCore.Service/Services/Interfaces/ILinkService.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; -using SampleWebApiAspNetCore.Models; +using SampleWebApiAspNetCore.Domain.Models; -namespace SampleWebApiAspNetCore.Services +namespace SampleWebApiAspNetCore.Service.Services.Interfaces { public interface ILinkService { diff --git a/SampleWebApiAspNetCore/Services/ISeedDataService.cs b/SampleWebApiAspNetCore.Service/Services/Interfaces/ISeedDataService.cs similarity index 50% rename from SampleWebApiAspNetCore/Services/ISeedDataService.cs rename to SampleWebApiAspNetCore.Service/Services/Interfaces/ISeedDataService.cs index c649c8e..9c3d396 100644 --- a/SampleWebApiAspNetCore/Services/ISeedDataService.cs +++ b/SampleWebApiAspNetCore.Service/Services/Interfaces/ISeedDataService.cs @@ -1,6 +1,6 @@ -using SampleWebApiAspNetCore.Repositories; +using SampleWebApiAspNetCore.Data; -namespace SampleWebApiAspNetCore.Services +namespace SampleWebApiAspNetCore.Service.Services.Interfaces { public interface ISeedDataService { diff --git a/SampleWebApiAspNetCore.sln b/SampleWebApiAspNetCore.sln index 6eee05a..ad0f294 100644 --- a/SampleWebApiAspNetCore.sln +++ b/SampleWebApiAspNetCore.sln @@ -3,7 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApiAspNetCore", "SampleWebApiAspNetCore\SampleWebApiAspNetCore.csproj", "{36DF3175-0775-44CC-8708-5B67F2ED70FE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleWebApiAspNetCore", "SampleWebApiAspNetCore\SampleWebApiAspNetCore.csproj", "{36DF3175-0775-44CC-8708-5B67F2ED70FE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApiAspNetCore.Data", "SamplwWebApiAspNetCore.Data\SampleWebApiAspNetCore.Data.csproj", "{F8A0B9B1-740C-4512-B416-14908B05BB04}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApiAspNetCore.Domain", "SampleWebApiAspNetCore.Domain\SampleWebApiAspNetCore.Domain.csproj", "{97C27773-DBE8-40DD-9B74-ACE0337DBD2C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWebApiAspNetCore.Service", "SampleWebApiAspNetCore.Service\SampleWebApiAspNetCore.Service.csproj", "{3F208067-DCD5-4F2E-B1E5-A2502B0B5495}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +21,18 @@ Global {36DF3175-0775-44CC-8708-5B67F2ED70FE}.Debug|Any CPU.Build.0 = Debug|Any CPU {36DF3175-0775-44CC-8708-5B67F2ED70FE}.Release|Any CPU.ActiveCfg = Release|Any CPU {36DF3175-0775-44CC-8708-5B67F2ED70FE}.Release|Any CPU.Build.0 = Release|Any CPU + {F8A0B9B1-740C-4512-B416-14908B05BB04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8A0B9B1-740C-4512-B416-14908B05BB04}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8A0B9B1-740C-4512-B416-14908B05BB04}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8A0B9B1-740C-4512-B416-14908B05BB04}.Release|Any CPU.Build.0 = Release|Any CPU + {97C27773-DBE8-40DD-9B74-ACE0337DBD2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {97C27773-DBE8-40DD-9B74-ACE0337DBD2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {97C27773-DBE8-40DD-9B74-ACE0337DBD2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {97C27773-DBE8-40DD-9B74-ACE0337DBD2C}.Release|Any CPU.Build.0 = Release|Any CPU + {3F208067-DCD5-4F2E-B1E5-A2502B0B5495}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3F208067-DCD5-4F2E-B1E5-A2502B0B5495}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3F208067-DCD5-4F2E-B1E5-A2502B0B5495}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3F208067-DCD5-4F2E-B1E5-A2502B0B5495}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs b/SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs index 892e327..6ca09b8 100644 --- a/SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs +++ b/SampleWebApiAspNetCore/Controllers/v1/FoodsController.cs @@ -1,12 +1,12 @@ using AutoMapper; using Microsoft.AspNetCore.JsonPatch; using Microsoft.AspNetCore.Mvc; -using SampleWebApiAspNetCore.Dtos; -using SampleWebApiAspNetCore.Entities; -using SampleWebApiAspNetCore.Helpers; -using SampleWebApiAspNetCore.Services; -using SampleWebApiAspNetCore.Models; -using SampleWebApiAspNetCore.Repositories; +using SampleWebApiAspNetCore.Data.Repositories.Interfaces; +using SampleWebApiAspNetCore.Domain.DataTransferObjects.Dtos; +using SampleWebApiAspNetCore.Domain.Entities; +using SampleWebApiAspNetCore.Domain.Models; +using SampleWebApiAspNetCore.Service.Helpers; +using SampleWebApiAspNetCore.Service.Services.Interfaces; using System.Text.Json; namespace SampleWebApiAspNetCore.Controllers.v1 diff --git a/SampleWebApiAspNetCore/Program.cs b/SampleWebApiAspNetCore/Program.cs index 9e890c6..2c9262c 100644 --- a/SampleWebApiAspNetCore/Program.cs +++ b/SampleWebApiAspNetCore/Program.cs @@ -1,24 +1,24 @@ -using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Routing; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -using Newtonsoft.Json.Serialization; +using Microsoft.OpenApi.Models; using SampleWebApiAspNetCore; -using SampleWebApiAspNetCore.Helpers; -using SampleWebApiAspNetCore.MappingProfiles; -using SampleWebApiAspNetCore.Repositories; -using SampleWebApiAspNetCore.Services; +using SampleWebApiAspNetCore.Data; +using SampleWebApiAspNetCore.Data.Repositories.Implementations; +using SampleWebApiAspNetCore.Data.Repositories.Interfaces; +using SampleWebApiAspNetCore.Service.Helpers; +using SampleWebApiAspNetCore.Service.Mapper; +using SampleWebApiAspNetCore.Service.Services.Implementations; +using SampleWebApiAspNetCore.Service.Services.Interfaces; using Swashbuckle.AspNetCore.SwaggerGen; var builder = WebApplication.CreateBuilder(args); // Add services to the container. -builder.Services.AddControllers() - .AddNewtonsoftJson(options => - options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver()); +builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); @@ -29,11 +29,44 @@ builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(typeof(ILinkService<>), typeof(LinkService<>)); -builder.Services.AddTransient, ConfigureSwaggerOptions>(); +//builder.Services.AddTransient, ConfigureSwaggerOptions>(); + +builder.Services.AddSwaggerGen( + c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Sample Web API", Version = "v1" }); + c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme + { + Description = "Jwt auth header", + Name = "Authorization", + In = ParameterLocation.Header, + Type = SecuritySchemeType.ApiKey, + Scheme = "Bearer" + }); + c.AddSecurityRequirement(new OpenApiSecurityRequirement + { + { + new OpenApiSecurityScheme + { + Reference = new OpenApiReference + { + Type = ReferenceType.SecurityScheme, + Id = "Bearer" + }, + Scheme = "oauth2", + Name = "Bearer", + In = ParameterLocation.Header + }, + new List() + } + }); + } +); builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddRouting(options => options.LowercaseUrls = true); builder.Services.AddVersioning(); @@ -44,26 +77,32 @@ var app = builder.Build(); -var apiVersionDescriptionProvider = app.Services.GetRequiredService(); +//var apiVersionDescriptionProvider = app.Services.GetRequiredService(); var loggerFactory = app.Services.GetRequiredService(); // Configure the HTTP request pipeline. +//if (app.Environment.IsDevelopment()) +//{ +// app.UseSwagger(); +// app.UseSwaggerUI( +// options => +// { +// foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions) +// { +// options.SwaggerEndpoint( +// $"/swagger/{description.GroupName}/swagger.json", +// description.GroupName.ToUpperInvariant()); +// } +// }); + +// app.SeedData(); +//} + if (app.Environment.IsDevelopment()) { app.UseSwagger(); - app.UseSwaggerUI( - options => - { - foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions) - { - options.SwaggerEndpoint( - $"/swagger/{description.GroupName}/swagger.json", - description.GroupName.ToUpperInvariant()); - } - }); - - app.SeedData(); -} + app.UseSwaggerUI(); +} else { app.AddProductionExceptionHandling(loggerFactory); diff --git a/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj b/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj index 6eb2b7d..c755912 100644 --- a/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj +++ b/SampleWebApiAspNetCore/SampleWebApiAspNetCore.csproj @@ -1,20 +1,27 @@  - net7.0 + net6.0 enable enable - - - - + + + + + + + + + + + diff --git a/SampleWebApiAspNetCore/Repositories/FoodDbContext.cs b/SamplwWebApiAspNetCore.Data/FoodDbContext.cs similarity index 77% rename from SampleWebApiAspNetCore/Repositories/FoodDbContext.cs rename to SamplwWebApiAspNetCore.Data/FoodDbContext.cs index 86187b7..151914c 100644 --- a/SampleWebApiAspNetCore/Repositories/FoodDbContext.cs +++ b/SamplwWebApiAspNetCore.Data/FoodDbContext.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; -using SampleWebApiAspNetCore.Entities; +using SampleWebApiAspNetCore.Domain.Entities; -namespace SampleWebApiAspNetCore.Repositories +namespace SampleWebApiAspNetCore.Data { public class FoodDbContext : DbContext { diff --git a/SampleWebApiAspNetCore/Repositories/FoodSqlRepository.cs b/SamplwWebApiAspNetCore.Data/Repositories/Implementations/FoodSqlRepository.cs similarity index 52% rename from SampleWebApiAspNetCore/Repositories/FoodSqlRepository.cs rename to SamplwWebApiAspNetCore.Data/Repositories/Implementations/FoodSqlRepository.cs index 5ace322..4f8fd1f 100644 --- a/SampleWebApiAspNetCore/Repositories/FoodSqlRepository.cs +++ b/SamplwWebApiAspNetCore.Data/Repositories/Implementations/FoodSqlRepository.cs @@ -1,9 +1,13 @@ -using SampleWebApiAspNetCore.Entities; -using SampleWebApiAspNetCore.Helpers; -using SampleWebApiAspNetCore.Models; -using System.Linq.Dynamic.Core; +//using SampleWebApiAspNetCore.Data.Repositories.Interfaces; +//using SampleWebApiAspNetCore.Domain.Entities; +//using SampleWebApiAspNetCore.Domain.Models; -namespace SampleWebApiAspNetCore.Repositories +using SampleWebApiAspNetCore.Data.Repositories.Interfaces; +using SampleWebApiAspNetCore.Domain.Entities; +using SampleWebApiAspNetCore.Domain.Models; + + +namespace SampleWebApiAspNetCore.Data.Repositories.Implementations { public class FoodSqlRepository : IFoodRepository { @@ -36,16 +40,49 @@ public FoodEntity Update(int id, FoodEntity item) return item; } + //public IQueryable GetAll(QueryParameters queryParameters) + //{ + // IQueryable _allItems = _foodDbContext.FoodItems.OrderBy(queryParameters.OrderBy, + // queryParameters.IsDescending); + + // if (queryParameters.HasQuery) + // { + // _allItems = _allItems + // .Where(x => x.Calories.ToString().Contains(queryParameters.Query.ToLowerInvariant()) + // || x.Name.ToLowerInvariant().Contains(queryParameters.Query.ToLowerInvariant())); + // } + + // return _allItems + // .Skip(queryParameters.PageCount * (queryParameters.Page - 1)) + // .Take(queryParameters.PageCount); + //} + public IQueryable GetAll(QueryParameters queryParameters) { - IQueryable _allItems = _foodDbContext.FoodItems.OrderBy(queryParameters.OrderBy, - queryParameters.IsDescending()); + IQueryable _allItems = _foodDbContext.FoodItems; - if (queryParameters.HasQuery()) + if (queryParameters.HasQuery) { _allItems = _allItems .Where(x => x.Calories.ToString().Contains(queryParameters.Query.ToLowerInvariant()) - || x.Name.ToLowerInvariant().Contains(queryParameters.Query.ToLowerInvariant())); + || x.Name.ToLowerInvariant().Contains(queryParameters.Query.ToLowerInvariant())); + } + + // Apply sorting + switch (queryParameters.OrderBy) + { + case "Calories": + _allItems = queryParameters.IsDescending + ? _allItems.OrderByDescending(x => x.Calories) + : _allItems.OrderBy(x => x.Calories); + break; + + case "Name": + default: + _allItems = queryParameters.IsDescending + ? _allItems.OrderByDescending(x => x.Name) + : _allItems.OrderBy(x => x.Name); + break; } return _allItems @@ -53,6 +90,7 @@ public IQueryable GetAll(QueryParameters queryParameters) .Take(queryParameters.PageCount); } + public int Count() { return _foodDbContext.FoodItems.Count(); diff --git a/SampleWebApiAspNetCore/Repositories/IFoodRepository.cs b/SamplwWebApiAspNetCore.Data/Repositories/Interfaces/IFoodRepository.cs similarity index 57% rename from SampleWebApiAspNetCore/Repositories/IFoodRepository.cs rename to SamplwWebApiAspNetCore.Data/Repositories/Interfaces/IFoodRepository.cs index 26574b2..ddaa1e9 100644 --- a/SampleWebApiAspNetCore/Repositories/IFoodRepository.cs +++ b/SamplwWebApiAspNetCore.Data/Repositories/Interfaces/IFoodRepository.cs @@ -1,7 +1,12 @@ -using SampleWebApiAspNetCore.Entities; -using SampleWebApiAspNetCore.Models; +using SampleWebApiAspNetCore.Domain.Entities; +using SampleWebApiAspNetCore.Domain.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; -namespace SampleWebApiAspNetCore.Repositories +namespace SampleWebApiAspNetCore.Data.Repositories.Interfaces { public interface IFoodRepository { diff --git a/SamplwWebApiAspNetCore.Data/SampleWebApiAspNetCore.Data.csproj b/SamplwWebApiAspNetCore.Data/SampleWebApiAspNetCore.Data.csproj new file mode 100644 index 0000000..d41926b --- /dev/null +++ b/SamplwWebApiAspNetCore.Data/SampleWebApiAspNetCore.Data.csproj @@ -0,0 +1,21 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + +