feat : RDB 기능 추가 (라이브러리, base 코드 구현)

This commit is contained in:
qornwh1
2026-03-01 16:58:38 +09:00
parent 563448a09a
commit 34394f2c96
14 changed files with 410 additions and 0 deletions

View 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);
}
}