A C# .NET Core API for managing library transactions. For a quick start, jump to [Getting Started](# Getting Started)
- Docker installed on your machine
- .NET Core 8+ installed on your machine
- Git installed on your machine
- Visual Studio Code installed on your machine
/CodeAssessmentAPI
│
├── /bin
├── /Controllers
│ ├── UserController.cs
│ └── ...
├── /Docker # SQL Container Setup
├── /Migrations
├── /Models
│ ├── User.cs
│ ├── UserContext.cs
│ └── ...
├── /Seeders
├── /Services
│ ├── UserService.cs
│ └── ...
├── /Repositories
├── /Properties
├── appsettings.json
├── appsettings.Development.json
├── Program.cs
├── MyWebAPI.csproj
├── MyWebAPI.sln
└── README.md
Run the following docker script to launch a container hosting SQL Server:
cd docker
bash build.sh
cd ..dotnet restoredotnet run --launch-profile https --project AppOnce the instance is live, start the app:
dotnet run --launch-profile httpsThe OpenAPI specs can now be found here
- Model (type defining)
- Controller (routing(req/res) & auth)
- Service (Handling)
dotnet add package PACKAGE_NAMEAdd a [MODEL_NAME].cs file to /Model holding object/type data:
namespace Models;
public class Model
{
public long Id { get; set; }
...
}To generate a controller template, run the following:
dotnet aspnet-codegenerator controller -name [MODEL_NAME]Controller -async -api -m [MODEL_NAME] -dc [MODEL_NAME]Context -outDir ControllersAdjust the controller as required for the instance.
Add [Authorization] above the route.
By default this will require the requested user to be logged in
Can also manage roles: [Authorization(roles = "Employee")]
Ensure .NET Entity Framework is installed
dotnet tool install --global dotnet-efAll should be run from the
/Appdirectory
Create a migration:
cd App
dotnet ef migrations add NewMigrationTitle -o Data/MigrationsRemove a migration:
dotnet ef migrations removeUpdate the database:
cd App
dotnet ef database updatedotnet formatdotnet testDownload Docker Download .NET 8+ .NET 8+ Web API .NET Migrations .NET Identity Prevent Over Posting Creating a Pipeline