initial commit
This commit is contained in:
48
Application/Services/KillService.cs
Normal file
48
Application/Services/KillService.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Application.Interfaces.Repositories;
|
||||
using Application.Interfaces.Services;
|
||||
using Domain.Entities;
|
||||
|
||||
namespace Application.Services;
|
||||
|
||||
public class KillService(IKillRepository repository, IUserService userService) : IKillService
|
||||
{
|
||||
private IKillRepository Repository { get; } = repository;
|
||||
|
||||
public IEnumerable<Kill> GetAllKills()
|
||||
{
|
||||
return Repository.GetAllKills();
|
||||
}
|
||||
|
||||
public Kill GetKillById(int id)
|
||||
{
|
||||
if (!Repository.TryGetKillById(id, out var kill))
|
||||
{
|
||||
throw new KeyNotFoundException($"Failed to find kill with id: {id}");
|
||||
}
|
||||
|
||||
return kill;
|
||||
}
|
||||
|
||||
public IEnumerable<Kill> GetKillsByUserId(int userId)
|
||||
{
|
||||
return Repository.GetAllKills().Where(x => x.UserId == userId);
|
||||
}
|
||||
|
||||
public IEnumerable<Kill> GetKillsByUserId(IEnumerable<int> userIds)
|
||||
{
|
||||
return Repository.GetAllKills().Where(x => userIds.Contains(x.UserId));
|
||||
}
|
||||
|
||||
public bool AddKill(Kill kill)
|
||||
{
|
||||
Repository.AddKill(kill);
|
||||
var user = userService.GetUserById(kill.UserId);
|
||||
user.Kills.Append(kill);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool RemoveKill(Kill kill)
|
||||
{
|
||||
return Repository.RemoveKill(kill);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user