Compare commits
4 Commits
49c7d14925
...
5687949f96
Author | SHA1 | Date | |
---|---|---|---|
5687949f96 | |||
2a9508f737 | |||
1e2bd05667 | |||
fbfde769b1 |
@ -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)
|
||||||
|
79
Cloud/Controllers/GreengouseController.cs
Normal file
79
Cloud/Controllers/GreengouseController.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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"]
|
||||||
|
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
14
Cloud/Models/Greenhouse.cs
Normal file
14
Cloud/Models/Greenhouse.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
8
Cloud/Models/Support/HeatingMode.cs
Normal file
8
Cloud/Models/Support/HeatingMode.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace Cloud.Models.Support
|
||||||
|
{
|
||||||
|
public enum HeatingMode
|
||||||
|
{
|
||||||
|
Manual,
|
||||||
|
Auto
|
||||||
|
}
|
||||||
|
}
|
8
Cloud/Models/Support/WateringMode.cs
Normal file
8
Cloud/Models/Support/WateringMode.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace Cloud.Models.Support
|
||||||
|
{
|
||||||
|
public enum WateringMode
|
||||||
|
{
|
||||||
|
Manual,
|
||||||
|
Auto
|
||||||
|
}
|
||||||
|
}
|
@ -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 =>
|
||||||
{
|
{
|
||||||
|
11
Cloud/Requests/GreenhouseRequest.cs
Normal file
11
Cloud/Requests/GreenhouseRequest.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
7
Cloud/Services/Broker/IBrokerConsumer.cs
Normal file
7
Cloud/Services/Broker/IBrokerConsumer.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace Cloud.Services.Broker
|
||||||
|
{
|
||||||
|
public interface IBrokerConsumer
|
||||||
|
{
|
||||||
|
// TODO: добавить методы для получения данных
|
||||||
|
}
|
||||||
|
}
|
9
Cloud/Services/Broker/IBrokerProdurcer.cs
Normal file
9
Cloud/Services/Broker/IBrokerProdurcer.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
using Cloud.Services.Broker.Support;
|
||||||
|
|
||||||
|
namespace Cloud.Services.Broker
|
||||||
|
{
|
||||||
|
public interface IBrokerProdurcer
|
||||||
|
{
|
||||||
|
Task ProduceAsync(string topic, Command command);
|
||||||
|
}
|
||||||
|
}
|
10
Cloud/Services/Broker/IBrokerService.cs
Normal file
10
Cloud/Services/Broker/IBrokerService.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
17
Cloud/Services/Broker/Implement/Kafka/KafkaService.cs
Normal file
17
Cloud/Services/Broker/Implement/Kafka/KafkaService.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Cloud/Services/Broker/Support/Command.cs
Normal file
9
Cloud/Services/Broker/Support/Command.cs
Normal 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!;
|
||||||
|
}
|
||||||
|
}
|
9
Cloud/Services/Broker/Support/CommandResult.cs
Normal file
9
Cloud/Services/Broker/Support/CommandResult.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
12
Cloud/Services/Broker/Support/GreenhouseInfo.cs
Normal file
12
Cloud/Services/Broker/Support/GreenhouseInfo.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user