초기커밋
This commit is contained in:
@@ -0,0 +1,210 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using ServerBase;
|
||||
using ServerCommon;
|
||||
|
||||
namespace BrokerCore.Repository;
|
||||
|
||||
using DbEntity;
|
||||
|
||||
using Context;
|
||||
|
||||
public class PlanetItemExchangeOrderAmountTotalLimitRepo
|
||||
{
|
||||
private readonly MetaverseBrokerDbContext m_db_context;
|
||||
|
||||
public PlanetItemExchangeOrderAmountTotalLimitRepo(MetaverseBrokerDbContext dbContext)
|
||||
{
|
||||
m_db_context = dbContext;
|
||||
}
|
||||
|
||||
// 총 교환 제한 추가
|
||||
public async Task<Result> add(PlanetItemExchangeOrderAmountTotalLimit limit,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = new Result();
|
||||
try
|
||||
{
|
||||
m_db_context.PlanetItemExchangeOrderAmountTotalLimits.Add(limit);
|
||||
await m_db_context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result.setFail(ServerErrorCode.RdbError, e.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 총 교환 제한 업데이트
|
||||
public async Task<Result> update(PlanetItemExchangeOrderAmountTotalLimit limit,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = new Result();
|
||||
try
|
||||
{
|
||||
m_db_context.PlanetItemExchangeOrderAmountTotalLimits.Update(limit);
|
||||
await m_db_context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result.setFail(ServerErrorCode.RdbError, e.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<Result> increaseDailyAmount(
|
||||
PlanetItemExchangeOrderAmountTotalLimit limit,
|
||||
int increaseAmount,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = new Result();
|
||||
try
|
||||
{
|
||||
limit.DailyAmount += increaseAmount;
|
||||
// DailyAmount만 업데이트하기 위해 특정 열만 업데이트
|
||||
var entity = m_db_context.Entry(limit);
|
||||
entity.Property(x => x.DailyAmount).IsModified = true;
|
||||
await m_db_context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result.setFail(ServerErrorCode.RdbError, e.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 총 교환 제한 삭제
|
||||
public async Task<Result> delete(PlanetItemExchangeOrderAmountTotalLimit limit,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = new Result();
|
||||
try
|
||||
{
|
||||
m_db_context.PlanetItemExchangeOrderAmountTotalLimits.Remove(limit);
|
||||
await m_db_context.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result.setFail(ServerErrorCode.RdbError, e.Message);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// 특정 교환 메타 아이디와 날짜에 대한 교환 제한 조회
|
||||
public async Task<(Result, PlanetItemExchangeOrderAmountTotalLimit?)> findByExchangeMetaAndDateOrCreate(
|
||||
string exchangeMetaId,
|
||||
DateOnly exchangeDate,
|
||||
string seasonId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = new Result();
|
||||
try
|
||||
{
|
||||
var limit = await m_db_context.PlanetItemExchangeOrderAmountTotalLimits
|
||||
.Where(x =>
|
||||
x.ExchangeMetaId == exchangeMetaId &&
|
||||
x.ExchangeDate == exchangeDate &&
|
||||
x.SeasonId == seasonId)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
|
||||
if (limit == null)
|
||||
{
|
||||
limit = new PlanetItemExchangeOrderAmountTotalLimit
|
||||
{
|
||||
ExchangeMetaId = exchangeMetaId,
|
||||
ExchangeDate = exchangeDate,
|
||||
SeasonId = seasonId,
|
||||
DailyAmount = 0
|
||||
};
|
||||
await add(limit, cancellationToken);
|
||||
}
|
||||
|
||||
return (result, limit);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result.setFail(ServerErrorCode.RdbError, e.Message);
|
||||
return (result, null);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<(Result, PlanetItemExchangeOrderAmountTotalLimit?)> findByExchangeMetaAndDate(
|
||||
string exchangeMetaId,
|
||||
DateOnly exchangeDate,
|
||||
string seasonId,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
var result = new Result();
|
||||
try
|
||||
{
|
||||
var limit = await m_db_context.PlanetItemExchangeOrderAmountTotalLimits
|
||||
.Where(x =>
|
||||
x.ExchangeMetaId == exchangeMetaId &&
|
||||
x.ExchangeDate == exchangeDate &&
|
||||
x.SeasonId == seasonId)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
return (result, limit);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
result.setFail(ServerErrorCode.RdbError, e.Message);
|
||||
return (result, null);
|
||||
}
|
||||
}
|
||||
|
||||
// // 특정 교환 메타 아이디에 대한 모든 교환 제한 조회
|
||||
// public async Task<(Result, IEnumerable<PlanetItemExchangeOrderAmountTotalLimit>?)> findByExchangeMeta(
|
||||
// string exchangeMetaId,
|
||||
// int pageIndex = 1,
|
||||
// int pageSize = 20,
|
||||
// CancellationToken cancellationToken = default)
|
||||
// {
|
||||
// var result = new Result();
|
||||
// try
|
||||
// {
|
||||
// var limits = await m_db_context.PlanetItemExchangeOrderAmountTotalLimits
|
||||
// .Where(x => x.ExchangeMetaId == exchangeMetaId)
|
||||
// .OrderBy(x => x.ExchangeDate)
|
||||
// .Skip((pageIndex - 1) * pageSize)
|
||||
// .Take(pageSize)
|
||||
// .ToArrayAsync(cancellationToken);
|
||||
//
|
||||
// return (result, limits);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// result.setFail(ServerErrorCode.RdbError, e.Message);
|
||||
// return (result, null);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// // 특정 날짜에 대한 모든 교환 제한 조회
|
||||
// public async Task<(Result, IEnumerable<PlanetItemExchangeOrderAmountTotalLimit>?)> findByDate(
|
||||
// DateOnly exchangeDate,
|
||||
// int pageIndex = 1,
|
||||
// int pageSize = 20,
|
||||
// CancellationToken cancellationToken = default)
|
||||
// {
|
||||
// var result = new Result();
|
||||
// try
|
||||
// {
|
||||
// var limits = await m_db_context.PlanetItemExchangeOrderAmountTotalLimits
|
||||
// .Where(x => x.ExchangeDate == exchangeDate)
|
||||
// .OrderBy(x => x.ExchangeMetaId)
|
||||
// .Skip((pageIndex - 1) * pageSize)
|
||||
// .Take(pageSize)
|
||||
// .ToArrayAsync(cancellationToken);
|
||||
//
|
||||
// return (result, limits);
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// result.setFail(ServerErrorCode.RdbError, e.Message);
|
||||
// return (result, null);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
Reference in New Issue
Block a user