Skip to content

Commit

Permalink
DEV-65 Add main services (#66)
Browse files Browse the repository at this point in the history
* #65 Add  backend services

* #65 Add worker services
  • Loading branch information
harvestcore authored Jun 17, 2022
1 parent 2e14910 commit 2b6e5d7
Show file tree
Hide file tree
Showing 11 changed files with 416 additions and 67 deletions.
58 changes: 33 additions & 25 deletions backend/src/Matroos.Backend/Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
WebApplicationBuilder 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();

WebApplication app = builder.Build();

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

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
using Matroos.Backend.Services;
using Matroos.Backend.Services.Interfaces;

WebApplicationBuilder 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();

// Services
builder.Services.AddSingleton<IBotsService, BotsService>();
builder.Services.AddSingleton<IUserCommandsService, UserCommandsService>();
builder.Services.AddSingleton<IWorkersService, WorkersService>();

WebApplication app = builder.Build();

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

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
37 changes: 37 additions & 0 deletions backend/src/Matroos.Backend/Services/BotsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Matroos.Resources.Classes.Bots;

namespace Matroos.Backend.Services.Interfaces;

public class BotsService : IBotsService
{
/// <summary>
/// The bots.
/// </summary>
public List<Bot> Bots { get; }

/// <summary>
/// Default constructor.
/// </summary>
public BotsService()
{
Bots = new List<Bot>();
}

/// <inheritdoc />
public bool AddBot(Bot bot)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public bool DeleteBot(Guid botId)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public bool UpdateBot(Bot bot)
{
throw new NotImplementedException();
}
}
27 changes: 27 additions & 0 deletions backend/src/Matroos.Backend/Services/Interfaces/IBotsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Matroos.Resources.Classes.Bots;

namespace Matroos.Backend.Services;

public interface IBotsService
{
/// <summary>
/// Add a new bot.
/// </summary>
/// <param name="bot">The bot.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool AddBot(Bot bot);

/// <summary>
/// Update the data of a bot.
/// </summary>
/// <param name="bot">The bot with the updated data.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool UpdateBot(Bot bot);

/// <summary>
/// Delete a bot.
/// </summary>
/// <param name="botId">The identifier of the bot to be removed.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool DeleteBot(Guid botId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Matroos.Resources.Classes.Commands;

namespace Matroos.Backend.Services;

public interface IUserCommandsService
{
/// <summary>
/// Add a new user command.
/// </summary>
/// <param name="userCommand">The user command to be added.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool AddUserCommand(UserCommand userCommand);

/// <summary>
/// Update the data of a command.
/// </summary>
/// <param name="userCommand">The user command with the updated data.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool UpdateUserCommand(UserCommand userCommand);

/// <summary>
/// Delete a command.
/// </summary>
/// <param name="userCommandId">The identifier of the user command to be removed.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool DeleteUserCommand(Guid userCommandId);
}
53 changes: 53 additions & 0 deletions backend/src/Matroos.Backend/Services/Interfaces/IWorkersService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Matroos.Resources.Classes.Bots;

namespace Matroos.Backend.Services;

public interface IWorkersService
{
/// <summary>
/// Starts a bot in a worker.
/// </summary>
/// <param name="workerId">The identifier of the worker where to start the bot.</param>
/// <param name="botId">The identifier of the bot to be started.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool StartBotInWorker(Guid workerId, Guid botId);

/// <summary>
/// Stops a bot in a worker.
/// </summary>
/// <param name="workerId">The identifier of the worker where to stop the bot.</param>
/// <param name="botId">The identifier of the bot to be stop.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool StopBotInWorker(Guid workerId, Guid botId);

/// <summary>
/// Gets all the bots from a worker.
/// </summary>
/// <param name="workerId">The identifier of the worker where to get the bots.</param>
/// <returns>Whether the operation was successful or not.</returns>
public Task<List<Bot>> GetBotsFromWorker(Guid workerId);

/// <summary>
/// Adds bots to a worker.
/// </summary>
/// <param name="workerId">The identifier of the worker where to add the bots.</param>
/// <param name="botIds">A list containing the identifiers of the bots to be added.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool AddBotsToWorker(Guid workerId, List<Guid> botIds);

/// <summary>
/// Updates the data of the given bots in a worker.
/// </summary>
/// <param name="workerId">The identifier of the worker where to update the data.</param>
/// <param name="botIds">A list containing the identifiers of the bots to be updated.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool UpdateBotsInWorker(Guid workerId, List<Guid> botIds);

/// <summary>
/// Deletes bots from a worker.
/// </summary>
/// <param name="workerId">The identifier of the worker where to delete the bots.</param>
/// <param name="botIds">A list containing the identifiers of the bots to be removed.</param>
/// <returns>Whether the operation was successful or not.</returns>
public bool DeleteBotsFromWorker(Guid workerId, List<Guid> botIds);
}
37 changes: 37 additions & 0 deletions backend/src/Matroos.Backend/Services/UserCommandsService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Matroos.Resources.Classes.Commands;

namespace Matroos.Backend.Services.Interfaces;

public class UserCommandsService : IUserCommandsService
{
/// <summary>
/// The user commands.
/// </summary>
public List<UserCommand> UserCommands { get; }

/// <summary>
/// Default constructor.
/// </summary>
public UserCommandsService()
{
UserCommands = new();
}

/// <inheritdoc />
public bool AddUserCommand(UserCommand userCommand)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public bool DeleteUserCommand(Guid userCommandId)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public bool UpdateUserCommand(UserCommand userCommand)
{
throw new NotImplementedException();
}
}
53 changes: 53 additions & 0 deletions backend/src/Matroos.Backend/Services/WorkersService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using Matroos.Resources.Classes.Bots;
using Matroos.Resources.Classes.Workers;

namespace Matroos.Backend.Services.Interfaces;

public class WorkersService : IWorkersService
{
/// <summary>
/// The workers.
/// </summary>
public List<Worker> Workers { get; }

public WorkersService()
{
Workers = new();
}

/// <inheritdoc />
public bool StartBotInWorker(Guid workerId, Guid botId)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public bool StopBotInWorker(Guid workerId, Guid botId)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public Task<List<Bot>> GetBotsFromWorker(Guid workerId)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public bool AddBotsToWorker(Guid workerId, List<Guid> botIds)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public bool UpdateBotsInWorker(Guid workerId, List<Guid> botIds)
{
throw new NotImplementedException();
}

/// <inheritdoc />
public bool DeleteBotsFromWorker(Guid workerId, List<Guid> botIds)
{
throw new NotImplementedException();
}
}
38 changes: 21 additions & 17 deletions worker/src/Matroos.Worker/Matroos.Worker.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\resources\src\Matroos.Resources\Matroos.Resources.csproj" />
</ItemGroup>

</Project>
56 changes: 31 additions & 25 deletions worker/src/Matroos.Worker/Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
WebApplicationBuilder 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();

WebApplication app = builder.Build();

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

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
using Matroos.Worker.Services;
using Matroos.Worker.Services.Interfaces;

WebApplicationBuilder 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();

// Services
builder.Services.AddSingleton<IMainService, MainService>();

WebApplication app = builder.Build();

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

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
Loading

0 comments on commit 2b6e5d7

Please sign in to comment.