feat : RDB 기능 추가 (라이브러리, base 코드 구현)
This commit is contained in:
57
MMOTestServer/MMOserver/RDB/Services/TestService.cs
Normal file
57
MMOTestServer/MMOserver/RDB/Services/TestService.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using MMOserver.RDB.Models;
|
||||
using MMOserver.RDB.Repositories;
|
||||
|
||||
namespace MMOserver.RDB.Services;
|
||||
|
||||
public class TestService
|
||||
{
|
||||
private readonly TestRepository repo;
|
||||
|
||||
public TestService(TestRepository repo)
|
||||
{
|
||||
this.repo = repo;
|
||||
}
|
||||
|
||||
public Task<Test?> GetTestAsync(int id)
|
||||
{
|
||||
return repo.GetByIdAsync(id);
|
||||
}
|
||||
|
||||
public Task<Test?> GetTestByUuidAsync(string uuid)
|
||||
{
|
||||
return repo.GetByUuidAsync(uuid);
|
||||
}
|
||||
|
||||
public Task<IEnumerable<Test>> GetAllTestsAsync()
|
||||
{
|
||||
return repo.GetAllAsync();
|
||||
}
|
||||
|
||||
public async Task<long> CreateTestAsync(int testA, string testB, double testC)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(testB))
|
||||
{
|
||||
throw new ArgumentException("TestB is required");
|
||||
}
|
||||
|
||||
return await repo.InsertAsync(new Test { TestA = testA, TestB = testB, TestC = testC, Uuid = Guid.NewGuid().ToString() });
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateTestAsync(int id, int? testA, string? testB, double? testC)
|
||||
{
|
||||
Test entity = await repo.GetByIdAsync(id) ?? throw new KeyNotFoundException("Test not found");
|
||||
|
||||
entity.TestA = testA ?? entity.TestA;
|
||||
entity.TestB = testB ?? entity.TestB;
|
||||
entity.TestC = testC ?? entity.TestC;
|
||||
|
||||
return await repo.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteTestAsync(int id)
|
||||
{
|
||||
Test entity = await repo.GetByIdAsync(id) ?? throw new KeyNotFoundException("Test not found");
|
||||
|
||||
return await repo.DeleteAsync(entity);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user