48 lines
1.2 KiB
C#
48 lines
1.2 KiB
C#
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);
|
|
}
|
|
} |