initial commit
This commit is contained in:
32
Presentation/GraphQL/Mutations/UserMutations.cs
Normal file
32
Presentation/GraphQL/Mutations/UserMutations.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user