This application is a Calculator service injected into our API
An Entity Relationship Diagram shows our database structure. Generated using app.diagrams.net. This is a simple one that shows the Entities and the links between them.
Main, OneToMany, ManyToMany, Repository, Validation increase in complexity.
List branches: git branch
Change branch: git checkout <<branchname>>
- Remove or rename the appsettings.Example.json so that you have an appsettings.json, appsettings.Development.json file in the root of the workshop.wwwapi project which contains your NEON credentials:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnectionString": "Host=URL; Database=neondb; Username=neondb_owner; Password=PASSWORD;"
}
}
- Note the .gitignore file in the root of the project which prevents the build directories being uploaded:
*/**/bin/Debug
*/**/bin/Release
*/**/obj/Debug
*/**/obj/Release
/workshop.wwwapi/appsettings.json
/workshop.wwwapi/appsettings.Development.json
You'll need all of these which have already been installed in this project:
Install-Package Scalar.AspNetCore
provides a /scalar endpointInstall-Package Swashbuckle.AspNetCore
provides a /swagger endpointInstall-Package Microsoft.EntityFrameworkCore
Install-Package Microsoft.EntityFrameworkCore.Tools
Install-Package Microsoft.EntityFrameworkCore.Design
Install-Package NpgSql.EntityFrameworkCore.PostgreSql
builder.Services.AddDbContext<DataContext>(options => {
options.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnectionString"));
options.LogTo(message => Debug.WriteLine(message));
});
In the Package Manager Console you can run:
add-migration First
to create a migrationupdate-database
to apply to a db
So this isn't ideal at the moment. I'm creating a Repository Layer for every Entity in my Database.
The join between the Person and Subjects is done via the PersonSubjects table. Note as I haven't written and endpoint for this, I used sql to insert some records:
INSERT INTO "Subjects" ("Name") VALUES
('Mathematics'),
('Nautical Studies'),
('Science'),
('Spanish'),
('German'),
('French'),
('Dutch'),
('Norwegian');
INSERT INTO "PersonSubjects" ("PersonId", "SubjectId", "CreationDate") VALUES (1, 3, CURRENT_TIMESTAMP);
INSERT INTO "PersonSubjects" ("PersonId", "SubjectId", "CreationDate") VALUES (1, 1, CURRENT_TIMESTAMP);
INSERT INTO "PersonSubjects" ("PersonId", "SubjectId", "CreationDate") VALUES (1, 6, CURRENT_TIMESTAMP);
INSERT INTO "PersonSubjects" ("PersonId", "SubjectId", "CreationDate") VALUES (1, 7, CURRENT_TIMESTAMP);
Install-Package FluentValidation
Install-Package FluentValidation.DependencyInjectionExtensions