mirror of
https://github.com/farcasclaudiu/MartianRobots.git
synced 2026-06-22 07:01:15 +03:00
Add project files.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using MartianRobots.Api.Data;
|
||||
using MartianRobotsSolver;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MartianRobots.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class MartianRobotsController : ControllerBase
|
||||
{
|
||||
private readonly ILogger<MartianRobotsController> logger;
|
||||
private readonly IRobotSolutionStorage storage;
|
||||
|
||||
public MartianRobotsController(ILogger<MartianRobotsController> logger, IRobotSolutionStorage storage)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.storage = storage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Solves Martian Robots
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <example>"5 3\n1 1 E\nRFRFRFRF\n3 2 N\nFRRFLLFFRRFLL\n0 3 W\nLLFFFRFLFL"</example>
|
||||
/// <returns></returns>
|
||||
[HttpPost("Solves Martian Robots")]
|
||||
[Route("Solve")]
|
||||
public IActionResult Solve([FromBody] string input)
|
||||
{
|
||||
var result = new MarsSolver().Process(input);
|
||||
storage.Add(result);
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
[HttpGet("Get the list of solutions")]
|
||||
[Route("List")]
|
||||
public IActionResult GetLastSolved()
|
||||
{
|
||||
return Ok(storage.List());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
using MartianRobotsSolver;
|
||||
|
||||
namespace MartianRobots.Api.Data
|
||||
{
|
||||
public interface IRobotSolutionStorage
|
||||
{
|
||||
void Add(RobotSolution solution);
|
||||
List<RobotSolution> List();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using MartianRobotsSolver;
|
||||
|
||||
namespace MartianRobots.Api.Data
|
||||
{
|
||||
public class RobotSolutionStorage : IRobotSolutionStorage
|
||||
{
|
||||
private List<RobotSolution> solutions = new List<RobotSolution>
|
||||
{
|
||||
new RobotSolution{ Input = "5 3\n1 1 E\nRFRFRFRF\n3 2 N\nFRRFLLFFRRFLL\n0 3 W\nLLFFFRFLFL" }
|
||||
};
|
||||
|
||||
public void Add(RobotSolution solution)
|
||||
{
|
||||
this.solutions.Add(solution);
|
||||
}
|
||||
|
||||
public List<RobotSolution> List()
|
||||
{
|
||||
return solutions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||
WORKDIR /src
|
||||
COPY ["MartianRobots.Api/MartianRobots.Api.csproj", "MartianRobots.Api/"]
|
||||
RUN dotnet restore "MartianRobots.Api/MartianRobots.Api.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/MartianRobots.Api"
|
||||
RUN dotnet build "MartianRobots.Api.csproj" -c Release -o /app/build
|
||||
|
||||
FROM build AS publish
|
||||
RUN dotnet publish "MartianRobots.Api.csproj" -c Release -o /app/publish /p:UseAppHost=false
|
||||
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "MartianRobots.Api.dll"]
|
||||
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MartianRobotsSolver\MartianRobotsSolver.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,27 @@
|
||||
using MartianRobots.Api.Data;
|
||||
|
||||
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();
|
||||
//storage
|
||||
builder.Services.AddSingleton<IRobotSolutionStorage, RobotSolutionStorage>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
}
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"profiles": {
|
||||
"MartianRobots.Api": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
"dotnetRunMessages": true,
|
||||
"applicationUrl": "http://localhost:5265"
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"Docker": {
|
||||
"commandName": "Docker",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
|
||||
"publishAllPorts": true
|
||||
}
|
||||
},
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:58013",
|
||||
"sslPort": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user