1
0
mirror of synced 2024-11-27 15:40:49 +01:00

Update commands, add option to aggregate

This commit is contained in:
asesidaa 2023-02-13 02:12:26 +08:00
parent 14f171792e
commit 1db9fdf6d3
22 changed files with 76 additions and 52 deletions

View File

@ -23,10 +23,8 @@ public class AvatarDto
public string Modified { get; set; } = string.Empty;
[XmlElement("new_flag")]
[DefaultValue(1)]
public int NewFlag { get; set; } = 1;
public int NewFlag { get; set; }
[XmlElement("use_flag")]
[DefaultValue(1)]
public int UseFlag { get; set; } = 1;
public int UseFlag { get; set; }
}

View File

@ -1,15 +1,20 @@
using Application.Interfaces;
using Domain.Config;
using Microsoft.Extensions.Options;
namespace Application.Game.Card;
public class CardDependencyAggregate : ICardDependencyAggregate
{
public CardDependencyAggregate(ICardDbContext cardDbContext, IMusicDbContext musicDbContext)
public CardDependencyAggregate(ICardDbContext cardDbContext, IMusicDbContext musicDbContext, IOptions<GameConfig> options)
{
CardDbContext = cardDbContext;
MusicDbContext = musicDbContext;
Options = options;
}
public ICardDbContext CardDbContext { get; }
public IMusicDbContext MusicDbContext { get; }
public IOptions<GameConfig> Options { get; }
}

View File

@ -1,20 +1,25 @@
using Application.Common.Models;
using Application.Interfaces;
using Domain.Config;
using MediatR;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Application.Game.Card;
public abstract class CardRequestHandlerBase<TIn, TOut>: IRequestHandlerWrapper<TIn, TOut>
where TIn : IRequestWrapper<TOut>
{
public ICardDbContext CardDbContext { get; }
public IMusicDbContext MusicDbContext { get; }
protected ICardDbContext CardDbContext { get; }
protected IMusicDbContext MusicDbContext { get; }
protected GameConfig Config { get; }
public CardRequestHandlerBase(ICardDependencyAggregate aggregate)
{
CardDbContext = aggregate.CardDbContext;
MusicDbContext = aggregate.MusicDbContext;
Config = aggregate.Options.Value;
}
public abstract Task<ServiceResult<TOut>> Handle(TIn request, CancellationToken cancellationToken);

View File

@ -15,17 +15,14 @@ public record ReadAvatarQuery(long CardId) : IRequestWrapper<string>;
public class ReadAvatarQueryHandler : CardRequestHandlerBase<ReadAvatarQuery, string>
{
private const string AVATAR_XPATH = "/root/avatar/record";
private readonly GameConfig config;
public ReadAvatarQueryHandler(ICardDependencyAggregate aggregate, IOptions<GameConfig> options) : base(aggregate)
public ReadAvatarQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
config = options.Value;
}
public override Task<ServiceResult<string>> Handle(ReadAvatarQuery request, CancellationToken cancellationToken)
{
var count = config.AvatarCount;
var count = Config.AvatarCount;
var list = new List<AvatarDto>();
for (int i = 0; i < count; i++)
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadCardBDataQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadCardBDataQuery(long CardId) : IRequestWrapper<string>;
public class ReadCardBDataQueryHandler : CardRequestHandlerBase<ReadCardBDataQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadCoinQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadCoinQuery(long CardId) : IRequestWrapper<string>;
public class ReadCoinQueryHandler : CardRequestHandlerBase<ReadCoinQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadCondQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadCondQuery(long CardId) : IRequestWrapper<string>;
public class ReadCondQueryHandler : CardRequestHandlerBase<ReadCondQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadEventRewardQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadEventRewardQuery(long CardId) : IRequestWrapper<string>;
public class ReadEventRewardQueryHandler : CardRequestHandlerBase<ReadEventRewardQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadGetMessageQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadGetMessageQuery(long CardId) : IRequestWrapper<string>;
public class ReadGetMessageQueryHandler : CardRequestHandlerBase<ReadGetMessageQuery, string>
{

View File

@ -14,21 +14,18 @@ public record ReadItemQuery(long CardId) : IRequestWrapper<string>;
public class ReadItemQueryHandler : CardRequestHandlerBase<ReadItemQuery, string>
{
private const string ITEM_XPATH = "/root/item/record";
private readonly GameConfig config;
public ReadItemQueryHandler(ICardDependencyAggregate aggregate, IOptions<GameConfig> options) : base(aggregate)
public ReadItemQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
config = options.Value;
}
public override Task<ServiceResult<string>> Handle(ReadItemQuery request, CancellationToken cancellationToken)
{
var count = config.AvatarCount;
var count = Config.ItemCount;
var list = new List<ItemDto>();
for (int i = 0; i < count; i++)
{
var avatar = new ItemDto()
var item = new ItemDto
{
Id = i,
CardId = request.CardId,
@ -39,7 +36,7 @@ public class ReadItemQueryHandler : CardRequestHandlerBase<ReadItemQuery, string
NewFlag = 0,
UseFlag = 1
};
list.Add(avatar);
list.Add(item);
}
var result = list.SerializeCardDataList(ITEM_XPATH);

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadMusicAouQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadMusicAouQuery(long CardId) : IRequestWrapper<string>;
public class ReadMusicAouQueryHandler : CardRequestHandlerBase<ReadMusicAouQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadMusicExtraQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadMusicExtraQuery(long CardId) : IRequestWrapper<string>;
public class ReadMusicExtraQueryHandler : CardRequestHandlerBase<ReadMusicExtraQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadMusicQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadMusicQuery(long CardId) : IRequestWrapper<string>;
public class ReadMusicQueryHandler : CardRequestHandlerBase<ReadMusicQuery, string>
{

View File

@ -1,16 +1,19 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
using Domain.Config;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace Application.Game.Card.Read;
public record ReadNavigatorQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadNavigatorQuery(long CardId) : IRequestWrapper<string>;
public class ReadNavigatorQueryHandler : CardRequestHandlerBase<ReadNavigatorQuery, string>
{
public ReadNavigatorQueryHandler(ICardDependencyAggregate aggregate) : base(aggregate)
{
}

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadSkinQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadSkinQuery(long CardId) : IRequestWrapper<string>;
public class ReadSkinQueryHandler : CardRequestHandlerBase<ReadSkinQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadSoundEffectQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadSoundEffectQuery(long CardId) : IRequestWrapper<string>;
public class ReadSoundEffectQueryHandler : CardRequestHandlerBase<ReadSoundEffectQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadTitleQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadTitleQuery(long CardId) : IRequestWrapper<string>;
public class ReadTitleQueryHandler : CardRequestHandlerBase<ReadTitleQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadTotalTrophyQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadTotalTrophyQuery(long CardId) : IRequestWrapper<string>;
public class ReadTotalTrophyQueryHandler : CardRequestHandlerBase<ReadTotalTrophyQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadUnlockKeynumQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadUnlockKeynumQuery(long CardId) : IRequestWrapper<string>;
public class ReadUnlockKeynumQueryHandler : CardRequestHandlerBase<ReadUnlockKeynumQuery, string>
{

View File

@ -7,7 +7,7 @@ using Microsoft.EntityFrameworkCore;
namespace Application.Game.Card.Read;
public record ReadUnlockRewardQuery(long CardId, string Data) : IRequestWrapper<string>;
public record ReadUnlockRewardQuery(long CardId) : IRequestWrapper<string>;
public class ReadUnlockRewardQueryHandler : CardRequestHandlerBase<ReadUnlockRewardQuery, string>
{

View File

@ -1,4 +1,6 @@
using Microsoft.Extensions.Logging;
using Domain.Config;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Application.Interfaces;
@ -6,4 +8,6 @@ public interface ICardDependencyAggregate
{
ICardDbContext CardDbContext { get; }
IMusicDbContext MusicDbContext { get; }
IOptions<GameConfig> Options { get; }
}

View File

@ -5,7 +5,6 @@ using Application.Game.Card.Management;
using Application.Game.Card.Read;
using Application.Game.Card.Session;
using Application.Game.Card.Write;
using Domain;
using Domain.Enums;
using Microsoft.AspNetCore.Mvc;
using Throw;
@ -47,39 +46,55 @@ public class CardController : BaseController<CardController>
result = await Mediator.Send(new ReadAllCardDetailsQuery(request.CardId));
break;
case CardRequestType.ReadCardBData:
result = await Mediator.Send(new ReadCardBDataQuery(request.CardId));
break;
case CardRequestType.ReadAvatar:
result = await Mediator.Send(new ReadAvatarQuery(request.CardId));
break;
case CardRequestType.ReadItem:
result = await Mediator.Send(new ReadItemQuery(request.CardId));
break;
case CardRequestType.ReadSkin:
result = await Mediator.Send(new ReadSkinQuery(request.CardId));
break;
case CardRequestType.ReadTitle:
break;
case CardRequestType.ReadMusic:
break;
case CardRequestType.ReadEventReward:
result = await Mediator.Send(new ReadTitleQuery(request.CardId));
break;
case CardRequestType.ReadNavigator:
break;
case CardRequestType.ReadMusicExtra:
break;
case CardRequestType.ReadMusicAou:
break;
case CardRequestType.ReadCoin:
break;
case CardRequestType.ReadUnlockReward:
break;
case CardRequestType.ReadUnlockKeynum:
result = await Mediator.Send(new ReadNavigatorQuery(request.CardId));
break;
case CardRequestType.ReadSoundEffect:
result = await Mediator.Send(new ReadSoundEffectQuery(request.CardId));
break;
case CardRequestType.ReadMusic:
result = await Mediator.Send(new ReadMusicQuery(request.CardId));
break;
case CardRequestType.ReadMusicAou:
result = await Mediator.Send(new ReadMusicAouQuery(request.CardId));
break;
case CardRequestType.ReadMusicExtra:
result = await Mediator.Send(new ReadMusicExtraQuery(request.CardId));
break;
case CardRequestType.ReadEventReward:
result = await Mediator.Send(new ReadEventRewardQuery(request.CardId));
break;
case CardRequestType.ReadCoin:
result = await Mediator.Send(new ReadCoinQuery(request.CardId));
break;
case CardRequestType.ReadUnlockReward:
result = await Mediator.Send(new ReadUnlockRewardQuery(request.CardId));
break;
case CardRequestType.ReadUnlockKeynum:
result = await Mediator.Send(new ReadUnlockKeynumQuery(request.CardId));
break;
case CardRequestType.ReadGetMessage:
result = await Mediator.Send(new ReadGetMessageQuery(request.CardId));
break;
case CardRequestType.ReadCond:
result = await Mediator.Send(new ReadCondQuery(request.CardId));
break;
case CardRequestType.ReadTotalTrophy:
result = await Mediator.Send(new ReadTotalTrophyQuery(request.CardId));
break;
case CardRequestType.GetSession:
case CardRequestType.StartSession: