Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
juuwel committed May 9, 2024
1 parent 1cb7f02 commit 0fb01da
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 17 deletions.
3 changes: 2 additions & 1 deletion Core/Services/ConditionsLogsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public async Task CreateConditionsLogAsync(CreateConditionsLogDto createConditio
Light = createConditionsLogDto.Light,
Temperature = createConditionsLogDto.Temperature,
Humidity = createConditionsLogDto.Humidity,
PlantId = plantId
PlantId = plantId,
Mood = -1
};

var newMood = await CalculateMood(conditionsLog);
Expand Down
2 changes: 2 additions & 0 deletions Infrastructure/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ await conditionsLogRepository.CreateConditionsLogAsync(
{
ConditionsId = Guid.NewGuid(),
PlantId = plants[0].PlantId,
TimeStamp = DateTime.UtcNow,
Mood = 2,
Light = 33.0,
SoilMoisture = 74.0,
Humidity = 50.0,
Expand Down
16 changes: 8 additions & 8 deletions Shared/Models/Information/ConditionsLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ namespace Shared.Models.Information;

public class ConditionsLog
{
public Guid ConditionsId { get; set; }
public Guid PlantId { get; set; }
public DateTime TimeStamp { get; set; }
public int Mood { get; set; }
public double SoilMoisture { get; set; }
public double Light { get; set; }
public double Temperature { get; set; }
public double Humidity { get; set; }
public required Guid ConditionsId { get; set; }
public required Guid PlantId { get; set; }
public required DateTime TimeStamp { get; set; }
public required int Mood { get; set; }
public required double SoilMoisture { get; set; }
public required double Light { get; set; }
public required double Temperature { get; set; }
public required double Humidity { get; set; }
}
3 changes: 2 additions & 1 deletion Tests/PlantTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using api.Events.Collections.Server;
using api.Events.PlantEvents.Client;
using api.Events.PlantEvents.Server;
using lib;
Expand Down Expand Up @@ -31,7 +32,7 @@ await webSocketTestClient.DoAndAssert(new ClientWantsAllPlantsDto
PageSize = 10
}, receivedMessages =>
{
return receivedMessages.Count(e => e.eventType == nameof(ServerSendsAllPlants)) == 1;
return receivedMessages.Count(e => e.eventType == nameof(ServerSendsPlantsForCollection)) == 1;
});
}

Expand Down
12 changes: 7 additions & 5 deletions api/Events/Conditions/ClientWantsLatestConditionsForPlant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public override async Task Handle(ClientWantsLatestConditionsForPlantDto dto, IW
{
var email = jwtService.GetEmailFromJwt(dto.Jwt!);
var conditionsLog = await conditionsLogsService.GetLatestConditionsLogForPlant(dto.PlantId, email);
socket.SendDto(new ServerSendsLatestConditionsForPlant()
{
ConditionsLog = conditionsLog
}
);

var serverResponse = new ServerSendsLatestConditionsForPlant
{
ConditionsLog = conditionsLog
};

socket.SendDto(serverResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ namespace api.Events.Conditions;

public class ServerSendsLatestConditionsForPlant : BaseDto
{
public required ConditionsLog ConditionsLog;
public required ConditionsLog ConditionsLog { get; set; }
}
2 changes: 1 addition & 1 deletion api/Events/PlantEvents/Client/ClientWantsPlantById.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ClientWantsPlantById(PlantService plantService, JwtService jwtServi
{
public override async Task Handle(ClientWantsPlantByIdDto dto, IWebSocketConnection socket)
{
var email = jwtService.GetEmailFromJwt(dto.Jwt);
var email = jwtService.GetEmailFromJwt(dto.Jwt!);
var plant = await plantService.GetPlantById(dto.PlantId, email);
socket.SendDto(new ServerSendsPlant
{
Expand Down
2 changes: 2 additions & 0 deletions api/Extensions/WebSocketExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Text.Json;
using Fleck;
using lib;
using Serilog;

namespace api.Extensions;

Expand All @@ -13,6 +14,7 @@ public static class WebSocketExtensions

public static void SendDto<T>(this IWebSocketConnection ws, T dto) where T : BaseDto
{
Log.Information("Sending message: {message}", JsonSerializer.Serialize(dto, Options));
ws.Send(JsonSerializer.Serialize(dto, Options) ?? throw new ArgumentException("Failed to serialize dto"));
}
}

0 comments on commit 0fb01da

Please sign in to comment.