Skip to content

Commit

Permalink
refactor: 調整專案架構
Browse files Browse the repository at this point in the history
  • Loading branch information
aa89227 committed Jun 2, 2024
1 parent c1ac1ae commit 30ac443
Show file tree
Hide file tree
Showing 330 changed files with 636 additions and 622 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Application.Common;
namespace Monopoly.ApplicationLayer.Application.Common;

public abstract record BaseRequest;
public abstract record GameRequest(string GameId, string PlayerId): BaseRequest;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Monopoly.DomainLayer.Common;

namespace Application.Common;
namespace Monopoly.ApplicationLayer.Application.Common;

public interface IEventBus<TEvent> where TEvent : DomainEvent
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Application.Common;
namespace Monopoly.ApplicationLayer.Application.Common;

public interface IPresenter<TResponse>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Application.DataModels;
using Domain.Maps;
using Monopoly.ApplicationLayer.Application.DataModels;

namespace Application.Common;
namespace Monopoly.ApplicationLayer.Application.Common;

public interface IRepository
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
using Application.DataModels;
using Domain.Maps;

namespace Application.Common;

internal static class RepositoryExtensions
using Monopoly.ApplicationLayer.Application.DataModels;
using Monopoly.DomainLayer.Domain;
using Monopoly.DomainLayer.Domain.Builders;
using Monopoly.DomainLayer.Domain.Maps;
using Auction = Monopoly.ApplicationLayer.Application.DataModels.Auction;
using Block = Monopoly.ApplicationLayer.Application.DataModels.Block;
using Chess = Monopoly.ApplicationLayer.Application.DataModels.Chess;
using CurrentPlayerState = Monopoly.ApplicationLayer.Application.DataModels.CurrentPlayerState;
using GameStage = Monopoly.DomainLayer.Domain.GameStage;
using Jail = Monopoly.DomainLayer.Domain.Jail;
using Land = Monopoly.DomainLayer.Domain.Land;
using LandContract = Monopoly.ApplicationLayer.Application.DataModels.LandContract;
using Map = Monopoly.ApplicationLayer.Application.DataModels.Map;
using ParkingLot = Monopoly.DomainLayer.Domain.ParkingLot;
using Player = Monopoly.ApplicationLayer.Application.DataModels.Player;
using Road = Monopoly.DomainLayer.Domain.Road;
using StartPoint = Monopoly.DomainLayer.Domain.StartPoint;
using Station = Monopoly.DomainLayer.Domain.Station;

namespace Monopoly.ApplicationLayer.Application.Common;

public static class RepositoryExtensions
{
internal static string Save(this IRepository repository, Domain.MonopolyAggregate domainMonopolyAggregate)
public static string Save(this IRepository repository, MonopolyAggregate domainMonopolyAggregate)
{
var monopoly = domainMonopolyAggregate.ToApplication();
return repository.Save(monopoly);
Expand All @@ -16,7 +32,7 @@ internal static string Save(this IRepository repository, Domain.MonopolyAggregat
/// </summary>
/// <param name="domainMonopolyAggregate"></param>
/// <returns></returns>
private static MonopolyDataModel ToApplication(this Domain.MonopolyAggregate domainMonopolyAggregate)
private static MonopolyDataModel ToApplication(this MonopolyAggregate domainMonopolyAggregate)
{
var players = domainMonopolyAggregate.Players.Select(player =>
{
Expand Down Expand Up @@ -44,11 +60,11 @@ private static MonopolyDataModel ToApplication(this Domain.MonopolyAggregate dom
);
var gamestage = domainMonopolyAggregate.GameStage switch
{
Domain.GameStage.Ready => GameStage.Preparing,
Domain.GameStage.Gaming => GameStage.Gaming,
GameStage.Ready => DataModels.GameStage.Preparing,
GameStage.Gaming => DataModels.GameStage.Gaming,
_ => throw new NotImplementedException(),
};
if (gamestage == GameStage.Preparing)
if (gamestage == DataModels.GameStage.Preparing)
{
return new MonopolyDataModel(domainMonopolyAggregate.Id, [..players], map, domainMonopolyAggregate.HostId, null!,
null!, gamestage);
Expand All @@ -69,7 +85,7 @@ domainMonopolyAggregate.CurrentPlayerState.Auction is null
domainMonopolyAggregate.CurrentPlayerState.RemainingSteps,
domainMonopolyAggregate.CurrentPlayerState.HadSelectedDirection
);
var LandHouses = domainMonopolyAggregate.Map.Blocks.SelectMany(block => block).OfType<Domain.Land>()
var LandHouses = domainMonopolyAggregate.Map.Blocks.SelectMany(block => block).OfType<Land>()
.Where(land => land.House > 0)
.Select(land => new LandHouse(land.Id, land.House)).ToArray();

Expand All @@ -78,16 +94,16 @@ domainMonopolyAggregate.CurrentPlayerState.Auction is null
currentPlayerState, LandHouses, gamestage);
}

private static Block ToApplicationBlock(this Domain.Block domainBlock)
private static Block ToApplicationBlock(this DomainLayer.Domain.Block domainBlock)
{
return domainBlock switch
{
Domain.StartPoint startBlock => new StartPoint(startBlock.Id),
Domain.Station stationBlock => new Station(stationBlock.Id),
Domain.Land landBlock => new Land(landBlock.Id),
Domain.ParkingLot parkingLotBlock => new ParkingLot(parkingLotBlock.Id),
Domain.Jail prisonBlock => new Jail(prisonBlock.Id),
Domain.Road roadBlock => new Road(roadBlock.Id),
StartPoint startBlock => new DataModels.StartPoint(startBlock.Id),
Station stationBlock => new DataModels.Station(stationBlock.Id),
Land landBlock => new DataModels.Land(landBlock.Id),
ParkingLot parkingLotBlock => new DataModels.ParkingLot(parkingLotBlock.Id),
Jail prisonBlock => new DataModels.Jail(prisonBlock.Id),
Road roadBlock => new DataModels.Road(roadBlock.Id),
null => new EmptyBlock(),
_ => throw new NotImplementedException(),
};
Expand All @@ -98,16 +114,16 @@ private static Block ToApplicationBlock(this Domain.Block domainBlock)
/// </summary>
/// <param name="monopolyDataModel"></param>
/// <returns></returns>
internal static Domain.MonopolyAggregate ToDomain(this MonopolyDataModel monopolyDataModel)
public static MonopolyAggregate ToDomain(this MonopolyDataModel monopolyDataModel)
{
//Domain.Map map = new(monopoly.Map.Id, monopoly.Map.Blocks
// .Select(row =>
// {
// return row.Select(block => block?.ToDomainBlock()).ToArray();
// }).ToArray()
// );
Domain.Map map = new SevenXSevenMap();
var builder = new Domain.Builders.MonopolyBuilder()
DomainLayer.Domain.Map map = new SevenXSevenMap();
var builder = new MonopolyBuilder()
.WithId(monopolyDataModel.Id)
.WithHost(monopolyDataModel.HostId)
.WithMap(map);
Expand All @@ -123,11 +139,11 @@ internal static Domain.MonopolyAggregate ToDomain(this MonopolyDataModel monopol
));
builder.WithGameStage(monopolyDataModel.GameStage switch
{
GameStage.Preparing => Domain.GameStage.Ready,
GameStage.Gaming => Domain.GameStage.Gaming,
DataModels.GameStage.Preparing => GameStage.Ready,
DataModels.GameStage.Gaming => GameStage.Gaming,
_ => throw new NotImplementedException(),
});
if (monopolyDataModel.GameStage == GameStage.Preparing)
if (monopolyDataModel.GameStage == DataModels.GameStage.Preparing)
{
return builder.Build();
}
Expand All @@ -151,7 +167,7 @@ internal static Domain.MonopolyAggregate ToDomain(this MonopolyDataModel monopol
return builder.Build();
}

private static Domain.Builders.PlayerBuilder WithLandContracts(this Domain.Builders.PlayerBuilder builder,
private static PlayerBuilder WithLandContracts(this PlayerBuilder builder,
LandContract[] landContracts)
{
landContracts.ToList().ForEach(landContract =>
Expand All @@ -161,29 +177,29 @@ private static Domain.Builders.PlayerBuilder WithLandContracts(this Domain.Build
return builder;
}

private static Domain.Block? ToDomainBlock(this Block? block)
private static DomainLayer.Domain.Block? ToDomainBlock(this Block? block)
{
return block switch
{
StartPoint startBlock => new Domain.StartPoint(startBlock.Id),
Station stationBlock => new Domain.Station(stationBlock.Id),
Land landBlock => new Domain.Land(landBlock.Id),
ParkingLot parkingLotBlock => new Domain.ParkingLot(parkingLotBlock.Id),
Jail prisonBlock => new Domain.Jail(prisonBlock.Id),
Road roadBlock => new Domain.Road(roadBlock.Id),
DataModels.StartPoint startBlock => new StartPoint(startBlock.Id),
DataModels.Station stationBlock => new Station(stationBlock.Id),
DataModels.Land landBlock => new Land(landBlock.Id),
DataModels.ParkingLot parkingLotBlock => new ParkingLot(parkingLotBlock.Id),
DataModels.Jail prisonBlock => new Jail(prisonBlock.Id),
DataModels.Road roadBlock => new Road(roadBlock.Id),
EmptyBlock => null,
_ => throw new NotImplementedException(),
};
}

private static Direction ToApplicationDirection(this Domain.Map.Direction direction)
private static Direction ToApplicationDirection(this DomainLayer.Domain.Map.Direction direction)
{
return direction switch
{
Domain.Map.Direction.Up => Direction.Up,
Domain.Map.Direction.Down => Direction.Down,
Domain.Map.Direction.Left => Direction.Left,
Domain.Map.Direction.Right => Direction.Right,
DomainLayer.Domain.Map.Direction.Up => Direction.Up,
DomainLayer.Domain.Map.Direction.Down => Direction.Down,
DomainLayer.Domain.Map.Direction.Left => Direction.Left,
DomainLayer.Domain.Map.Direction.Right => Direction.Right,
_ => throw new NotImplementedException(),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Domain.Common;
using Monopoly.DomainLayer.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Common;
namespace Monopoly.ApplicationLayer.Application.Common;

public abstract record Response();
public abstract record CommandResponse(IReadOnlyList<DomainEvent> Events) : Response;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Monopoly.DomainLayer.Common;

namespace Application.Common;
namespace Monopoly.ApplicationLayer.Application.Common;

public abstract class Usecase<TRequest, TResponse>()
where TRequest : BaseRequest where TResponse : Response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
namespace Application.DataModels;
using Monopoly.DomainLayer.Domain;

namespace Monopoly.ApplicationLayer.Application.DataModels;

public record MonopolyDataModel(string Id, Player[] Players, Map Map, string HostId, CurrentPlayerState CurrentPlayerState, LandHouse[] LandHouses, GameStage GameStage);

public record Player(string Id, decimal Money, Chess Chess, LandContract[] LandContracts, Domain.PlayerState PlayerState, int BankruptRounds, int LocationId, string? RoleId);
public record Player(string Id, decimal Money, Chess Chess, LandContract[] LandContracts, PlayerState PlayerState, int BankruptRounds, int LocationId, string? RoleId);
public record CurrentPlayerState(string PlayerId, bool IsPayToll, bool IsBoughtLand, bool IsUpgradeLand, Auction? Auction, int RemainingSteps, bool HadSelectedDirection);
public record Chess(string CurrentPosition, Direction Direction);
public record LandContract(string LandId, bool InMortgage, int Deadline);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Monopoly.ApplicationLayer.Application.Common;

namespace Application;
namespace Monopoly.ApplicationLayer.Application;

public static class DependencyInjection
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DomainLayer\Monopoly.DomainLayer.ReadyRoom\Monopoly.DomainLayer.ReadyRoom.csproj" />
<ProjectReference Include="..\Domain\Domain.csproj" />
<ProjectReference Include="..\..\DomainLayer\Monopoly.DomainLayer.Domain\Monopoly.DomainLayer.Domain.csproj" />
<ProjectReference Include="..\..\DomainLayer\Monopoly.DomainLayer.ReadyRoom\Monopoly.DomainLayer.ReadyRoom.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Application.Common;
using Application.Usecases.ReadyRoom;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.ApplicationLayer.Application.Usecases.ReadyRoom;
using Monopoly.DomainLayer.ReadyRoom;

namespace Application.Queries;
namespace Monopoly.ApplicationLayer.Application.Queries;

public record GetReadyRoomInfosRequest(string GameId, string PlayerId)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record BidRequest(string GameId, string PlayerId, decimal BidPrice)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record BuildHouseRequest(string GameId, string PlayerId)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record ChooseDirectionRequest(string GameId, string PlayerId, string Direction)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Application.Common;
using Domain.Builders;
using Domain.Maps;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;
using Monopoly.DomainLayer.Domain.Builders;
using Monopoly.DomainLayer.Domain.Maps;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record CreateGameRequest(string HostId, string[] PlayerIds) : GameRequest(null!, HostId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record EndAuctionRequest(string GameId, string PlayerId)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record EndRoundRequest(string GameId, string PlayerId)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record MortgageRequest(string GameId, string PlayerId, string BlockId)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record PayTollRequest(string GameId, string PlayerId)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record PlayerBuyLandRequest(string GameId, string PlayerId, string LandID)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.Common;

namespace Application.Usecases;
namespace Monopoly.ApplicationLayer.Application.Usecases;

public record PlayerRollDiceRequest(string GameId, string PlayerId)
: GameRequest(GameId, PlayerId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Application.Common;
using Monopoly.ApplicationLayer.Application.Common;
using Monopoly.DomainLayer.ReadyRoom;

namespace Application.Usecases.ReadyRoom;
namespace Monopoly.ApplicationLayer.Application.Usecases.ReadyRoom;

public record CreateReadyRoomRequest(string PlayerId) : BaseRequest;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Monopoly.DomainLayer.ReadyRoom;

namespace Application.Usecases.ReadyRoom;
namespace Monopoly.ApplicationLayer.Application.Usecases.ReadyRoom;

public interface IReadyRoomRepository
{
Expand Down
Loading

0 comments on commit 30ac443

Please sign in to comment.