-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created statsservice to handle updating stats when collection or plan…
…t is added, updated or deleted Upon logging out we no longer remove the entire connection, just the email, the connection is removed on onclose
- Loading branch information
1 parent
c569b77
commit da1c116
Showing
12 changed files
with
99 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace Shared.Models; | ||
|
||
public class Stats | ||
{ | ||
public int TotalPlants { get; set; } | ||
public int HappyPlants { get; set; } | ||
public int Collections { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Shared.Dtos; | ||
using Shared.Models; | ||
|
||
namespace api.Core.Services; | ||
|
||
public class StatsService(CollectionsService collectionsService, PlantService plantService) | ||
{ | ||
public async Task<Stats> GetStats(string email) | ||
{ | ||
var totalPlants = await plantService.GetTotalPlantsCount(email); | ||
var happyPlants = await plantService.GetHappyPlantsCount(email); | ||
var collections = await collectionsService.GetTotalCollectionsCount(email); | ||
|
||
return new Stats | ||
{ | ||
TotalPlants = totalPlants, | ||
HappyPlants = happyPlants, | ||
Collections = collections | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using api.Core.Services; | ||
using api.Extensions; | ||
using Fleck; | ||
using lib; | ||
using Shared.Models; | ||
|
||
namespace api.Events.Statistics; | ||
|
||
public class ClientWantsStatsDto : BaseDtoWithJwt | ||
{ | ||
|
||
} | ||
|
||
public class ClientWantsStats(StatsService statsService, JwtService jwtService) : BaseEventHandler<ClientWantsStatsDto> | ||
{ | ||
public override async Task Handle(ClientWantsStatsDto dto, IWebSocketConnection socket) | ||
{ | ||
var email = jwtService.GetEmailFromJwt(dto.Jwt!); | ||
|
||
var stats = await statsService.GetStats(email); | ||
socket.SendDto(new ServerSendsStats{Stats = stats}); | ||
} | ||
} | ||
|
||
public class ServerSendsStats : BaseDto | ||
{ | ||
public Stats Stats { get; set; } = null!; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters