Skip to content

Commit

Permalink
T #98 renames and shareded model proto [not compiling]
Browse files Browse the repository at this point in the history
  • Loading branch information
HueByte committed Sep 23, 2022
1 parent 082a0a5 commit a97490b
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 76 deletions.
8 changes: 2 additions & 6 deletions src/Huppy/Huppy.App/Configuration/ModuleConfigurator.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using Grpc.Net.Client;
using Huppy.App.Middlewares;
using Huppy.Core.Extensions;
using Huppy.Core.Interfaces.IRepositories;
Expand All @@ -27,11 +26,8 @@
using Huppy.Core.Services.Urban;
using Huppy.Infrastructure;
using Huppy.Infrastructure.Repositories;
using HuppyService.Service.Protos;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Serilog;
using CommandLog = HuppyService.Service.Protos.CommandLog;

namespace Huppy.App.Configuration
{
Expand All @@ -58,13 +54,13 @@ public ModuleConfigurator AddAppSettings(AppSettings? settings = null)

public ModuleConfigurator AddGRPCServices()
{
_services.AddGrpcClient<GPT.GPTClient>((services, options) =>
_services.AddGrpcClient<GPTProto.GPTProtoClient>((services, options) =>
{
//var basketApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.HuppyCoreUrl;
options.Address = new Uri(_appSettings?.Microservices?.HuppyCoreUrl!);
});

_services.AddGrpcClient<CommandLog.CommandLogClient>((services, options) =>
_services.AddGrpcClient<CommandLogProto.CommandLogProtoClient>((services, options) =>
{
options.Address = new Uri(_appSettings?.Microservices?.HuppyCoreUrl!);
});
Expand Down
4 changes: 0 additions & 4 deletions src/Huppy/Huppy.App/Middlewares/CommandLogMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System.Diagnostics;
using Discord.Interactions;
using Huppy.Core.Interfaces;
using Huppy.Core.Interfaces.IRepositories;
using Huppy.Core.Interfaces.IServices;
using Huppy.Core.Utilities;
using Huppy.Kernel;
using HuppyService.Service.Protos;
using Microsoft.Extensions.Logging;

namespace Huppy.App.Middlewares
Expand Down
11 changes: 9 additions & 2 deletions src/Huppy/Huppy.Core/Huppy.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<HuppyCoreProtoRoot></HuppyCoreProtoRoot>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.18.0" />
Expand All @@ -25,11 +26,17 @@
<ProjectReference Include="..\Huppy.Kernel\Huppy.Kernel.csproj" />
</ItemGroup>
<ItemGroup>
<Protobuf Include="..\..\HuppyService\HuppyService.Service\Protos\commandLog.proto" GrpcServices="Client">
<Protobuf Include="..\..\HuppyService\HuppyService.Service\Protos\commandLog.proto" GrpcServices="Client" ProtoRoot="../../HuppyService/HuppyService.Service/Protos/">
<Link>Protos\commandLog.proto</Link>
</Protobuf>
<Protobuf Include="..\..\HuppyService\HuppyService.Service\Protos\gpt.proto" GrpcServices="Client">
<Protobuf Include="..\..\HuppyService\HuppyService.Service\Protos\gpt.proto" GrpcServices="Client" ProtoRoot="../../HuppyService/HuppyService.Service/Protos/">
<Link>Protos\gpt.proto</Link>
</Protobuf>
<Protobuf Include="..\..\HuppyService\HuppyService.Service\Protos\models\database.proto" GrpcServices="Client" ProtoRoot="../../HuppyService/HuppyService.Service/Protos/">
<Link>Protos\database.proto</Link>
</Protobuf>
<Protobuf Include="..\..\HuppyService\HuppyService.Service\Protos\server.proto" GrpcServices="Client" ProtoRoot="../../HuppyService/HuppyService.Service/Protos/">
<Link>Protos\server.proto</Link>
</Protobuf>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface ICommandLogService
Task<int> GetCount();
Task<double> GetAverageExecutionTime();
Task<MapField<ulong, int>> GetAiUsage();
Task<CommandLogModelResponse> AddCommand(CommandLogModel model);
Task<CommandLogModel> AddCommand(CommandLogModel model);
Task<bool> RemoveCommand(CommandLogModel model);
}
}
14 changes: 7 additions & 7 deletions src/Huppy/Huppy.Core/Services/CommandLog/CommandLogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@ namespace Huppy.Core.Services.CommandLog
{
public class CommandLogService : ICommandLogService
{
private readonly HuppyService.Service.Protos.CommandLog.CommandLogClient _commandLogClient;
public CommandLogService(HuppyService.Service.Protos.CommandLog.CommandLogClient commandLogClient)
private readonly HuppyService.Service.Protos.CommandLogProto.CommandLogProtoClient _commandLogClient;
public CommandLogService(HuppyService.Service.Protos.CommandLogProto.CommandLogProtoClient commandLogClient)
{
_commandLogClient = commandLogClient;
}

public async Task<CommandLogModelResponse> AddCommand(CommandLogModel commandLog)
public async Task<CommandLogModel> AddCommand(CommandLogModel commandLog)
{
var result = await _commandLogClient.AddCommandAsync(commandLog);

return result;
}

public async Task<MapField<ulong, int>> GetAiUsage()
{
// implement single instance of empty?
var result = await _commandLogClient.GetAiUsageAsync(new Empty());

return result.AiUsers;
}

public async Task<double> GetAverageExecutionTime()
{
var result = await _commandLogClient.GetAverageExecutionTimeAsync(new Empty());

return result.AverageTime;
}

public async Task<int> GetCount()
{
var result = await _commandLogClient.GetCountAsync(new Empty());

return result.Count;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Huppy/Huppy.Core/Services/GPT/GPTService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public class GPTService : IGPTService
private readonly IHttpClientFactory _clientFactory;
private readonly ILogger _logger;
private readonly AppSettings _settings;
private readonly HuppyService.Service.Protos.GPT.GPTClient _gptClient;
public GPTService(HuppyService.Service.Protos.GPT.GPTClient gptClient, IHttpClientFactory clientFactory, ILogger<GPTService> logger, AppSettings settings)
private readonly HuppyService.Service.Protos.GPTProto.GPTProtoClient _gptClient;
public GPTService(HuppyService.Service.Protos.GPTProto.GPTProtoClient gptClient, IHttpClientFactory clientFactory, ILogger<GPTService> logger, AppSettings settings)
{
_gptClient = gptClient;
_clientFactory = clientFactory;
Expand Down
21 changes: 12 additions & 9 deletions src/Huppy/Huppy.sln
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
# Visual Studio Version 17
VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Huppy.App", "Huppy.App\Huppy.App.csproj", "{63A53A9E-3A99-47A7-BC56-757C4C484789}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Huppy.App", "Huppy.App\Huppy.App.csproj", "{63A53A9E-3A99-47A7-BC56-757C4C484789}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Huppy.Core", "Huppy.Core\Huppy.Core.csproj", "{24DBA258-A21A-4C73-B2E4-1F095F6629D2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Huppy.Core", "Huppy.Core\Huppy.Core.csproj", "{24DBA258-A21A-4C73-B2E4-1F095F6629D2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Huppy.Infrastructure", "Huppy.Infrastructure\Huppy.Infrastructure.csproj", "{63DCCC50-7380-445C-AF41-3DBD2A7FE953}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Huppy.Infrastructure", "Huppy.Infrastructure\Huppy.Infrastructure.csproj", "{63DCCC50-7380-445C-AF41-3DBD2A7FE953}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Huppy.Kernel", "Huppy.Kernel\Huppy.Kernel.csproj", "{DFC4F96F-AAD1-406B-B9C7-21CC2FAF19DE}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Huppy.Kernel", "Huppy.Kernel\Huppy.Kernel.csproj", "{DFC4F96F-AAD1-406B-B9C7-21CC2FAF19DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{63A53A9E-3A99-47A7-BC56-757C4C484789}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{63A53A9E-3A99-47A7-BC56-757C4C484789}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand All @@ -37,4 +34,10 @@ Global
{DFC4F96F-AAD1-406B-B9C7-21CC2FAF19DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DFC4F96F-AAD1-406B-B9C7-21CC2FAF19DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {36D3F2A9-4A13-4B10-AF99-49448449FF3D}
EndGlobalSection
EndGlobal
2 changes: 1 addition & 1 deletion src/HuppyService/HuppyService.Core/Models/ServerRooms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ServerRooms : DbModel<ulong>
public ulong GreetingRoom { get; set; }

[ForeignKey("ServerId")]
public ulong? ServerID { get; set; }
public ulong? ServerId { get; set; }
public virtual Server? Server { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<Protobuf Include="Protos\commandLog.proto" GrpcServices="Server" />
<Protobuf Include="Protos\gpt.proto" GrpcServices="Server" />
<Protobuf Include="Protos\greet.proto" GrpcServices="Server" />
<Protobuf Include="Protos\models\database.proto" GrpcServices="Server" />
<Protobuf Include="Protos\server.proto" GrpcServices="Server" />
</ItemGroup>

<ItemGroup>
Expand Down
32 changes: 5 additions & 27 deletions src/HuppyService/HuppyService.Service/Protos/commandLog.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ syntax = "proto3";
option csharp_namespace = "HuppyService.Service.Protos";

import "google/protobuf/empty.proto";
import "Protos/models/database.proto";

package CommandLog;
package CommandLogProto;

service CommandLog {
service CommandLogProto {
rpc GetCount(google.protobuf.Empty) returns (CommandLogCount);
rpc GetAverageExecutionTime(google.protobuf.Empty) returns (AverageTimeResponse);
rpc GetAiUsage(google.protobuf.Empty) returns (AiUsageResponse);
rpc AddCommand(CommandLogModel) returns (CommandLogModelResponse);
rpc RemoveCommand(CommandLogModel) returns (CommandLogResponse);
rpc AddCommand(database.models.CommandLogModel) returns (database.models.CommandLogModel);
rpc RemoveCommand(database.models.CommandLogModel) returns (CommandLogResponse);
}

message CommandLogCount {
Expand All @@ -26,29 +27,6 @@ message AiUsageResponse {
map<uint64, int32> AiUsers = 1;
}

message CommandLogModel {
string CommandName = 1;
uint64 UnixTime = 2;
bool IsSuccess = 3;
uint64 UserId = 4;
int64 ExecutionTimeMs = 5;
uint64 ChannelId = 6;
string ErrorMessage = 7;
uint64 GuildId = 8;
}

message CommandLogModelResponse {
int32 Id = 1;
string CommandName = 2;
uint64 UnixTime = 3;
bool IsSuccess = 4;
uint64 UserId = 5;
int64 ExecutionTimeMs = 6;
uint64 ChannelId = 7;
string ErrorMessage = 8;
uint64 GuildId = 9;
}

message CommandLogResponse {
bool IsSuccess = 1;
}
4 changes: 2 additions & 2 deletions src/HuppyService/HuppyService.Service/Protos/gpt.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ syntax = "proto3";

option csharp_namespace = "HuppyService.Service.Protos";

package GPT;
package GPTProto;

service GPT {
service GPTProto {
rpc DavinciCompletion(GPTInputRequest) returns (GPTOutputResponse);
}

Expand Down
34 changes: 34 additions & 0 deletions src/HuppyService/HuppyService.Service/Protos/models/database.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
syntax = "proto3";

option csharp_namespace = "HuppyService.Service.Protos.Models";

package database.models;

message CommandLogModel {
int32 Id = 1;
string CommandName = 2;
uint64 UnixTime = 3;
bool IsSuccess = 4;
uint64 UserId = 5;
int64 ExecutionTimeMs = 6;
uint64 ChannelId = 7;
string ErrorMessage = 8;
uint64 GuildId = 9;
}

message ServerModel {
uint64 Id = 1;
string ServerName = 2;
bool UseGreet = 3;
string GreetMessage = 4;
uint64 RoleId = 5;
uint64 ServerRommsId = 6;
ServerRoomsModel Rooms = 7;
}

message ServerRoomsModel {
uint64 Id = 1;
uint64 OutputRoom = 2;
uint64 GreetingRoom = 3;
uint64 ServerId = 4;
}
28 changes: 28 additions & 0 deletions src/HuppyService/HuppyService.Service/Protos/server.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
syntax = "proto3";

option csharp_namespace = "HuppyService.Service.Protos";

import "google/protobuf/empty.proto";
import "Protos/models/database.proto";

package ServerProto;

service ServerProto {
rpc GetOrCreate(GetOrCreateServerInput) returns (database.models.ServerModel);
rpc UpdateAsync(database.models.ServerModel) returns(ServerProtoDefaultResponse);
rpc GetAll(google.protobuf.Empty) returns (ServerModelCollection);
}

message ServerModelCollection {
repeated database.models.ServerModel ServerModel= 1;
}

message GetOrCreateServerInput {
uint64 Id = 1;
string ServerName = 2;
uint64 DefaultChannel = 3;
}

message ServerProtoDefaultResponse {
bool IsSuccess = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
using HuppyService.Core.Interfaces.IRepositories;
using HuppyService.Core.Utilities;
using HuppyService.Service.Protos;
using HuppyService.Service.Protos.Models;
using Microsoft.EntityFrameworkCore;

namespace HuppyService.Service.Services
{
public class CommandLogService : CommandLog.CommandLogBase
public class CommandLogService : CommandLogProto.CommandLogProtoBase
{
private readonly ICommandLogRepository _commandLogRepository;
public CommandLogService(ICommandLogRepository commandLogRepository)
Expand Down Expand Up @@ -53,7 +54,7 @@ public override async Task<AverageTimeResponse> GetAverageExecutionTime(Empty re
return new AverageTimeResponse() { AverageTime = avgTime };
}

public override async Task<CommandLogModelResponse> AddCommand(CommandLogModel request, ServerCallContext context)
public override async Task<CommandLogModel> AddCommand(CommandLogModel request, ServerCallContext context)
{
Core.Models.CommandLog commandLog = new()
{
Expand All @@ -72,18 +73,8 @@ public override async Task<CommandLogModelResponse> AddCommand(CommandLogModel r

if (result)
{
return new CommandLogModelResponse()
{
Id = commandLog.Id,
ChannelId = commandLog.ChannelId,
CommandName = commandLog.CommandName,
ErrorMessage = commandLog.ErrorMessage,
ExecutionTimeMs = commandLog.ExecutionTimeMs,
GuildId = (ulong)commandLog.GuildId,
IsSuccess = commandLog.IsSuccess,
UnixTime = request.UnixTime,
UserId = commandLog.UserId
};
request.Id = commandLog.Id;
return request;
}

return null!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace HuppyService.Service.Services
{
public class GPTService : GPT.GPTBase
public class GPTService : GPTProto.GPTProtoBase
{
private readonly IHttpClientFactory _clientFactory;
private readonly ILogger _logger;
Expand Down

0 comments on commit a97490b

Please sign in to comment.