Add resurrector methods in API

master
Tudor Stanciu 2022-01-13 10:50:51 +02:00
parent 3571a26262
commit ac631e5781
11 changed files with 114 additions and 6 deletions

View File

@ -66,6 +66,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Server.W
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Server.PublishedLanguage", "src\server\NetworkResurrector.Server.PublishedLanguage\NetworkResurrector.Server.PublishedLanguage.csproj", "{388D632D-8104-45E2-8017-D04848941F29}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Server.PublishedLanguage", "src\server\NetworkResurrector.Server.PublishedLanguage\NetworkResurrector.Server.PublishedLanguage.csproj", "{388D632D-8104-45E2-8017-D04848941F29}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NetworkResurrector.Api.PublishedLanguage", "src\api\NetworkResurrector.Api.PublishedLanguage\NetworkResurrector.Api.PublishedLanguage.csproj", "{1EA9EAD7-8896-4756-A2C2-7969E9073FA6}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -140,6 +142,10 @@ Global
{388D632D-8104-45E2-8017-D04848941F29}.Debug|Any CPU.Build.0 = Debug|Any CPU {388D632D-8104-45E2-8017-D04848941F29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{388D632D-8104-45E2-8017-D04848941F29}.Release|Any CPU.ActiveCfg = Release|Any CPU {388D632D-8104-45E2-8017-D04848941F29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{388D632D-8104-45E2-8017-D04848941F29}.Release|Any CPU.Build.0 = Release|Any CPU {388D632D-8104-45E2-8017-D04848941F29}.Release|Any CPU.Build.0 = Release|Any CPU
{1EA9EAD7-8896-4756-A2C2-7969E9073FA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1EA9EAD7-8896-4756-A2C2-7969E9073FA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1EA9EAD7-8896-4756-A2C2-7969E9073FA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1EA9EAD7-8896-4756-A2C2-7969E9073FA6}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -167,6 +173,7 @@ Global
{750531C0-CB4D-44AE-ADDE-CC815F2539C5} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302} {750531C0-CB4D-44AE-ADDE-CC815F2539C5} = {C04663A1-E0CD-41D6-A8D7-FADDF9DA8302}
{696DAC79-9C18-4DC3-9925-755AD6C1FEC9} = {6889D39C-D8DA-4B99-AFC1-F0B6355E73C0} {696DAC79-9C18-4DC3-9925-755AD6C1FEC9} = {6889D39C-D8DA-4B99-AFC1-F0B6355E73C0}
{388D632D-8104-45E2-8017-D04848941F29} = {6889D39C-D8DA-4B99-AFC1-F0B6355E73C0} {388D632D-8104-45E2-8017-D04848941F29} = {6889D39C-D8DA-4B99-AFC1-F0B6355E73C0}
{1EA9EAD7-8896-4756-A2C2-7969E9073FA6} = {43C78941-52E6-4AB8-9170-CC7C006E4784}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7} SolutionGuid = {351D76E9-FE02-4C30-A464-7B29AFC64BC7}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>net5.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -15,5 +15,6 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\NetworkResurrector.Api.Domain\NetworkResurrector.Api.Domain.csproj" /> <ProjectReference Include="..\NetworkResurrector.Api.Domain\NetworkResurrector.Api.Domain.csproj" />
<ProjectReference Include="..\NetworkResurrector.Api.PublishedLanguage\NetworkResurrector.Api.PublishedLanguage.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -0,0 +1,9 @@
using NDB.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands
{
public class PingMachine : Command<MachinePinged>
{
}
}

View File

@ -0,0 +1,9 @@
using NDB.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands
{
public class ShutdownMachine : Command<MachineShutdown>
{
}
}

View File

@ -0,0 +1,9 @@
using NDB.Application.DataContracts;
using NetworkResurrector.Api.PublishedLanguage.Events;
namespace NetworkResurrector.Api.PublishedLanguage.Commands
{
public class WakeMachine : Command<MachineWaked>
{
}
}

View File

@ -0,0 +1,8 @@
namespace NetworkResurrector.Api.PublishedLanguage.Events
{
public class MachinePinged
{
public bool Success { get; set; }
public string Status { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace NetworkResurrector.Api.PublishedLanguage.Events
{
public class MachineShutdown
{
public bool Success { get; set; }
public string Status { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace NetworkResurrector.Api.PublishedLanguage.Events
{
public class MachineWaked
{
public bool Success { get; set; }
public string Status { get; set; }
}
}

View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NDB.Application.DataContracts" Version="$(NDBApplicationPackageVersion)" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,42 @@
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetworkResurrector.Api.PublishedLanguage.Commands;
using System.Threading.Tasks;
namespace NetworkResurrector.Api.Controllers
{
[Authorize]
[ApiController]
[Route("resurrector")]
public class ResurrectorController : ControllerBase
{
private readonly IMediator _mediator;
public ResurrectorController(IMediator mediator)
{
_mediator = mediator;
}
[HttpPost("wake")]
public async Task<IActionResult> WakeMachine([FromBody] WakeMachine wakeMachine)
{
var result = await _mediator.Send(wakeMachine);
return Ok(result);
}
[HttpPost("ping")]
public async Task<IActionResult> PingMachine([FromBody] PingMachine pingMachine)
{
var result = await _mediator.Send(pingMachine);
return Ok(result);
}
[HttpPost("shutdown")]
public async Task<IActionResult> ShutdownMachine([FromBody] ShutdownMachine shutdownMachine)
{
var result = await _mediator.Send(shutdownMachine);
return Ok(result);
}
}
}

View File

@ -1,8 +1,4 @@
using System; namespace NetworkResurrector.Server.PublishedLanguage.Events
using System.Collections.Generic;
using System.Text;
namespace NetworkResurrector.Server.PublishedLanguage.Events
{ {
public class MachineShutdown public class MachineShutdown
{ {