Skip to content

Commit

Permalink
#17 Trying to fix the api
Browse files Browse the repository at this point in the history
Something's not working in it if it's ran as part of the main program
  • Loading branch information
David032 committed Nov 27, 2023
1 parent 8c1dbed commit b247175
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 11 deletions.
9 changes: 8 additions & 1 deletion skullOS.API/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {}
"tools": {
"dotnet-ef": {
"version": "8.0.0",
"commands": [
"dotnet-ef"
]
}
}
}
3 changes: 2 additions & 1 deletion skullOS.API/Controllers/BuzzerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace skullOS.API.Controllers
{
[Route("api/[controller]")]
[Route("Buzzer")]
[ApiController]
public class BuzzerController : ControllerBase
{
Expand All @@ -17,6 +17,7 @@ public BuzzerController(ILogger<BuzzerController> logger, IBuzzerModule buzzer)
_module = buzzer;
}

[HttpGet("PlayTune")]
public string PlayTune(string tune)
{
Tunes tuneToPlay = (Tunes)Enum.Parse(typeof(Tunes), tune);
Expand Down
6 changes: 3 additions & 3 deletions skullOS.API/Controllers/CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace skullOS.API.Controllers
{
[Route("api/[controller]")]
[Route("Camera")]
[ApiController]
public class CameraController : ControllerBase
{
Expand All @@ -16,14 +16,14 @@ public CameraController(ILogger<CameraController> logger, ICameraModule camera)
_module = camera;
}

[HttpGet]
[HttpGet("TakePicture")]
public string TakePicture()
{
_module.TakePicture();
return "Picture Taken!";
}

[HttpGet]
[HttpGet("RecordVideo")]
public string RecordVideo()
{
_module.RecordShortVideo();
Expand Down
8 changes: 7 additions & 1 deletion skullOS.API/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using skullOS.Modules;
using skullOS.Modules.Interfaces;

namespace skullOS.API
{
Expand All @@ -15,6 +17,10 @@ public static void Main(string[] args)
builder.Services.AddSwaggerGen();
builder.WebHost.UseUrls("http://*:5000;https://*:5001");

#region Skull Modules
builder.Services.AddScoped<ICameraModule, Camera>();
builder.Services.AddScoped<IBuzzerModule, Buzzer>();
#endregion

var app = builder.Build();

Expand All @@ -35,7 +41,7 @@ public static void Main(string[] args)

app.MapControllers();

Task webAPIStatus = app.RunAsync();
app.Run();
}
}
}
82 changes: 81 additions & 1 deletion skullOS.API/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace skullOS.API
{
public class Runner
{
public Task StartWebAPI(string[] args)
public Task StartWebApiTask(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -44,5 +44,85 @@ public Task StartWebAPI(string[] args)

return app.RunAsync();
}
public void StartWebApiAsync(string[] args)
{
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();
builder.WebHost.UseUrls("http://*:5000;https://*:5001");

#region Skull Modules
//builder.Services.AddScoped<ICameraModule, Camera>();
//builder.Services.AddScoped<IBuzzerModule, Buzzer>();
#endregion


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
if (!app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}


app.UseAuthorization();


app.MapControllers();

app.RunAsync();
}

public void StartWebApi(string[] args)
{
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();
builder.WebHost.UseUrls("http://*:5000;https://*:5001");

#region Skull Modules
builder.Services.AddScoped<ICameraModule, Camera>();
builder.Services.AddScoped<IBuzzerModule, Buzzer>();
#endregion


var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
if (!app.Environment.IsDevelopment())
{
app.UseHttpsRedirection();
}


app.UseAuthorization();


app.MapControllers();

app.Run();
}

}
}
11 changes: 7 additions & 4 deletions skullOS/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using skullOS.Core;
using skullOS.API;
using skullOS.Core;
using System.Device.Gpio;
using System.Reflection;
using Module = skullOS.Modules.Module;
using Runner = skullOS.API.Runner;

namespace skullOS
{
Expand Down Expand Up @@ -65,9 +65,12 @@ static void Run(bool shouldCreateDirectory = true)
arguments[0] = "environment=development";
logger.LogMessage("Set first argument to " + arguments[0]);
#endif
//Replace this with something that calls the api seperatley

Runner apiRunner = new();
Task apiStatus = apiRunner.StartWebAPI(arguments);
deviceManager.AttachApi(apiStatus);
//Task apiStatus = apiRunner.StartWebApiTask(arguments);
//deviceManager.AttachApi(apiStatus);
apiRunner.StartWebApi(arguments);
logger.LogMessage("API enabled");
}
}
Expand Down

0 comments on commit b247175

Please sign in to comment.