Skip to content

devinobrien-css/code-assessment-api

Repository files navigation

Code Assessment API

A C# .NET Core API for managing library transactions. For a quick start, jump to [Getting Started](# Getting Started)

 

Prerequisites

 

Repository Overview

/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

 

Getting Started / Running the app

Launch an instance of SQL Server

Run the following docker script to launch a container hosting SQL Server:

cd docker
bash build.sh
cd ..

Restore installs

dotnet restore

Generate & Trust a Development Cert

dotnet run --launch-profile https --project App

Start the application

Once the instance is live, start the app:

dotnet run --launch-profile https

View the OpenAPI Specs

The OpenAPI specs can now be found here

 

Contributing

Logical Breakdown of Concepts

  • Model (type defining)
  • Controller (routing(req/res) & auth)
  • Service (Handling)

Adding a Package

dotnet add package PACKAGE_NAME

Creating a Model

Add a [MODEL_NAME].cs file to /Model holding object/type data:

namespace Models;

public class Model
{
    public long Id { get; set; }
    ...
}

Controller Development

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 Controllers

Adjust the controller as required for the instance.

Authenticating Endpoints

Add [Authorization] above the route.

By default this will require the requested user to be logged in

Can also manage roles: [Authorization(roles = "Employee")]

Migration Scripts

Ensure .NET Entity Framework is installed

dotnet tool install --global dotnet-ef

All should be run from the /App directory

Create a migration:

cd App
dotnet ef migrations add NewMigrationTitle -o Data/Migrations

Remove a migration:

dotnet ef migrations remove

Update the database:

cd App
dotnet ef database update

Code formatting:

dotnet format

Unit Testing:

dotnet test

Documentation

Download Docker Download .NET 8+ .NET 8+ Web API .NET Migrations .NET Identity Prevent Over Posting Creating a Pipeline

About

A C# .NET Core 8+ API for managing library transactions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages