From 1a9fd04f261585048c00fe956d00e3bcd847b369 Mon Sep 17 00:00:00 2001 From: Charles Showalter Date: Mon, 9 May 2022 14:41:15 -0700 Subject: [PATCH] Initial commit --- .gitignore | 4 ++ .vscode/launch.json | 35 ++++++++++++ .vscode/tasks.json | 41 ++++++++++++++ API/API.csproj | 22 ++++++++ API/Controllers/ProductsController.cs | 32 +++++++++++ API/Controllers/WeatherForecastController.cs | 32 +++++++++++ API/Program.cs | 17 ++++++ API/Properties/launchSettings.json | 31 +++++++++++ API/Startup.cs | 50 ++++++++++++++++++ API/WeatherForecast.cs | 14 +++++ API/appsettings.Development.json | 11 ++++ API/ecommerce.db | Bin 0 -> 20480 bytes API/ecommerce.db-shm | Bin 0 -> 32768 bytes API/ecommerce.db-wal | Bin 0 -> 8272 bytes Core/Core.csproj | 8 +++ Core/Entities/Product.cs | 8 +++ E-Commerce.sln | 34 ++++++++++++ .../20220509191604_InitialCreate.Designer.cs | 37 +++++++++++++ .../20220509191604_InitialCreate.cs | 31 +++++++++++ .../Migrations/StoreContextModelSnapshot.cs | 35 ++++++++++++ Infrastucture/Data/StoreContext.cs | 13 +++++ Infrastucture/Infrastucture.csproj | 16 ++++++ LICENSE | 9 ++++ README.md | 3 ++ 24 files changed, 483 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 API/API.csproj create mode 100644 API/Controllers/ProductsController.cs create mode 100644 API/Controllers/WeatherForecastController.cs create mode 100644 API/Program.cs create mode 100644 API/Properties/launchSettings.json create mode 100644 API/Startup.cs create mode 100644 API/WeatherForecast.cs create mode 100644 API/appsettings.Development.json create mode 100644 API/ecommerce.db create mode 100644 API/ecommerce.db-shm create mode 100644 API/ecommerce.db-wal create mode 100644 Core/Core.csproj create mode 100644 Core/Entities/Product.cs create mode 100644 E-Commerce.sln create mode 100644 Infrastucture/Data/Migrations/20220509191604_InitialCreate.Designer.cs create mode 100644 Infrastucture/Data/Migrations/20220509191604_InitialCreate.cs create mode 100644 Infrastucture/Data/Migrations/StoreContextModelSnapshot.cs create mode 100644 Infrastucture/Data/StoreContext.cs create mode 100644 Infrastucture/Infrastucture.csproj create mode 100644 LICENSE create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..454729b --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +obj +bin +appsettings.json +*.db \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..42a7cbc --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,35 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/API/bin/Debug/net6.0/API.dll", + "args": [], + "cwd": "${workspaceFolder}/API", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..d1eb122 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/API/API.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/API/API.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/API/API.csproj" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/API/API.csproj b/API/API.csproj new file mode 100644 index 0000000..9c4628b --- /dev/null +++ b/API/API.csproj @@ -0,0 +1,22 @@ + + + + net6.0 + enable + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + diff --git a/API/Controllers/ProductsController.cs b/API/Controllers/ProductsController.cs new file mode 100644 index 0000000..f01f3e2 --- /dev/null +++ b/API/Controllers/ProductsController.cs @@ -0,0 +1,32 @@ +using Infrastucture.Data; +using Core.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace API.Controllers +{ + [ApiController] + [Route("api/[controller]")] + public class ProductsController : ControllerBase + { + private readonly StoreContext _context; + public ProductsController(StoreContext context) + { + _context = context; + } + + [HttpGet] + public async Task>> GetProducts() + { + var products = await _context.Products.ToListAsync(); + + return Ok(products); + } + + [HttpGet("{id}")] + public async Task> GetProduct(int id) + { + return await _context.Products.FindAsync(id); + } + } +} \ No newline at end of file diff --git a/API/Controllers/WeatherForecastController.cs b/API/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..b879c25 --- /dev/null +++ b/API/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace API.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/API/Program.cs b/API/Program.cs new file mode 100644 index 0000000..f606381 --- /dev/null +++ b/API/Program.cs @@ -0,0 +1,17 @@ +namespace API +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/API/Properties/launchSettings.json b/API/Properties/launchSettings.json new file mode 100644 index 0000000..dec3d93 --- /dev/null +++ b/API/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:45380", + "sslPort": 44391 + } + }, + "profiles": { + "API": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/API/Startup.cs b/API/Startup.cs new file mode 100644 index 0000000..d3b6a29 --- /dev/null +++ b/API/Startup.cs @@ -0,0 +1,50 @@ +using Infrastucture.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.OpenApi.Models; + +namespace API +{ + public class Startup + { + private readonly IConfiguration _config; + public Startup(IConfiguration config) + { + _config = config; + } + + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + services.AddDbContext(x => x.UseSqlite(_config.GetConnectionString("DefaultConnection"))); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "WebAPIv5", Version = "v1" }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebAPIv5 v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/API/WeatherForecast.cs b/API/WeatherForecast.cs new file mode 100644 index 0000000..8cd5ab0 --- /dev/null +++ b/API/WeatherForecast.cs @@ -0,0 +1,14 @@ +using System; + +namespace API; + +public class WeatherForecast +{ + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } +} diff --git a/API/appsettings.Development.json b/API/appsettings.Development.json new file mode 100644 index 0000000..cf133aa --- /dev/null +++ b/API/appsettings.Development.json @@ -0,0 +1,11 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "ConnectionStrings": { + "DefaultConnection": "Data source=ecommerce.db" + } +} diff --git a/API/ecommerce.db b/API/ecommerce.db new file mode 100644 index 0000000000000000000000000000000000000000..f47dc3838c1abbe400c80f5b309679f445882644 GIT binary patch literal 20480 zcmeI&F;Ck-6bJA-CqNs?xSJ>F$?5b^nKM{3ccXhOAy0KUW*7gMa`8AOHafKmY;|fB*y_0D=E4 z(5o(+TU)d*<1a%|oDJ2xUQ~#)kw{NwhfD2%J0WMG^RC0$%&{A3d@8opnVT2ul@)Vs zjb0j)oV`37j80@x?yC>7Smm_EHuM@(VYvf~xn9WM^MHAN$h@OYhqZn0Fbo_u&#c}- zbaz%SaJx>>X9v8`oTJcpJ(a)9y>NS)&Qt5MSjdlWGwHR>i(|TCwp#SkpDZwn_$SnUpcT#(}^ts2})$upyxS-qXFQ{fgqI;#4#Z2q|B=SNnb|$SV&DEC8 z&n-%lbRf>BcPJjoY%-4KUMFhIovx?{?b-NY(^aF!HBlP^0uX=z1Rwwb2tWV=5P$## zAOL|!C-90^xY@LuP5X_#*Vt?9+B=b(CNhbK?OeoC?AGo2PEFNCjbB7<2nav`0uX=z z1Rwwb2tWV=5P$##9;v{~3V;5uj{xJ}|J9%V5fFd?1Rwwb2tWV=5P$##AOHafJYfO6 e|3BfIi_#zf0SG_<0uX=z1Rwwb2tWV=Q-MDwdduYi literal 0 HcmV?d00001 diff --git a/API/ecommerce.db-shm b/API/ecommerce.db-shm new file mode 100644 index 0000000000000000000000000000000000000000..09e3ea49c5f14c160c9199f2c9f7a89b1388766b GIT binary patch literal 32768 zcmeI)!3n}Z5Cu?O;@xAKu!!{FNzg)4h+T*U1Oh2QD-Z-PiXC_|J1XMUqvm}WW?7b5 zcm+&(nvEjkXH8S?lU%p$;ks_B`h476mWw9sQrGV1tGfL1eIE5l%)Ni)b^UHdKE=O6 zfB*pk1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0t5&U zAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK;Rz*V&9h#7^XmMqZ0xI2oNAZfB*pk x1PBlyK!5-N0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!Ct+2=u28E2RJc literal 0 HcmV?d00001 diff --git a/API/ecommerce.db-wal b/API/ecommerce.db-wal new file mode 100644 index 0000000000000000000000000000000000000000..583b3a8158461cb236d4bc569de7d78bc3bc66ed GIT binary patch literal 8272 zcmXr7XKP~6eI&uaAiw|u&+o5&5gWCeY44OrzbY(5{s4toki{=buUW;rwt$@%D9Frz zj)DIJ{{tX33PwX + + + net6.0 + enable + + + diff --git a/Core/Entities/Product.cs b/Core/Entities/Product.cs new file mode 100644 index 0000000..c34544a --- /dev/null +++ b/Core/Entities/Product.cs @@ -0,0 +1,8 @@ +namespace Core.Entities +{ + public class Product + { + public int Id { get; set; } + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/E-Commerce.sln b/E-Commerce.sln new file mode 100644 index 0000000..7828964 --- /dev/null +++ b/E-Commerce.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "API", "API\API.csproj", "{B50BBAB5-56F7-46B3-B2B0-FE4831B956CD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "Core\Core.csproj", "{124DD725-C323-44B3-B490-0D3613FE6AFB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastucture", "Infrastucture\Infrastucture.csproj", "{D2AA653B-A7B8-4365-9D72-213F87B67175}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B50BBAB5-56F7-46B3-B2B0-FE4831B956CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B50BBAB5-56F7-46B3-B2B0-FE4831B956CD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B50BBAB5-56F7-46B3-B2B0-FE4831B956CD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B50BBAB5-56F7-46B3-B2B0-FE4831B956CD}.Release|Any CPU.Build.0 = Release|Any CPU + {124DD725-C323-44B3-B490-0D3613FE6AFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {124DD725-C323-44B3-B490-0D3613FE6AFB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {124DD725-C323-44B3-B490-0D3613FE6AFB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {124DD725-C323-44B3-B490-0D3613FE6AFB}.Release|Any CPU.Build.0 = Release|Any CPU + {D2AA653B-A7B8-4365-9D72-213F87B67175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D2AA653B-A7B8-4365-9D72-213F87B67175}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D2AA653B-A7B8-4365-9D72-213F87B67175}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D2AA653B-A7B8-4365-9D72-213F87B67175}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Infrastucture/Data/Migrations/20220509191604_InitialCreate.Designer.cs b/Infrastucture/Data/Migrations/20220509191604_InitialCreate.Designer.cs new file mode 100644 index 0000000..e7dfbb0 --- /dev/null +++ b/Infrastucture/Data/Migrations/20220509191604_InitialCreate.Designer.cs @@ -0,0 +1,37 @@ +// +using API.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace Infrastucture.Data.Migrations +{ + [DbContext(typeof(StoreContext))] + [Migration("20220509191604_InitialCreate")] + partial class InitialCreate + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.4"); + + modelBuilder.Entity("API.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastucture/Data/Migrations/20220509191604_InitialCreate.cs b/Infrastucture/Data/Migrations/20220509191604_InitialCreate.cs new file mode 100644 index 0000000..44f3174 --- /dev/null +++ b/Infrastucture/Data/Migrations/20220509191604_InitialCreate.cs @@ -0,0 +1,31 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Infrastucture.Data.Migrations +{ + public partial class InitialCreate : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Products", + columns: table => new + { + Id = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Name = table.Column(type: "TEXT", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Products", x => x.Id); + }); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Products"); + } + } +} diff --git a/Infrastucture/Data/Migrations/StoreContextModelSnapshot.cs b/Infrastucture/Data/Migrations/StoreContextModelSnapshot.cs new file mode 100644 index 0000000..65f2453 --- /dev/null +++ b/Infrastucture/Data/Migrations/StoreContextModelSnapshot.cs @@ -0,0 +1,35 @@ +// +using Infrastucture.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace API.Data.Migrations +{ + [DbContext(typeof(StoreContext))] + partial class StoreContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder.HasAnnotation("ProductVersion", "6.0.4"); + + modelBuilder.Entity("API.Entities.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Infrastucture/Data/StoreContext.cs b/Infrastucture/Data/StoreContext.cs new file mode 100644 index 0000000..55af113 --- /dev/null +++ b/Infrastucture/Data/StoreContext.cs @@ -0,0 +1,13 @@ +using Core.Entities; +using Microsoft.EntityFrameworkCore; + +namespace Infrastucture.Data +{ + public class StoreContext : DbContext + { + public StoreContext(DbContextOptions options) : base(options) + { + } + public DbSet Products { get; set; } + } +} \ No newline at end of file diff --git a/Infrastucture/Infrastucture.csproj b/Infrastucture/Infrastucture.csproj new file mode 100644 index 0000000..269da8a --- /dev/null +++ b/Infrastucture/Infrastucture.csproj @@ -0,0 +1,16 @@ + + + + + + + + + + + + net6.0 + enable + + + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2071b23 --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..c92c4df --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# E-Commerce + +Built upon .NET, Angular, and Bootstrap \ No newline at end of file