Yuna/Yuna.Website/Yuna.Website.Server/Services/PropService/PropService.cs

60 lines
1.6 KiB
C#

using Yuna.Website.Server.Model;
using Yuna.Website.Server.Storage.Repositories.Prop;
namespace Yuna.Website.Server.Services.DeviceSkillService
{
public class PropService : IPropService
{
private readonly IPropRepository _propRepository;
public PropService(IPropRepository propRepository)
{
_propRepository = propRepository;
}
public async Task<Prop?> Create(Prop prop)
{
var existingProp = await _propRepository.GetByPropName(prop.Name);
if (existingProp is not null) return null;
var result = await _propRepository.Create(prop);
return result;
}
public async Task<Prop?> Delete(long id)
{
var prop = await _propRepository.GetById(id);
if (prop is null) return null;
var result = await _propRepository.Delete(id);
return result;
}
public async Task<Prop?> GetById(long id)
{
var result = await _propRepository.GetById(id);
return result;
}
public async Task<IReadOnlyList<Prop>?> GetByIds(long[] ids)
{
if (ids.Count() == 0) return [];
var props = await _propRepository.GetByIds(ids);
return props;
}
public async Task<Prop?> GetByPropName(string name)
{
var result = await _propRepository.GetByPropName(name);
return result;
}
public async Task<IReadOnlyList<Prop>> GetList()
{
var result = await _propRepository.GetList();
return result ?? [];
}
}
}