Compare commits

...

4 Commits

16 changed files with 199 additions and 1 deletions

View File

@ -6,6 +6,7 @@ public class ApplicationContext : DbContext
{ {
public DbSet<User> Users { get; set; } = null!; public DbSet<User> Users { get; set; } = null!;
public DbSet<Farm> Farms { get; set; } = null!; public DbSet<Farm> Farms { get; set; } = null!;
public DbSet<Greenhouse> Greenhouses { get; set; } = null!;
public ApplicationContext(DbContextOptions<ApplicationContext> options) public ApplicationContext(DbContextOptions<ApplicationContext> options)
: base(options) : base(options)

View File

@ -0,0 +1,79 @@
using Cloud.Models;
using Cloud.Requests;
using Cloud.Services.Broker;
using Cloud.Services.Broker.Support;
using Microsoft.AspNetCore.Mvc;
namespace Cloud.Controllers
{
[ApiController]
[Route("api/user/{userId}/farm/{farmId}/greenhouse")]
public class GreenhouseController : ControllerBase
{
private readonly IBrokerService _brokerService;
private readonly ApplicationContext _context;
private readonly IConfiguration _config;
public GreenhouseController(IConfiguration config, ApplicationContext context,
IBrokerService brokerService)
{
_brokerService = brokerService;
_context = context;
_config = config;
}
/**
* Возвращает текущую информацию о всех теплицах пользователя
*/
[HttpGet]
public async Task<ActionResult<List<GreenhouseInfo>>> GetAll(int userId, int farmId)
{
throw new NotImplementedException();
}
/**
* Возвращает текущую информацию о конкретной теплице
*/
[HttpGet("{greenhouseId}")]
public async Task<ActionResult<GreenhouseInfo>> Get(int userId, int farmId, int greenhouseId)
{
throw new NotImplementedException();
}
/**
* Возвращает сохраненные данные для автоматизации теплицы
*/
[HttpGet("{greenhouseId}/settings")]
public async Task<ActionResult<Greenhouse>> GetGreenhouse(int userId, int farmId, int greenhouseId)
{
throw new NotImplementedException();
}
/**
* Сохраняет в базе данных API данные для автоматизации теплицы
*/
[HttpPost]
public async Task<ActionResult<Greenhouse>> SaveToDatabase(int userId, int farmId, GreenhouseRequest greenhouse)
{
throw new NotImplementedException();
}
/**
* Обновляет в базе данных API данные для автоматизации теплицы
*/
[HttpPut("{greenhouseId}/settings")]
public async Task<ActionResult<Greenhouse>> Update(int userId, int farmId, int greenhouseId, GreenhouseRequest greenhouse)
{
throw new NotImplementedException();
}
/**
* Удаляет из базы данных API запись настроек автоматизации теплицы
*/
[HttpDelete("{greenhouseId}")]
public async Task<ActionResult> Delete(int userId, int farmId, int greenhouseId)
{
throw new NotImplementedException();
}
}
}

View File

@ -25,5 +25,6 @@ RUN dotnet publish "./Cloud.csproj" -c $configuration -o /app/publish /p:UseAppH
FROM base AS final FROM base AS final
WORKDIR /app WORKDIR /app
COPY --from=publish /app/publish . COPY --from=publish /app/publish .
# TODO: Добавить инициализацию базы данных с помощью миграции
ENTRYPOINT ["dotnet", "Cloud.dll"] ENTRYPOINT ["dotnet", "Cloud.dll"]

View File

@ -7,5 +7,6 @@
public int UserId { get; set; } public int UserId { get; set; }
public User? User { get; set; } public User? User { get; set; }
public string RaspberryIP { get; set; } public string RaspberryIP { get; set; }
List<Greenhouse> Greenhouses { get; set; } = new();
} }
} }

View File

@ -0,0 +1,14 @@
using Cloud.Models.Support;
namespace Cloud.Models
{
public class Greenhouse
{
public int Id { get; set; }
public int RecomendedTemperature { get; set; }
public WateringMode WateringMode { get; set; }
public HeatingMode HeatingMode { get; set; }
public int FarmId { get; set; }
public Farm? Farm { get; set; }
}
}

View File

@ -0,0 +1,8 @@
namespace Cloud.Models.Support
{
public enum HeatingMode
{
Manual,
Auto
}
}

View File

@ -0,0 +1,8 @@
namespace Cloud.Models.Support
{
public enum WateringMode
{
Manual,
Auto
}
}

View File

@ -7,11 +7,13 @@ using FluentValidation;
using FluentValidation.AspNetCore; using FluentValidation.AspNetCore;
using Cloud.Validation; using Cloud.Validation;
using StackExchange.Redis; using StackExchange.Redis;
using Cloud.Services.Broker.Implement.Kafka;
using Cloud.Services.Broker;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddSingleton<IBrokerService, KafkaService>();
//Redis configuration //Redis configuration
builder.Services.AddSingleton<IConnectionMultiplexer>(sp => builder.Services.AddSingleton<IConnectionMultiplexer>(sp =>
{ {

View File

@ -0,0 +1,11 @@
using Cloud.Models.Support;
namespace Cloud.Requests
{
public class GreenhouseRequest
{
public int RecomendedTemperature { get; set; }
public WateringMode WateringMode { get; set; }
public HeatingMode HeatingMode { get; set; }
}
}

View File

@ -0,0 +1,7 @@
namespace Cloud.Services.Broker
{
public interface IBrokerConsumer
{
// TODO: добавить методы для получения данных
}
}

View File

@ -0,0 +1,9 @@
using Cloud.Services.Broker.Support;
namespace Cloud.Services.Broker
{
public interface IBrokerProdurcer
{
Task ProduceAsync(string topic, Command command);
}
}

View File

@ -0,0 +1,10 @@
using Cloud.Services.Broker.Support;
namespace Cloud.Services.Broker
{
public interface IBrokerService
{
Task<CommandResult> Produce(Command command);
Task<T> Consume<T>(string topic);
}
}

View File

@ -0,0 +1,17 @@
using Cloud.Services.Broker.Support;
namespace Cloud.Services.Broker.Implement.Kafka
{
public class KafkaService : IBrokerService
{
public Task<T> Consume<T>(string topic)
{
throw new NotImplementedException();
}
public Task<CommandResult> Produce(Command command)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,9 @@
namespace Cloud.Services.Broker.Support
{
public class Command
{
public int Id { get; set; }
public int GreenhouseId { get; set; }
public string CommandName { get; set; } = null!;
}
}

View File

@ -0,0 +1,9 @@
namespace Cloud.Services.Broker.Support
{
public class CommandResult
{
public int CommandId { get; set; }
public int GreenhouseId { get; set; }
public string ResultMessage { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,12 @@
namespace Cloud.Services.Broker.Support
{
public class GreenhouseInfo
{
public int Id { get; set; }
public int PercentWater { get; set; }
public int SoilTemperature { get; set; }
public bool PumpStatus { get; set; }
public bool HeatingStatus { get; set; }
public bool AutoWateringStatus { get; set; }
}
}