32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using Application;
|
|
using Application.Interfaces.Services;
|
|
using Application.Services;
|
|
using Domain.Entities;
|
|
using GraphQLTEST.GraphQL.Subscriptions;
|
|
using HotChocolate.Subscriptions;
|
|
|
|
namespace GraphQLTEST.GraphQL.Mutations;
|
|
|
|
[ExtendObjectType(nameof(MutationType))]
|
|
public class UserMutations
|
|
{
|
|
public async Task<bool> AddUser(string username, string email, string password, [Service] IUserService service) =>
|
|
await Task.Run(() => service.CreateUser(username, password, email));
|
|
|
|
public async Task<Kill> AddKill(
|
|
string victim,
|
|
double damage,
|
|
int userId,
|
|
[Service] IKillService killService,
|
|
[Service] IUserService userService,
|
|
[Service] ITopicEventSender eventSender,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var user = userService.GetUserById(userId);
|
|
var kill = new Kill
|
|
{ Id = Random.Shared.Next(0, 100), Damage = damage, User = user, UserId = user.Id, Victim = victim };
|
|
killService.AddKill(kill);
|
|
await eventSender.SendAsync(nameof(UserSubscriptions.KillAdded), kill, cancellationToken);
|
|
return kill;
|
|
}
|
|
} |