223 lines
6.1 KiB
C#
223 lines
6.1 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
|
|
using ServerBase;
|
|
|
|
namespace BrokerApiCore;
|
|
|
|
public class PlanetItemExchangeOrderAmountUserLimitRepo
|
|
{
|
|
private readonly MetaverseBrokerDbContext m_db_context;
|
|
|
|
public PlanetItemExchangeOrderAmountUserLimitRepo(MetaverseBrokerDbContext dbContext)
|
|
{
|
|
m_db_context = dbContext;
|
|
}
|
|
|
|
// 사용자별 교환 제한 추가
|
|
public async Task<Result> add(PlanetItemExchangeOrderAmountUserLimit limit,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var result = new Result();
|
|
try
|
|
{
|
|
m_db_context.PlanetItemExchangeOrderAmountUserLimits.Add(limit);
|
|
await m_db_context.SaveChangesAsync(cancellationToken);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
result.setFail(ServerErrorCode.InternalServerError, e.Message);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// 사용자별 교환 제한 업데이트
|
|
public async Task<Result> update(PlanetItemExchangeOrderAmountUserLimit limit,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var result = new Result();
|
|
try
|
|
{
|
|
m_db_context.PlanetItemExchangeOrderAmountUserLimits.Update(limit);
|
|
await m_db_context.SaveChangesAsync(cancellationToken);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
result.setFail(ServerErrorCode.InternalServerError, e.Message);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// 사용자별 교환 제한 삭제
|
|
public async Task<Result> delete(PlanetItemExchangeOrderAmountUserLimit limit,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var result = new Result();
|
|
try
|
|
{
|
|
m_db_context.PlanetItemExchangeOrderAmountUserLimits.Remove(limit);
|
|
await m_db_context.SaveChangesAsync(cancellationToken);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
result.setFail(ServerErrorCode.InternalServerError, e.Message);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
// 특정 사용자와 날짜에 대한 교환 제한 조회
|
|
public async Task<(Result, PlanetItemExchangeOrderAmountUserLimit?)> findByUserAndDate(
|
|
string exchangeMetaId,
|
|
string userGuid,
|
|
DateOnly exchangeDate,
|
|
string seasonId,
|
|
CancellationToken cancellationToken = default)
|
|
{
|
|
var result = new Result();
|
|
try
|
|
{
|
|
var limit = await m_db_context.PlanetItemExchangeOrderAmountUserLimits
|
|
.Where(x =>
|
|
x.ExchangeMetaId == exchangeMetaId &&
|
|
x.ExchangeDate == exchangeDate &&
|
|
x.SeasonId == seasonId &&
|
|
x.UserGuid == userGuid)
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
|
|
return (result, limit);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
result.setFail(ServerErrorCode.RdbError, e.Message);
|
|
return (result, null);
|
|
}
|
|
}
|
|
|
|
// // 특정 교환 메타 아이디에 대한 모든 교환 제한 조회
|
|
// public async Task<(Result, IEnumerable<PlanetItemExchangeOrderAmountUserLimit>?)> findByExchangeMeta(
|
|
// string exchangeMetaId,
|
|
// int pageIndex = 1,
|
|
// int pageSize = 20,
|
|
// CancellationToken cancellationToken = default)
|
|
// {
|
|
// var result = new Result();
|
|
// try
|
|
// {
|
|
// var limits = await m_db_context.PlanetItemExchangeOrderAmountUserLimits
|
|
// .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<PlanetItemExchangeOrderAmountUserLimit>?)> findByDate(
|
|
// DateOnly exchangeDate,
|
|
// int pageIndex = 1,
|
|
// int pageSize = 20,
|
|
// CancellationToken cancellationToken = default)
|
|
// {
|
|
// var result = new Result();
|
|
// try
|
|
// {
|
|
// var limits = await m_db_context.PlanetItemExchangeOrderAmountUserLimits
|
|
// .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);
|
|
// }
|
|
// }
|
|
//
|
|
// // 특정 사용자의 모든 교환 제한 조회
|
|
// public async Task<(Result, IEnumerable<PlanetItemExchangeOrderAmountUserLimit>?)> findByUser(
|
|
// string userGuid,
|
|
// int pageIndex = 1,
|
|
// int pageSize = 20,
|
|
// CancellationToken cancellationToken = default)
|
|
// {
|
|
// var result = new Result();
|
|
// try
|
|
// {
|
|
// var limits = await m_db_context.PlanetItemExchangeOrderAmountUserLimits
|
|
// .Where(x => x.UserGuid == userGuid)
|
|
// .OrderBy(x => x.ExchangeDate)
|
|
// .ThenBy(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);
|
|
// }
|
|
// }
|
|
|
|
public async Task increaseDailyAmount(PlanetItemExchangeOrderAmountUserLimit userLimit, int increaseAmount,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
userLimit.DailyAmount += increaseAmount;
|
|
var entry = m_db_context.Entry(userLimit);
|
|
entry.Property(x => x.DailyAmount).IsModified = true;
|
|
await update(userLimit, cancellationToken);
|
|
}
|
|
|
|
public async Task<(Result, PlanetItemExchangeOrderAmountUserLimit?)> findByExchangeMetaAndDateOrCreate(
|
|
string orderExchangeMetaId, string orderUserGuid, DateOnly exchangeDate, string orderSeasonId,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
var result = new Result();
|
|
try
|
|
{
|
|
var limit = await m_db_context.PlanetItemExchangeOrderAmountUserLimits
|
|
.Where(x =>
|
|
x.ExchangeMetaId == orderExchangeMetaId &&
|
|
x.ExchangeDate == exchangeDate &&
|
|
x.SeasonId == orderSeasonId &&
|
|
x.UserGuid == orderUserGuid)
|
|
.FirstOrDefaultAsync(cancellationToken);
|
|
|
|
if (limit is null)
|
|
{
|
|
limit = new PlanetItemExchangeOrderAmountUserLimit
|
|
{
|
|
ExchangeMetaId = orderExchangeMetaId,
|
|
UserGuid = orderUserGuid,
|
|
ExchangeDate = exchangeDate,
|
|
SeasonId = orderSeasonId,
|
|
DailyAmount = 0,
|
|
};
|
|
await add(limit, cancellationToken);
|
|
}
|
|
|
|
return (result, limit);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
result.setFail(ServerErrorCode.RdbError, e.Message);
|
|
return (result, null);
|
|
}
|
|
}
|
|
}
|