Skip to content

Commit

Permalink
Refactor UserInteractionService to reuse IUserManager instance
Browse files Browse the repository at this point in the history
  • Loading branch information
urumo committed Oct 27, 2024
1 parent bce9f4b commit f649688
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/Argon.Api/Services/UserInteractionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,34 @@ public class UserInteractionService(
IGrainFactory grainFactory
) : IUserInteraction
{
public async Task<UserResponse> GetMe() => await grainFactory.GetGrain<IUserManager>(username).Get();
private readonly IUserManager userManager = grainFactory.GetGrain<IUserManager>(username);

public async Task<ServerResponse> CreateServer(CreateServerRequest request) =>
await grainFactory
.GetGrain<IUserManager>(username)
.CreateServer(request.Name, request.Description);
public async Task<UserResponse> GetMe()
{
return await userManager.Get();
}

public async Task<List<ServerResponse>> GetServers() =>
(await grainFactory
.GetGrain<IUserManager>(username)
.GetServers())
.Select(x => (ServerResponse)x)
.ToList();
public async Task<ServerResponse> CreateServer(CreateServerRequest request)
{
return await userManager.CreateServer(request.Name, request.Description);
}

public async Task<List<ServerDetailsResponse>> GetServerDetails(ServerDetailsRequest request) =>
(await grainFactory.GetGrain<IUserManager>(username).GetServerChannels(request.ServerId))
.Select(x => (ServerDetailsResponse)x)
.ToList();
public async Task<List<ServerResponse>> GetServers()
{
return (await userManager.GetServers())
.Select(x => (ServerResponse)x)
.ToList();
}

public async Task<ChannelJoinResponse> JoinChannel(ChannelJoinRequest request) =>
new((await grainFactory.GetGrain<IUserManager>(username)
.JoinChannel(request.ServerId, request.ChannelId)).value);
public async Task<List<ServerDetailsResponse>> GetServerDetails(ServerDetailsRequest request)
{
return (await userManager.GetServerChannels(request.ServerId))
.Select(x => (ServerDetailsResponse)x)
.ToList();
}

public async Task<ChannelJoinResponse> JoinChannel(ChannelJoinRequest request)
{
return new ChannelJoinResponse((await userManager.JoinChannel(request.ServerId, request.ChannelId)).value);
}
}

0 comments on commit f649688

Please sign in to comment.