Skip to content

Commit

Permalink
hot fix for not getting historic data
Browse files Browse the repository at this point in the history
  • Loading branch information
juuwel committed Jun 5, 2024
1 parent 26e4201 commit 0c6b42e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-be.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
dotnet-version: '8.0.x'

- run: cd api && dotnet publish -c Release -o publish
- run: cd api && dotnet publish --prod -c Release -o publish
- uses: AkhileshNS/[email protected]
with:
heroku_api_key: ${{ secrets.HEROKU_API_KEY }}
Expand Down
10 changes: 10 additions & 0 deletions Infrastructure/Repositories/ConditionsLogsRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,22 @@ public async Task<int> GetRecentMoodAsync(Guid plantId)
.FirstOrDefaultAsync();
}

// TODO: returns empty if there is no data in the past 7 days, but should then look further back
public async Task<List<ConditionsLog>> GetConditionsLogsForPlant(Guid plantId, int timeSpanInDays)
{
await using var context = await dbContextFactory.CreateDbContextAsync();
var logs = await context.ConditionsLogs
.Where(log => log.PlantId == plantId && log.TimeStamp >= DateTime.UtcNow.AddDays(-timeSpanInDays))
.ToListAsync();

if (logs.Count == 0)
{
logs = await context.ConditionsLogs
.Where(log => log.PlantId == plantId)
.OrderByDescending(log => log.TimeStamp)
.Take(7)
.ToListAsync();
}

var groupedLogs = logs
.GroupBy(log => new DateTime(log.TimeStamp.Year, log.TimeStamp.Month, timeSpanInDays == 365 ? 1 : log.TimeStamp.Day))
Expand Down
12 changes: 3 additions & 9 deletions Shared/Exceptions/AppException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ namespace Shared.Exceptions;

public class AppException : Exception
{
public AppException(string message) : base(message)
{
}
public AppException(string message) : base(message) { }

protected AppException(string message, Exception innerException) : base(message, innerException)
{
}
protected AppException(string message, Exception innerException) : base(message, innerException) { }

protected AppException()
{
}
protected AppException() { }
}
1 change: 1 addition & 0 deletions api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public static async Task<WebApplication> StartApi(string[] args)
var jwtValid = jwtService.IsJwtTokenValid(dto.Jwt);
if (!jwtValid)
{
app.Services.GetRequiredService<WebSocketConnectionService>().RemoveEmailFromConnection(socket);
throw new NotAuthenticatedException("JWT token is not valid. Please log in.");
}
}
Expand Down

0 comments on commit 0c6b42e

Please sign in to comment.