diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..24df3ff --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,33 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/bin/Debug/net7.0/GerbilManager.dll", + "args": [], + "cwd": "${workspaceFolder}", + "stopAtEntry": false, + "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..5008f35 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,41 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/GerbilManager.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/GerbilManager.sln", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary;ForceNoAlign" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "--project", + "${workspaceFolder}/GerbilManager.sln" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/Controllers/GerbilsController.cs b/Controllers/GerbilsController.cs new file mode 100644 index 0000000..2417675 --- /dev/null +++ b/Controllers/GerbilsController.cs @@ -0,0 +1,26 @@ +using GerbilManager.Models; +using GerbilManager.Repositories; +using Microsoft.AspNetCore.Mvc; + +namespace GerbilManager.Controllers +{ + [ApiController] + [Route("gerbils")] + public class GerbilsController : ControllerBase + { + private readonly InMemGerbilRepository repository; + + public GerbilsController() + { + repository = new InMemGerbilRepository(); + } + + //GET /gerbils + [HttpGet] + public IEnumerable GetGerbils() + { + var items = repository.GetGerbils(); + return items; + } + } +} \ No newline at end of file diff --git a/GerbilManager.csproj b/GerbilManager.csproj new file mode 100644 index 0000000..7429eed --- /dev/null +++ b/GerbilManager.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + + diff --git a/GerbilManager.sln b/GerbilManager.sln new file mode 100644 index 0000000..d1bce9b --- /dev/null +++ b/GerbilManager.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.002.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GerbilManager", "GerbilManager.csproj", "{48875578-7112-4F6F-A4C0-F1E7637B513D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {48875578-7112-4F6F-A4C0-F1E7637B513D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48875578-7112-4F6F-A4C0-F1E7637B513D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48875578-7112-4F6F-A4C0-F1E7637B513D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48875578-7112-4F6F-A4C0-F1E7637B513D}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7F573F67-6F28-4056-8D14-0E04C8C54B7E} + EndGlobalSection +EndGlobal diff --git a/Models/Breeder.cs b/Models/Breeder.cs new file mode 100644 index 0000000..9a67a0e --- /dev/null +++ b/Models/Breeder.cs @@ -0,0 +1,8 @@ +namespace GerbilManager.Models +{ + public record Breeder + { + public Guid Id { get; init; } + public string Name { get; init; } + } +} \ No newline at end of file diff --git a/Models/Gender.cs b/Models/Gender.cs new file mode 100644 index 0000000..590ef4f --- /dev/null +++ b/Models/Gender.cs @@ -0,0 +1,9 @@ +namespace GerbilManager.Models +{ + public enum Gender + { + unknown, + male, + female + } +} \ No newline at end of file diff --git a/Models/Gerbil.cs b/Models/Gerbil.cs new file mode 100644 index 0000000..87c23d1 --- /dev/null +++ b/Models/Gerbil.cs @@ -0,0 +1,11 @@ +namespace GerbilManager.Models +{ + public record Gerbil + { + public Guid Id { get; init; } + public string Name { get; init; } + public Gender Gender { get; init; } + public Litter Litter { get; init; } + public Breeder Breeder { get; init; } + } +} \ No newline at end of file diff --git a/Models/Litter.cs b/Models/Litter.cs new file mode 100644 index 0000000..57c41e3 --- /dev/null +++ b/Models/Litter.cs @@ -0,0 +1,13 @@ +namespace GerbilManager.Models +{ + public record Litter + { + public Guid Id { get; init; } + public string Name { get; init; } + public DateTime Date { get; init; } + public int Strength { get; init; } + public Gerbil Father { get; init; } + public Gerbil Mother { get; init; } + } +} + diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..15eacee --- /dev/null +++ b/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..bc52a00 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:23762", + "sslPort": 44327 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5179", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7191;http://localhost:5179", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Repositories/InMemGerbilRepository.cs b/Repositories/InMemGerbilRepository.cs new file mode 100644 index 0000000..58bbaff --- /dev/null +++ b/Repositories/InMemGerbilRepository.cs @@ -0,0 +1,23 @@ +using GerbilManager.Models; + +namespace GerbilManager.Repositories +{ + + public class InMemGerbilRepository + { + private readonly List _gerbilList = new() + { + new Gerbil() {Id = Guid.NewGuid(), Name = "Blacky", Breeder = null, Litter = null, Gender = Gender.unknown}, + new Gerbil() {Id = Guid.NewGuid(), Name = "Coocky", Breeder = null, Litter = null, Gender = Gender.male}, + new Gerbil() {Id = Guid.NewGuid(), Name = "Lazy", Breeder = null, Litter = null, Gender = Gender.female} + }; + + public IEnumerable GetGerbils() + { + return _gerbilList; + } + + public Gerbil GetGerbil(Guid id) => _gerbilList.SingleOrDefault(x => x.Id == id); + } + +} diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..ff66ba6 --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..4d56694 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}