diff --git a/Library.Encyclopedia/.gitignore b/Library.Encyclopedia.API/.gitignore
similarity index 100%
rename from Library.Encyclopedia/.gitignore
rename to Library.Encyclopedia.API/.gitignore
diff --git a/Library.Encyclopedia/ClientApp/.editorconfig b/Library.Encyclopedia.API/ClientApp/.editorconfig
similarity index 100%
rename from Library.Encyclopedia/ClientApp/.editorconfig
rename to Library.Encyclopedia.API/ClientApp/.editorconfig
diff --git a/Library.Encyclopedia/ClientApp/.gitignore b/Library.Encyclopedia.API/ClientApp/.gitignore
similarity index 100%
rename from Library.Encyclopedia/ClientApp/.gitignore
rename to Library.Encyclopedia.API/ClientApp/.gitignore
diff --git a/Library.Encyclopedia/ClientApp/README.md b/Library.Encyclopedia.API/ClientApp/README.md
similarity index 100%
rename from Library.Encyclopedia/ClientApp/README.md
rename to Library.Encyclopedia.API/ClientApp/README.md
diff --git a/Library.Encyclopedia/ClientApp/angular.json b/Library.Encyclopedia.API/ClientApp/angular.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/angular.json
rename to Library.Encyclopedia.API/ClientApp/angular.json
diff --git a/Library.Encyclopedia/ClientApp/browserslist b/Library.Encyclopedia.API/ClientApp/browserslist
similarity index 100%
rename from Library.Encyclopedia/ClientApp/browserslist
rename to Library.Encyclopedia.API/ClientApp/browserslist
diff --git a/Library.Encyclopedia/ClientApp/e2e/protractor.conf.js b/Library.Encyclopedia.API/ClientApp/e2e/protractor.conf.js
similarity index 100%
rename from Library.Encyclopedia/ClientApp/e2e/protractor.conf.js
rename to Library.Encyclopedia.API/ClientApp/e2e/protractor.conf.js
diff --git a/Library.Encyclopedia/ClientApp/e2e/src/app.e2e-spec.ts b/Library.Encyclopedia.API/ClientApp/e2e/src/app.e2e-spec.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/e2e/src/app.e2e-spec.ts
rename to Library.Encyclopedia.API/ClientApp/e2e/src/app.e2e-spec.ts
diff --git a/Library.Encyclopedia/ClientApp/e2e/src/app.po.ts b/Library.Encyclopedia.API/ClientApp/e2e/src/app.po.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/e2e/src/app.po.ts
rename to Library.Encyclopedia.API/ClientApp/e2e/src/app.po.ts
diff --git a/Library.Encyclopedia/ClientApp/e2e/tsconfig.e2e.json b/Library.Encyclopedia.API/ClientApp/e2e/tsconfig.e2e.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/e2e/tsconfig.e2e.json
rename to Library.Encyclopedia.API/ClientApp/e2e/tsconfig.e2e.json
diff --git a/Library.Encyclopedia/ClientApp/package-lock.json b/Library.Encyclopedia.API/ClientApp/package-lock.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/package-lock.json
rename to Library.Encyclopedia.API/ClientApp/package-lock.json
diff --git a/Library.Encyclopedia/ClientApp/package.json b/Library.Encyclopedia.API/ClientApp/package.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/package.json
rename to Library.Encyclopedia.API/ClientApp/package.json
diff --git a/Library.Encyclopedia/ClientApp/src/app/app.component.html b/Library.Encyclopedia.API/ClientApp/src/app/app.component.html
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/app.component.html
rename to Library.Encyclopedia.API/ClientApp/src/app/app.component.html
diff --git a/Library.Encyclopedia/ClientApp/src/app/app.component.ts b/Library.Encyclopedia.API/ClientApp/src/app/app.component.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/app.component.ts
rename to Library.Encyclopedia.API/ClientApp/src/app/app.component.ts
diff --git a/Library.Encyclopedia/ClientApp/src/app/app.module.ts b/Library.Encyclopedia.API/ClientApp/src/app/app.module.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/app.module.ts
rename to Library.Encyclopedia.API/ClientApp/src/app/app.module.ts
diff --git a/Library.Encyclopedia/ClientApp/src/app/app.server.module.ts b/Library.Encyclopedia.API/ClientApp/src/app/app.server.module.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/app.server.module.ts
rename to Library.Encyclopedia.API/ClientApp/src/app/app.server.module.ts
diff --git a/Library.Encyclopedia/ClientApp/src/app/counter/counter.component.html b/Library.Encyclopedia.API/ClientApp/src/app/counter/counter.component.html
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/counter/counter.component.html
rename to Library.Encyclopedia.API/ClientApp/src/app/counter/counter.component.html
diff --git a/Library.Encyclopedia/ClientApp/src/app/counter/counter.component.spec.ts b/Library.Encyclopedia.API/ClientApp/src/app/counter/counter.component.spec.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/counter/counter.component.spec.ts
rename to Library.Encyclopedia.API/ClientApp/src/app/counter/counter.component.spec.ts
diff --git a/Library.Encyclopedia/ClientApp/src/app/counter/counter.component.ts b/Library.Encyclopedia.API/ClientApp/src/app/counter/counter.component.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/counter/counter.component.ts
rename to Library.Encyclopedia.API/ClientApp/src/app/counter/counter.component.ts
diff --git a/Library.Encyclopedia/ClientApp/src/app/fetch-data/fetch-data.component.html b/Library.Encyclopedia.API/ClientApp/src/app/fetch-data/fetch-data.component.html
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/fetch-data/fetch-data.component.html
rename to Library.Encyclopedia.API/ClientApp/src/app/fetch-data/fetch-data.component.html
diff --git a/Library.Encyclopedia/ClientApp/src/app/fetch-data/fetch-data.component.ts b/Library.Encyclopedia.API/ClientApp/src/app/fetch-data/fetch-data.component.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/fetch-data/fetch-data.component.ts
rename to Library.Encyclopedia.API/ClientApp/src/app/fetch-data/fetch-data.component.ts
diff --git a/Library.Encyclopedia/ClientApp/src/app/home/home.component.html b/Library.Encyclopedia.API/ClientApp/src/app/home/home.component.html
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/home/home.component.html
rename to Library.Encyclopedia.API/ClientApp/src/app/home/home.component.html
diff --git a/Library.Encyclopedia/ClientApp/src/app/home/home.component.ts b/Library.Encyclopedia.API/ClientApp/src/app/home/home.component.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/home/home.component.ts
rename to Library.Encyclopedia.API/ClientApp/src/app/home/home.component.ts
diff --git a/Library.Encyclopedia/ClientApp/src/app/nav-menu/nav-menu.component.css b/Library.Encyclopedia.API/ClientApp/src/app/nav-menu/nav-menu.component.css
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/nav-menu/nav-menu.component.css
rename to Library.Encyclopedia.API/ClientApp/src/app/nav-menu/nav-menu.component.css
diff --git a/Library.Encyclopedia/ClientApp/src/app/nav-menu/nav-menu.component.html b/Library.Encyclopedia.API/ClientApp/src/app/nav-menu/nav-menu.component.html
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/nav-menu/nav-menu.component.html
rename to Library.Encyclopedia.API/ClientApp/src/app/nav-menu/nav-menu.component.html
diff --git a/Library.Encyclopedia/ClientApp/src/app/nav-menu/nav-menu.component.ts b/Library.Encyclopedia.API/ClientApp/src/app/nav-menu/nav-menu.component.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/app/nav-menu/nav-menu.component.ts
rename to Library.Encyclopedia.API/ClientApp/src/app/nav-menu/nav-menu.component.ts
diff --git a/Library.Encyclopedia/ClientApp/src/assets/.gitkeep b/Library.Encyclopedia.API/ClientApp/src/assets/.gitkeep
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/assets/.gitkeep
rename to Library.Encyclopedia.API/ClientApp/src/assets/.gitkeep
diff --git a/Library.Encyclopedia/ClientApp/src/environments/environment.prod.ts b/Library.Encyclopedia.API/ClientApp/src/environments/environment.prod.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/environments/environment.prod.ts
rename to Library.Encyclopedia.API/ClientApp/src/environments/environment.prod.ts
diff --git a/Library.Encyclopedia/ClientApp/src/environments/environment.ts b/Library.Encyclopedia.API/ClientApp/src/environments/environment.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/environments/environment.ts
rename to Library.Encyclopedia.API/ClientApp/src/environments/environment.ts
diff --git a/Library.Encyclopedia/ClientApp/src/index.html b/Library.Encyclopedia.API/ClientApp/src/index.html
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/index.html
rename to Library.Encyclopedia.API/ClientApp/src/index.html
diff --git a/Library.Encyclopedia/ClientApp/src/karma.conf.js b/Library.Encyclopedia.API/ClientApp/src/karma.conf.js
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/karma.conf.js
rename to Library.Encyclopedia.API/ClientApp/src/karma.conf.js
diff --git a/Library.Encyclopedia/ClientApp/src/main.ts b/Library.Encyclopedia.API/ClientApp/src/main.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/main.ts
rename to Library.Encyclopedia.API/ClientApp/src/main.ts
diff --git a/Library.Encyclopedia/ClientApp/src/polyfills.ts b/Library.Encyclopedia.API/ClientApp/src/polyfills.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/polyfills.ts
rename to Library.Encyclopedia.API/ClientApp/src/polyfills.ts
diff --git a/Library.Encyclopedia/ClientApp/src/styles.css b/Library.Encyclopedia.API/ClientApp/src/styles.css
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/styles.css
rename to Library.Encyclopedia.API/ClientApp/src/styles.css
diff --git a/Library.Encyclopedia/ClientApp/src/test.ts b/Library.Encyclopedia.API/ClientApp/src/test.ts
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/test.ts
rename to Library.Encyclopedia.API/ClientApp/src/test.ts
diff --git a/Library.Encyclopedia/ClientApp/src/tsconfig.app.json b/Library.Encyclopedia.API/ClientApp/src/tsconfig.app.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/tsconfig.app.json
rename to Library.Encyclopedia.API/ClientApp/src/tsconfig.app.json
diff --git a/Library.Encyclopedia/ClientApp/src/tsconfig.server.json b/Library.Encyclopedia.API/ClientApp/src/tsconfig.server.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/tsconfig.server.json
rename to Library.Encyclopedia.API/ClientApp/src/tsconfig.server.json
diff --git a/Library.Encyclopedia/ClientApp/src/tsconfig.spec.json b/Library.Encyclopedia.API/ClientApp/src/tsconfig.spec.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/tsconfig.spec.json
rename to Library.Encyclopedia.API/ClientApp/src/tsconfig.spec.json
diff --git a/Library.Encyclopedia/ClientApp/src/tslint.json b/Library.Encyclopedia.API/ClientApp/src/tslint.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/src/tslint.json
rename to Library.Encyclopedia.API/ClientApp/src/tslint.json
diff --git a/Library.Encyclopedia/ClientApp/tsconfig.json b/Library.Encyclopedia.API/ClientApp/tsconfig.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/tsconfig.json
rename to Library.Encyclopedia.API/ClientApp/tsconfig.json
diff --git a/Library.Encyclopedia/ClientApp/tslint.json b/Library.Encyclopedia.API/ClientApp/tslint.json
similarity index 100%
rename from Library.Encyclopedia/ClientApp/tslint.json
rename to Library.Encyclopedia.API/ClientApp/tslint.json
diff --git a/Library.Encyclopedia.API/Controllers/EncylopediaController.cs b/Library.Encyclopedia.API/Controllers/EncylopediaController.cs
new file mode 100644
index 0000000..13da0b8
--- /dev/null
+++ b/Library.Encyclopedia.API/Controllers/EncylopediaController.cs
@@ -0,0 +1,95 @@
+using Library.Encyclopedia.DataAccess;
+using Library.Encyclopedia.DataAccess.DataAccess;
+using Library.Encyclopedia.Entity.Interfaces;
+using Library.Encyclopedia.Entity.Models.External;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Logging;
+using System;
+using System.Collections.Generic;
+using System.Threading.Tasks;
+
+namespace Library.Encyclopedia.Controllers
+{
+ ///
+ /// CRUD operations on Main Table
+ ///
+ [ApiController]
+ [Route("[controller]")]
+ public class EncylopediaController : ControllerBase
+ {
+ private readonly ILogger _logger;
+ private readonly IMainDataAccess mainDataAccess;
+
+ ///
+ /// Constructor
+ ///
+ ///
+ ///
+ public EncylopediaController(ILogger logger, IApplicationDbContext dbContext)
+ {
+ _logger = logger;
+ this.mainDataAccess = new MainDataAccess(dbContext);
+ }
+
+ ///
+ /// Get all items based on search query
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ public async Task Get(string query,
+ int offset = 0,
+ int size = 10,
+ bool asc = true)
+ {
+ try
+ {
+ var response = await mainDataAccess.GetAsync(query, offset, size, asc);
+
+ if (response == null)
+ {
+ return StatusCode(204);
+ }
+ else
+ {
+ return Ok(response);
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, $"an error has occured {ex.Message}");
+ throw;
+ }
+ }
+
+ ///
+ /// Create new entry
+ ///
+ ///
+ [HttpPost]
+ public async Task Create()
+ {
+ try
+ {
+ var response = await mainDataAccess.CreateAsync(null);
+
+ if (response == null)
+ {
+ return StatusCode(204);
+ }
+ else
+ {
+ return Ok();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, $"an error has occured {ex.Message}");
+ throw;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Library.Encyclopedia/Controllers/WeatherForecastController.cs b/Library.Encyclopedia.API/Controllers/WeatherForecastController.cs
similarity index 100%
rename from Library.Encyclopedia/Controllers/WeatherForecastController.cs
rename to Library.Encyclopedia.API/Controllers/WeatherForecastController.cs
diff --git a/Library.Encyclopedia/Library.Encyclopedia.csproj b/Library.Encyclopedia.API/Library.Encyclopedia.API.csproj
similarity index 95%
rename from Library.Encyclopedia/Library.Encyclopedia.csproj
rename to Library.Encyclopedia.API/Library.Encyclopedia.API.csproj
index 3c46ced..10210cb 100644
--- a/Library.Encyclopedia/Library.Encyclopedia.csproj
+++ b/Library.Encyclopedia.API/Library.Encyclopedia.API.csproj
@@ -12,6 +12,10 @@
false
+
+
+
+
diff --git a/Library.Encyclopedia/Pages/Error.cshtml b/Library.Encyclopedia.API/Pages/Error.cshtml
similarity index 100%
rename from Library.Encyclopedia/Pages/Error.cshtml
rename to Library.Encyclopedia.API/Pages/Error.cshtml
diff --git a/Library.Encyclopedia/Pages/Error.cshtml.cs b/Library.Encyclopedia.API/Pages/Error.cshtml.cs
similarity index 100%
rename from Library.Encyclopedia/Pages/Error.cshtml.cs
rename to Library.Encyclopedia.API/Pages/Error.cshtml.cs
diff --git a/Library.Encyclopedia/Pages/_ViewImports.cshtml b/Library.Encyclopedia.API/Pages/_ViewImports.cshtml
similarity index 100%
rename from Library.Encyclopedia/Pages/_ViewImports.cshtml
rename to Library.Encyclopedia.API/Pages/_ViewImports.cshtml
diff --git a/Library.Encyclopedia/Program.cs b/Library.Encyclopedia.API/Program.cs
similarity index 100%
rename from Library.Encyclopedia/Program.cs
rename to Library.Encyclopedia.API/Program.cs
diff --git a/Library.Encyclopedia/Properties/launchSettings.json b/Library.Encyclopedia.API/Properties/launchSettings.json
similarity index 91%
rename from Library.Encyclopedia/Properties/launchSettings.json
rename to Library.Encyclopedia.API/Properties/launchSettings.json
index 6d1e37b..3535896 100644
--- a/Library.Encyclopedia/Properties/launchSettings.json
+++ b/Library.Encyclopedia.API/Properties/launchSettings.json
@@ -11,6 +11,7 @@
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
+ "launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
@@ -18,6 +19,7 @@
"Library.Encyclopedia": {
"commandName": "Project",
"launchBrowser": true,
+ "launchUrl": "swagger",
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
diff --git a/Library.Encyclopedia/Startup.cs b/Library.Encyclopedia.API/Startup.cs
similarity index 79%
rename from Library.Encyclopedia/Startup.cs
rename to Library.Encyclopedia.API/Startup.cs
index f648aab..b123ba6 100644
--- a/Library.Encyclopedia/Startup.cs
+++ b/Library.Encyclopedia.API/Startup.cs
@@ -1,11 +1,7 @@
using Library.Encyclopedia.DataAccess;
-using Library.Encyclopedia.DataAccess.DataAccess;
-using Library.Encyclopedia.Entity.Interfaces;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
-using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.SpaServices.AngularCli;
-using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@@ -31,12 +27,7 @@ public void ConfigureServices(IServiceCollection services)
configuration.RootPath = "ClientApp/dist";
});
- services.AddDbContext(options => options.UseSqlServer(
- Configuration.GetConnectionString("DefaultConnection"),
- ef => ef.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));
- services.AddScoped(provider => provider.GetService());
-
- services.AddTransient();
+ services.AddScoped();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
diff --git a/Library.Encyclopedia/WeatherForecast.cs b/Library.Encyclopedia.API/WeatherForecast.cs
similarity index 100%
rename from Library.Encyclopedia/WeatherForecast.cs
rename to Library.Encyclopedia.API/WeatherForecast.cs
diff --git a/Library.Encyclopedia/appsettings.Development.json b/Library.Encyclopedia.API/appsettings.Development.json
similarity index 100%
rename from Library.Encyclopedia/appsettings.Development.json
rename to Library.Encyclopedia.API/appsettings.Development.json
diff --git a/Library.Encyclopedia/appsettings.json b/Library.Encyclopedia.API/appsettings.json
similarity index 100%
rename from Library.Encyclopedia/appsettings.json
rename to Library.Encyclopedia.API/appsettings.json
diff --git a/Library.Encyclopedia/wwwroot/favicon.ico b/Library.Encyclopedia.API/wwwroot/favicon.ico
similarity index 100%
rename from Library.Encyclopedia/wwwroot/favicon.ico
rename to Library.Encyclopedia.API/wwwroot/favicon.ico
diff --git a/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs b/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs
index 63b991e..4a427ff 100644
--- a/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs
+++ b/Library.Encyclopedia.DataAccess/DataAccess/MainDataAccess.cs
@@ -1,7 +1,10 @@
using Library.Encyclopedia.Entity.Interfaces;
using Library.Encyclopedia.Entity.Models;
+using Library.Encyclopedia.Entity.Models.External;
+using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -9,29 +12,50 @@ namespace Library.Encyclopedia.DataAccess.DataAccess
{
public class MainDataAccess : IMainDataAccess
{
- public MainDataAccess()
+ private IApplicationDbContext _dbcontext;
+ public MainDataAccess(IApplicationDbContext dbcontext)
{
+ _dbcontext = dbcontext;
+ }
+
+
+ #region GET
+ async Task IMainDataAccess.GetAsync(string query, int offset, int pagesize, bool ascending)
+ {
+ var data = await _dbcontext.Main.Where(s => s.Description.Contains(query) || s.Title.Contains(query))
+ .Skip(offset)
+ .Take(pagesize)
+ .OrderBy(s => s.Title)
+ .ThenBy(s => s.Description)
+ .ToListAsync();
+
+ MainMinimizedExternalCollection result = new MainMinimizedExternalCollection(data, )
}
- Task> IMainDataAccess.Get(string query, int offset, int pagesize, bool ascending)
+ Task IMainDataAccess.GetAsync(string id)
{
throw new NotImplementedException();
}
- Task IMainDataAccess.Get(string id)
+ Task> IMainDataAccess.GetAsync(char startingAlphabet)
{
throw new NotImplementedException();
}
- Task> IMainDataAccess.Get(char startingAlphabet)
+ Task> IMainDataAccess.GetByCategoryAsync(string category, int offset, int pagesize, bool ascending)
{
throw new NotImplementedException();
}
+ #endregion
- Task> IMainDataAccess.GetByCategory(string category, int offset, int pagesize, bool ascending)
+ #region CREATE
+ public async Task CreateAsync(Main main)
{
- throw new NotImplementedException();
+ await _dbcontext.Main.AddAsync(main);
+ await _dbcontext.SaveChanges();
+ return main.Id;
}
+ #endregion
}
}
diff --git a/Library.Encyclopedia.DataAccess/Migrations/20211130180621_NewDatabase.Designer.cs b/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.Designer.cs
similarity index 68%
rename from Library.Encyclopedia.DataAccess/Migrations/20211130180621_NewDatabase.Designer.cs
rename to Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.Designer.cs
index 8cc1a41..51d3f77 100644
--- a/Library.Encyclopedia.DataAccess/Migrations/20211130180621_NewDatabase.Designer.cs
+++ b/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.Designer.cs
@@ -1,4 +1,5 @@
//
+using System;
using Library.Encyclopedia.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -9,8 +10,8 @@
namespace Library.Encyclopedia.DataAccess.Migrations
{
[DbContext(typeof(ApplicationDbContext))]
- [Migration("20211130180621_NewDatabase")]
- partial class NewDatabase
+ [Migration("20211130183310_Update_11302021")]
+ partial class Update_11302021
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@@ -22,23 +23,27 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Files", b =>
{
- b.Property("Id")
- .HasColumnType("nvarchar(450)");
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uniqueidentifier");
b.Property("FileDescription")
.HasColumnType("nvarchar(max)");
b.Property("FileName")
+ .IsRequired()
.HasColumnType("nvarchar(max)");
b.Property("FilePath")
+ .IsRequired()
.HasColumnType("nvarchar(max)");
b.Property("FileType")
+ .IsRequired()
.HasColumnType("nvarchar(max)");
- b.Property("MainId")
- .HasColumnType("nvarchar(450)");
+ b.Property("MainId")
+ .HasColumnType("uniqueidentifier");
b.HasKey("Id");
@@ -49,8 +54,9 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Links", b =>
{
- b.Property("Id")
- .HasColumnType("nvarchar(450)");
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uniqueidentifier");
b.Property("Description")
.HasColumnType("nvarchar(max)");
@@ -59,10 +65,11 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
.HasColumnType("bit");
b.Property("Link")
+ .IsRequired()
.HasColumnType("nvarchar(max)");
- b.Property("MainId")
- .HasColumnType("nvarchar(450)");
+ b.Property("MainId")
+ .HasColumnType("uniqueidentifier");
b.HasKey("Id");
@@ -73,17 +80,21 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Main", b =>
{
- b.Property("Id")
- .HasColumnType("nvarchar(450)");
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uniqueidentifier");
b.Property("Category")
- .HasColumnType("nvarchar(max)");
+ .HasMaxLength(256)
+ .HasColumnType("nvarchar(256)");
b.Property("Description")
.HasColumnType("nvarchar(max)");
b.Property("Title")
- .HasColumnType("nvarchar(max)");
+ .IsRequired()
+ .HasMaxLength(1024)
+ .HasColumnType("nvarchar(1024)");
b.HasKey("Id");
@@ -94,14 +105,18 @@ protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
b.HasOne("Library.Encyclopedia.Entity.Models.Main", null)
.WithMany("Files")
- .HasForeignKey("MainId");
+ .HasForeignKey("MainId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
});
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Links", b =>
{
b.HasOne("Library.Encyclopedia.Entity.Models.Main", null)
.WithMany("Links")
- .HasForeignKey("MainId");
+ .HasForeignKey("MainId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
});
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Main", b =>
diff --git a/Library.Encyclopedia.DataAccess/Migrations/20211130180621_NewDatabase.cs b/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.cs
similarity index 76%
rename from Library.Encyclopedia.DataAccess/Migrations/20211130180621_NewDatabase.cs
rename to Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.cs
index a21ea80..eb10574 100644
--- a/Library.Encyclopedia.DataAccess/Migrations/20211130180621_NewDatabase.cs
+++ b/Library.Encyclopedia.DataAccess/Migrations/20211130183310_Update_11302021.cs
@@ -1,8 +1,9 @@
-using Microsoft.EntityFrameworkCore.Migrations;
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
namespace Library.Encyclopedia.DataAccess.Migrations
{
- public partial class NewDatabase : Migration
+ public partial class Update_11302021 : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
@@ -10,10 +11,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "Main",
columns: table => new
{
- Id = table.Column(type: "nvarchar(450)", nullable: false),
- Title = table.Column(type: "nvarchar(max)", nullable: true),
+ Id = table.Column(type: "uniqueidentifier", nullable: false),
+ Title = table.Column(type: "nvarchar(1024)", maxLength: 1024, nullable: false),
Description = table.Column(type: "nvarchar(max)", nullable: true),
- Category = table.Column(type: "nvarchar(max)", nullable: true)
+ Category = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true)
},
constraints: table =>
{
@@ -24,12 +25,12 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "Files",
columns: table => new
{
- Id = table.Column(type: "nvarchar(450)", nullable: false),
- MainId = table.Column(type: "nvarchar(450)", nullable: true),
- FileName = table.Column(type: "nvarchar(max)", nullable: true),
- FileType = table.Column(type: "nvarchar(max)", nullable: true),
+ Id = table.Column(type: "uniqueidentifier", nullable: false),
+ MainId = table.Column(type: "uniqueidentifier", nullable: false),
+ FileName = table.Column(type: "nvarchar(max)", nullable: false),
+ FileType = table.Column(type: "nvarchar(max)", nullable: false),
FileDescription = table.Column(type: "nvarchar(max)", nullable: true),
- FilePath = table.Column(type: "nvarchar(max)", nullable: true)
+ FilePath = table.Column(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
@@ -39,16 +40,16 @@ protected override void Up(MigrationBuilder migrationBuilder)
column: x => x.MainId,
principalTable: "Main",
principalColumn: "Id",
- onDelete: ReferentialAction.Restrict);
+ onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Links",
columns: table => new
{
- Id = table.Column(type: "nvarchar(450)", nullable: false),
- MainId = table.Column(type: "nvarchar(450)", nullable: true),
- Link = table.Column(type: "nvarchar(max)", nullable: true),
+ Id = table.Column(type: "uniqueidentifier", nullable: false),
+ MainId = table.Column(type: "uniqueidentifier", nullable: false),
+ Link = table.Column(type: "nvarchar(max)", nullable: false),
Description = table.Column(type: "nvarchar(max)", nullable: true),
IsInternal = table.Column(type: "bit", nullable: false)
},
@@ -60,7 +61,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
column: x => x.MainId,
principalTable: "Main",
principalColumn: "Id",
- onDelete: ReferentialAction.Restrict);
+ onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
diff --git a/Library.Encyclopedia.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs b/Library.Encyclopedia.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs
index 614def6..236dc44 100644
--- a/Library.Encyclopedia.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs
+++ b/Library.Encyclopedia.DataAccess/Migrations/ApplicationDbContextModelSnapshot.cs
@@ -1,4 +1,5 @@
//
+using System;
using Library.Encyclopedia.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
@@ -20,23 +21,27 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Files", b =>
{
- b.Property("Id")
- .HasColumnType("nvarchar(450)");
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uniqueidentifier");
b.Property("FileDescription")
.HasColumnType("nvarchar(max)");
b.Property("FileName")
+ .IsRequired()
.HasColumnType("nvarchar(max)");
b.Property("FilePath")
+ .IsRequired()
.HasColumnType("nvarchar(max)");
b.Property("FileType")
+ .IsRequired()
.HasColumnType("nvarchar(max)");
- b.Property("MainId")
- .HasColumnType("nvarchar(450)");
+ b.Property("MainId")
+ .HasColumnType("uniqueidentifier");
b.HasKey("Id");
@@ -47,8 +52,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Links", b =>
{
- b.Property("Id")
- .HasColumnType("nvarchar(450)");
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uniqueidentifier");
b.Property("Description")
.HasColumnType("nvarchar(max)");
@@ -57,10 +63,11 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasColumnType("bit");
b.Property("Link")
+ .IsRequired()
.HasColumnType("nvarchar(max)");
- b.Property("MainId")
- .HasColumnType("nvarchar(450)");
+ b.Property("MainId")
+ .HasColumnType("uniqueidentifier");
b.HasKey("Id");
@@ -71,17 +78,21 @@ protected override void BuildModel(ModelBuilder modelBuilder)
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Main", b =>
{
- b.Property("Id")
- .HasColumnType("nvarchar(450)");
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uniqueidentifier");
b.Property("Category")
- .HasColumnType("nvarchar(max)");
+ .HasMaxLength(256)
+ .HasColumnType("nvarchar(256)");
b.Property("Description")
.HasColumnType("nvarchar(max)");
b.Property("Title")
- .HasColumnType("nvarchar(max)");
+ .IsRequired()
+ .HasMaxLength(1024)
+ .HasColumnType("nvarchar(1024)");
b.HasKey("Id");
@@ -92,14 +103,18 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
b.HasOne("Library.Encyclopedia.Entity.Models.Main", null)
.WithMany("Files")
- .HasForeignKey("MainId");
+ .HasForeignKey("MainId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
});
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Links", b =>
{
b.HasOne("Library.Encyclopedia.Entity.Models.Main", null)
.WithMany("Links")
- .HasForeignKey("MainId");
+ .HasForeignKey("MainId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
});
modelBuilder.Entity("Library.Encyclopedia.Entity.Models.Main", b =>
diff --git a/Library.Encyclopedia.Entity/Interfaces/IMainDataAccess.cs b/Library.Encyclopedia.Entity/Interfaces/IMainDataAccess.cs
index da3fcbd..49a95f7 100644
--- a/Library.Encyclopedia.Entity/Interfaces/IMainDataAccess.cs
+++ b/Library.Encyclopedia.Entity/Interfaces/IMainDataAccess.cs
@@ -1,4 +1,5 @@
using Library.Encyclopedia.Entity.Models;
+using System;
using System.Collections.Generic;
using System.Threading.Tasks;
@@ -6,9 +7,10 @@ namespace Library.Encyclopedia.Entity.Interfaces
{
public interface IMainDataAccess
{
- public Task> Get(string query, int offset, int pagesize, bool ascending);
- public Task> GetByCategory(string category, int offset, int pagesize, bool ascending);
- public Task Get(string id);
- public Task> Get(char startingAlphabet);
+ public Task> GetAsync(string query, int offset, int pagesize, bool ascending);
+ public Task> GetByCategoryAsync(string category, int offset, int pagesize, bool ascending);
+ public Task GetAsync(string id);
+ public Task> GetAsync(char startingAlphabet);
+ public Task CreateAsync(Main main);
}
}
\ No newline at end of file
diff --git a/Library.Encyclopedia.Entity/Models/External/MainMinimizedExternal.cs b/Library.Encyclopedia.Entity/Models/External/MainMinimizedExternal.cs
index f672eda..e4c2ba0 100644
--- a/Library.Encyclopedia.Entity/Models/External/MainMinimizedExternal.cs
+++ b/Library.Encyclopedia.Entity/Models/External/MainMinimizedExternal.cs
@@ -1,4 +1,7 @@
-namespace Library.Encyclopedia.Entity.Models.External
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Library.Encyclopedia.Entity.Models.External
{
public class MainMinimizedExternal
{
@@ -7,4 +10,13 @@ public class MainMinimizedExternal
public string Description { get; set; }
public string Category { get; set; }
}
+ public class MainMinimizedExternalCollection : QueryExternalModel
+ {
+ public MainMinimizedExternalCollection(IEnumerable collection, int total, int offset, int limit)
+ {
+ this.Result = collection;
+ this.Count = collection.Count();
+ this.Total
+ }
+ }
}
diff --git a/Library.Encyclopedia.Entity/Models/External/QueryExternalModel.cs b/Library.Encyclopedia.Entity/Models/External/QueryExternalModel.cs
new file mode 100644
index 0000000..acd7099
--- /dev/null
+++ b/Library.Encyclopedia.Entity/Models/External/QueryExternalModel.cs
@@ -0,0 +1,13 @@
+using System.Collections.Generic;
+
+namespace Library.Encyclopedia.Entity.Models.External
+{
+ public class QueryExternalModel
+ {
+ public IEnumerable Result { get; set; }
+ public int Count { get; set; }
+ public int Total { get; set; }
+ public int Offset { get; set; }
+ public int Limit { get; set; }
+ }
+}
\ No newline at end of file
diff --git a/Library.Encyclopedia.API.sln b/Library.Encyclopedia.sln
similarity index 74%
rename from Library.Encyclopedia.API.sln
rename to Library.Encyclopedia.sln
index ea30851..1644e84 100644
--- a/Library.Encyclopedia.API.sln
+++ b/Library.Encyclopedia.sln
@@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library.Encyclopedia", "Library.Encyclopedia\Library.Encyclopedia.csproj", "{9EB0F02C-FB4B-4AEB-9879-D9BB7B2C2081}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library.Encyclopedia.Entity", "Library.Encyclopedia.Entity\Library.Encyclopedia.Entity.csproj", "{00243580-2623-4E3C-8299-65C91E7CEC98}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library.Encyclopedia.Entity", "Library.Encyclopedia.Entity\Library.Encyclopedia.Entity.csproj", "{00243580-2623-4E3C-8299-65C91E7CEC98}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library.Encyclopedia.DataAccess", "Library.Encyclopedia.DataAccess\Library.Encyclopedia.DataAccess.csproj", "{759EFC47-D4A9-4214-87D2-DC2A4699D2D2}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Library.Encyclopedia.DataAccess", "Library.Encyclopedia.DataAccess\Library.Encyclopedia.DataAccess.csproj", "{759EFC47-D4A9-4214-87D2-DC2A4699D2D2}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Library.Encyclopedia.API", "Library.Encyclopedia.API\Library.Encyclopedia.API.csproj", "{0613D31C-65B7-4018-A30D-913D754DB8DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,10 +15,6 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {9EB0F02C-FB4B-4AEB-9879-D9BB7B2C2081}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {9EB0F02C-FB4B-4AEB-9879-D9BB7B2C2081}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {9EB0F02C-FB4B-4AEB-9879-D9BB7B2C2081}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {9EB0F02C-FB4B-4AEB-9879-D9BB7B2C2081}.Release|Any CPU.Build.0 = Release|Any CPU
{00243580-2623-4E3C-8299-65C91E7CEC98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{00243580-2623-4E3C-8299-65C91E7CEC98}.Debug|Any CPU.Build.0 = Debug|Any CPU
{00243580-2623-4E3C-8299-65C91E7CEC98}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -27,6 +23,10 @@ Global
{759EFC47-D4A9-4214-87D2-DC2A4699D2D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{759EFC47-D4A9-4214-87D2-DC2A4699D2D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{759EFC47-D4A9-4214-87D2-DC2A4699D2D2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0613D31C-65B7-4018-A30D-913D754DB8DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0613D31C-65B7-4018-A30D-913D754DB8DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0613D31C-65B7-4018-A30D-913D754DB8DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0613D31C-65B7-4018-A30D-913D754DB8DF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Library.Encyclopedia/Controllers/EncylopediaController.cs b/Library.Encyclopedia/Controllers/EncylopediaController.cs
deleted file mode 100644
index d91ca8d..0000000
--- a/Library.Encyclopedia/Controllers/EncylopediaController.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using Library.Encyclopedia.Entity.Interfaces;
-using Library.Encyclopedia.Entity.Models.External;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-
-namespace Library.Encyclopedia.Controllers
-{
- [ApiController]
- [Route("[controller]")]
- public class EncylopediaController : ControllerBase
- {
- private readonly ILogger _logger;
- private readonly IMainDataAccess mainDataAccess;
-
- public EncylopediaController(ILogger logger, IMainDataAccess mainDataAccess)
- {
- _logger = logger;
- this.mainDataAccess = mainDataAccess;
- }
-
- [HttpGet]
- public async Task Get(string query,
- int offset = 0,
- int size = 10,
- bool asc = true)
- {
- try
- {
- var response = await mainDataAccess.Get(query, offset, size, asc);
-
- if (response == null)
- {
- return StatusCode(204);
- }
- else
- {
- return Ok();
- }
- }
- catch (Exception ex)
- {
- _logger.LogError(ex, $"an error has occured {ex.Message}");
- throw;
- }
- }
- }
-}
\ No newline at end of file