Skip to content

Commit

Permalink
Remove unused code and update method implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ricksu978 committed Jan 20, 2024
1 parent 612f7b6 commit b76bd1f
Show file tree
Hide file tree
Showing 25 changed files with 110 additions and 178 deletions.
2 changes: 0 additions & 2 deletions src/BackEnd/src/Core/Application/Common/IRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ public interface IRepository
Task SaveAsync(Game game);
void Save(Game game);


void Initialize();
}
13 changes: 13 additions & 0 deletions src/BackEnd/src/Infrastructure/InMemory/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.Extensions.DependencyInjection;
using Wsa.Gaas.Werewolf.Application.Common;

namespace Wsa.Gaas.Werewolf.InMemory;
public static class DependencyInjection
{
public static IServiceCollection AddInMemoryRepository(this IServiceCollection services)
{
services.AddSingleton<IRepository, InMemoryRepository>();

return services;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Wsa.Gaas.Werewolf.Application.Common;
using Wsa.Gaas.Werewolf.Domain.Objects;

namespace Wsa.Gaas.Werewolf.SqlServer;
namespace Wsa.Gaas.Werewolf.InMemory;
public class InMemoryRepository : IRepository
{
private readonly Dictionary<ulong, Game> _discordIdMemory = new();
Expand Down Expand Up @@ -36,10 +36,6 @@ public IQueryable<Game> FindAll()
return Task.FromResult(game);
}

public void Initialize()
{
}

public void Save(Game game)
{
if (game.Id == Guid.Empty)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\Core\Application\Wsa.Gaas.Werewolf.Application.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
namespace Wsa.Gaas.Werewolf.SqlServer;
public static class DependencyInjection
{
public static IServiceCollection AddEntityFrameworkCoreRepository(this IServiceCollection services)
public static IServiceCollection AddSqlServer(this IServiceCollection services)
{
//services.AddDbContext<IRepository, EntityFrameworkCoreRepository>(opt =>
//services.AddDbContext<IRepository, SqlServerRepository>(opt =>
//{
// opt.UseInMemoryDatabase(nameof(EntityFrameworkCoreRepository));
// //opt.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Integrated Security=true;Initial Catalog=TestDb");
// opt.UseSqlServer("Server=(localdb)\\MSSQLLocalDB;Integrated Security=true;Initial Catalog=TestDb");

// opt.EnableDetailedErrors();
// opt.EnableSensitiveDataLogging();
//});

services.AddSingleton<IRepository, InMemoryRepository>();

return services;
}
}
14 changes: 0 additions & 14 deletions src/BackEnd/src/Infrastructure/SqlServer/SqlServerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,4 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.ApplyConfigurationsFromAssembly(GetType().Assembly);
}

public void Initialize()
{
if (Database.IsInMemory())
{
Database.EnsureCreated();
}
else if (Database.IsSqlServer())
{
Database.Migrate();
}
}


}
5 changes: 4 additions & 1 deletion src/BackEnd/src/Presentation/WebApi/Common/WebApiEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ public abstract class WebApiEndpoint<TRequest, TResponse> : Endpoint<TRequest, T
{
public required UseCase<TRequest, TResponse> UseCase { get; set; }

public abstract override Task<TResponse> ExecuteAsync(TRequest req, CancellationToken ct);
public override Task<TResponse> ExecuteAsync(TRequest req, CancellationToken ct)
{
return UseCase.ExecuteAsync(req, ct);
}

}
13 changes: 9 additions & 4 deletions src/BackEnd/src/Presentation/WebApi/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,29 @@
using FastEndpoints.Swagger;
using Wsa.Gaas.Werewolf.Application.Common;
using Wsa.Gaas.Werewolf.Application.Options;
using Wsa.Gaas.Werewolf.InMemory;

namespace Wsa.Gaas.Werewolf.WebApi;
public static class DependencyInjection
{
public static IServiceCollection AddWebApi(this IServiceCollection services, IConfiguration configuration)
public static IServiceCollection AddWerewolfWebApi(this IServiceCollection services, IConfiguration configuration)
{
services
.AddExceptionHandler<GlobalExceptionHandler>()
.AddScoped<IGameEventHandler, GameEventHubHandler>()
.Configure<GameSettingOptions>(
opt => configuration.Bind(nameof(GameSettingOptions), opt)
)
.AddFastEndpoints()
.SwaggerDocument(
opt => { }
)
.SwaggerDocument(opt => { })
.AddSignalR()
;

return services;
}

public static IServiceCollection AddWerewolfInfrastructure(this IServiceCollection services)
{
return services.AddInMemoryRepository();
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;

public class ConfirmPlayerRoleEndpoint : WebApiEndpoint<ConfirmPlayerRoleRequest, ConfirmPlayerRoleResponse>
{
/// <summary>
/// Register API Route
/// </summary>
public override void Configure()
{
Get("/games/{DiscordVoiceChannelId}/players/{PlayerId}/Role");
AllowAnonymous();
}

/// <summary>
/// api request
/// </summary>
/// <param name="req"></param>
/// <param name="ct"></param>
/// <returns></returns>
public async override Task<ConfirmPlayerRoleResponse> ExecuteAsync(ConfirmPlayerRoleRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
public class CreateGameEndpoint : WebApiEndpoint<CreateGameRequest, CreateGameResponse>
{
public override void Configure()
{
Post("/games");
AllowAnonymous();
}

public override async Task<CreateGameResponse> ExecuteAsync(CreateGameRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
public class DiscoverPlayerRoleEndpoint : WebApiEndpoint<DiscoverPlayerRoleRequest, DiscoverPlayerRoleResponse>
{
public override void Configure()
{
Post("/games/{DiscordVoiceChannelId}/players/{PlayerId}/DiscoverRole");
AllowAnonymous();
}

public override async Task<DiscoverPlayerRoleResponse> ExecuteAsync(DiscoverPlayerRoleRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
public class EndGameEndpoint : WebApiEndpoint<EndGameRequest, EndGameResponse>
{
public override void Configure()
{
Post("/games/{DiscordVoiceChannelId}/end");
AllowAnonymous();
}

public override async Task<EndGameResponse> ExecuteAsync(EndGameRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;

public class GetGameEndpoint : WebApiEndpoint<GetGameRequest, GetGameResponse>
{
Expand All @@ -9,10 +7,4 @@ public override void Configure()
Get("/games/{DiscordVoiceChannelId}");
AllowAnonymous();
}

public override async Task<GetGameResponse> ExecuteAsync(GetGameRequest req, CancellationToken ct)
{
// 執行 UseCase.Execute();
return await UseCase.ExecuteAsync(req, ct);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;


public class PlayerTriggerSkillEndpoint : WebApiEndpoint<PlayerTriggerSkillRequest, PlayerTriggerSkillResponse>
Expand All @@ -11,9 +9,4 @@ public override void Configure()
AllowAnonymous();
}

public override async Task<PlayerTriggerSkillResponse> ExecuteAsync(PlayerTriggerSkillRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
public class StartGameEndpoint : WebApiEndpoint<StartGameRequest, StartGameResponse>
{
public override void Configure()
{
Post("/games/{DiscordVoiceChannelId}/start");
AllowAnonymous();
}

public override async Task<StartGameResponse> ExecuteAsync(StartGameRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
public class WerewolfVoteEndpoint : WebApiEndpoint<WerewolfVoteRequest, WerewolfVoteResponse>
{
public override void Configure()
{
Post("/games/{DiscordChannelId}/werewolf/vote");
AllowAnonymous();
}

public override async Task<WerewolfVoteResponse> ExecuteAsync(WerewolfVoteRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;
public class WitchUseAntidoteEndpoint : WebApiEndpoint<WitchUseAntidoteRequest, WitchUseAntidoteResponse>
{
public override void Configure()
{
Post("/games/{DiscordVoiceChannelId}/players/{playerId}:useAnitdote");
AllowAnonymous();
}

public override async Task<WitchUseAntidoteResponse> ExecuteAsync(WitchUseAntidoteRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}
}


Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Wsa.Gaas.Werewolf.WebApi.Common;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;

namespace Wsa.Gaas.Werewolf.WebApi.Endpoints;

public class WitchUsePoisonEndpoint : WebApiEndpoint<WitchUsePoisonRequest, WitchUsePoisonResponse>
{
Expand All @@ -10,10 +7,5 @@ public override void Configure()
Post("/games/{DiscordVoiceChannelId}/players/{playerId}:usePoison");
AllowAnonymous();
}

public override async Task<WitchUsePoisonResponse> ExecuteAsync(WitchUsePoisonRequest req, CancellationToken ct)
{
return await UseCase.ExecuteAsync(req, ct);
}
}

This file was deleted.

Loading

0 comments on commit b76bd1f

Please sign in to comment.