From 4cc740cd51ec9b81cef515ef0808e064878464f2 Mon Sep 17 00:00:00 2001 From: HueByte Date: Tue, 11 Oct 2022 12:51:16 +0200 Subject: [PATCH] T #98 shared proto types --- .../Services/CommandLog/CommandLogService.cs | 12 ++-- .../Services/Reminder/ReminderService.cs | 6 +- .../Services/Server/ServerService.cs | 6 +- .../HuppyService.Service.csproj | 4 ++ .../Protos/commandLog.proto | 14 ++--- .../Protos/database.proto | 6 +- .../Protos/reminder.proto | 23 ++----- .../HuppyService.Service/Protos/server.proto | 12 ++-- .../HuppyService.Service/Protos/shared.proto | 23 +++++++ .../HuppyService.Service/Protos/ticket.proto | 61 +++++++++++++++++++ .../Services/CommandLogService.cs | 8 +-- .../Services/ReminderService.cs | 8 +-- .../Services/ServerService.cs | 4 +- 13 files changed, 127 insertions(+), 60 deletions(-) create mode 100644 src/HuppyService/HuppyService.Service/Protos/shared.proto create mode 100644 src/HuppyService/HuppyService.Service/Protos/ticket.proto diff --git a/src/Huppy/Huppy.Core/Services/CommandLog/CommandLogService.cs b/src/Huppy/Huppy.Core/Services/CommandLog/CommandLogService.cs index fc9f893..e962659 100644 --- a/src/Huppy/Huppy.Core/Services/CommandLog/CommandLogService.cs +++ b/src/Huppy/Huppy.Core/Services/CommandLog/CommandLogService.cs @@ -1,5 +1,7 @@ -using Google.Protobuf.WellKnownTypes; +using System.Security.Authentication.ExtendedProtection; +using Google.Protobuf.WellKnownTypes; using Huppy.Core.Interfaces.IServices; +using HuppyService.Service; using HuppyService.Service.Protos.Models; namespace Huppy.Core.Services.CommandLog @@ -22,23 +24,23 @@ public async Task AddCommand(CommandLogModel commandLog) public async Task> GetAiUsage() { // implement single instance of empty? - var result = await _commandLogClient.GetAiUsageAsync(new Empty()); + var result = await _commandLogClient.GetAiUsageAsync(new HuppyService.Service.Protos.Void()); return result.AiUsers; } public async Task GetAverageExecutionTime() { - var result = await _commandLogClient.GetAverageExecutionTimeAsync(new Empty()); + var result = await _commandLogClient.GetAverageExecutionTimeAsync(new HuppyService.Service.Protos.Void()); return result.AverageTime; } public async Task GetCount() { - var result = await _commandLogClient.GetCountAsync(new Empty()); + var result = await _commandLogClient.GetCountAsync(new HuppyService.Service.Protos.Void()); - return result.Count; + return result.Number; } public async Task RemoveCommand(CommandLogModel commandLog) diff --git a/src/Huppy/Huppy.Core/Services/Reminder/ReminderService.cs b/src/Huppy/Huppy.Core/Services/Reminder/ReminderService.cs index 2926dd2..583d431 100644 --- a/src/Huppy/Huppy.Core/Services/Reminder/ReminderService.cs +++ b/src/Huppy/Huppy.Core/Services/Reminder/ReminderService.cs @@ -38,8 +38,8 @@ public async Task> GetSortedUserReminders(ulong userId, int public async Task GetRemindersCount(ulong userId) { - var result = await _reminderClient.GetRemindersCountAsync(new GetReminderCountInput() { UserId = userId }); - return result.Count; + var result = await _reminderClient.GetRemindersCountAsync(new HuppyService.Service.Protos.UserId() { Id = userId }); + return result.Number; } public async Task GetReminderAsync(ulong userId, int reminderId) @@ -85,7 +85,7 @@ await _eventService.AddEvent(Miscellaneous.UnixTimeStampToUtcDateTime(reminder.U public async Task> GetUserRemindersAsync(ulong userId) { - return (await _reminderClient.GetUserRemindersAsync(new() { UserId = userId })).ReminderModels; + return (await _reminderClient.GetUserRemindersAsync(new HuppyService.Service.Protos.UserId() { Id = userId })).ReminderModels; } public async Task AddReminderAsync(DateTime date, ulong userId, string message) diff --git a/src/Huppy/Huppy.Core/Services/Server/ServerService.cs b/src/Huppy/Huppy.Core/Services/Server/ServerService.cs index a79ce4b..e2f4f75 100644 --- a/src/Huppy/Huppy.Core/Services/Server/ServerService.cs +++ b/src/Huppy/Huppy.Core/Services/Server/ServerService.cs @@ -15,13 +15,13 @@ public ServerService(ServerProto.ServerProtoClient serverClient) public async Task GetAllAsync(Empty empty) { - var result = await _serverClient.GetAllAsync(new Empty()); + var result = await _serverClient.GetAllAsync(new HuppyService.Service.Protos.Void()); return result; } public async Task GetAsync(ulong serverId) { - var result = await _serverClient.GetAsync(new ServerIdInput() { Id = serverId }); + var result = await _serverClient.GetAsync(new HuppyService.Service.Protos.ServerId() { Id = serverId }); return result; } @@ -40,7 +40,7 @@ public async Task GetOrCreateAsync(ulong serverId, string serverNam public async Task UpdateAsync(ServerModel server) { var updateResult = await _serverClient.UpdateAsync(server); - + return updateResult; } } diff --git a/src/HuppyService/HuppyService.Service/HuppyService.Service.csproj b/src/HuppyService/HuppyService.Service/HuppyService.Service.csproj index bc33f0f..d5fdec1 100644 --- a/src/HuppyService/HuppyService.Service/HuppyService.Service.csproj +++ b/src/HuppyService/HuppyService.Service/HuppyService.Service.csproj @@ -8,6 +8,8 @@ + + @@ -17,6 +19,8 @@ + + diff --git a/src/HuppyService/HuppyService.Service/Protos/commandLog.proto b/src/HuppyService/HuppyService.Service/Protos/commandLog.proto index 736a758..1179350 100644 --- a/src/HuppyService/HuppyService.Service/Protos/commandLog.proto +++ b/src/HuppyService/HuppyService.Service/Protos/commandLog.proto @@ -2,21 +2,17 @@ syntax = "proto3"; option csharp_namespace = "HuppyService.Service.Protos"; -import "google/protobuf/empty.proto"; import "Protos/database.proto"; +import "Protos/shared.proto"; package CommandLogProto; service CommandLogProto { - rpc GetCount(google.protobuf.Empty) returns (CommandLogCount); - rpc GetAverageExecutionTime(google.protobuf.Empty) returns (AverageTimeResponse); - rpc GetAiUsage(google.protobuf.Empty) returns (AiUsageResponse); + rpc GetCount(shared.Void) returns (shared.Int32); + rpc GetAverageExecutionTime(shared.Void) returns (AverageTimeResponse); + rpc GetAiUsage(shared.Void) returns (AiUsageResponse); rpc AddCommand(database.models.CommandLogModel) returns (database.models.CommandLogModel); - rpc RemoveCommand(database.models.CommandLogModel) returns (database.models.CommonResponse); -} - -message CommandLogCount { - int32 Count = 1; + rpc RemoveCommand(database.models.CommandLogModel) returns (shared.CommonResponse); } message AverageTimeResponse { diff --git a/src/HuppyService/HuppyService.Service/Protos/database.proto b/src/HuppyService/HuppyService.Service/Protos/database.proto index db0a246..e532482 100644 --- a/src/HuppyService/HuppyService.Service/Protos/database.proto +++ b/src/HuppyService/HuppyService.Service/Protos/database.proto @@ -33,10 +33,6 @@ message ServerRoomsModel { uint64 ServerId = 4; } -message CommonResponse { - bool IsSuccess = 1; -} - message ReminderModel { int32 Id = 1; uint64 UnixTime = 2; @@ -53,4 +49,4 @@ message TicketModel { uint64 CreatedDate = 6; uint64 ClosedDate = 7; uint64 UserId = 8; -} \ No newline at end of file +} diff --git a/src/HuppyService/HuppyService.Service/Protos/reminder.proto b/src/HuppyService/HuppyService.Service/Protos/reminder.proto index ae0a2bd..ffa2e8b 100644 --- a/src/HuppyService/HuppyService.Service/Protos/reminder.proto +++ b/src/HuppyService/HuppyService.Service/Protos/reminder.proto @@ -2,19 +2,20 @@ syntax = "proto3"; option csharp_namespace = "HuppyService.Service.Protos"; -import "Protos/database.proto"; +import "Protos/database.proto"; +import "Protos/shared.proto"; package ReminderProto; service ReminderProto { rpc GetReminder(GetReminderInput) returns (database.models.ReminderModel); rpc GetReminderBatch(ReminderBatchInput) returns (ReminderModelCollection); - rpc GetUserReminders(ReminderUserInput) returns (ReminderModelCollection); + rpc GetUserReminders(shared.UserId) returns (ReminderModelCollection); rpc GetSortedUserReminders(SortedUserRemindersInput) returns (ReminderModelCollection); - rpc GetRemindersCount(GetReminderCountInput) returns (GetReminderCountResponse); + rpc GetRemindersCount(shared.UserId) returns (shared.Int32); rpc AddReminder(database.models.ReminderModel) returns (database.models.ReminderModel); - rpc RemoveReminder(database.models.ReminderModel) returns (database.models.CommonResponse); - rpc RemoveReminderRange(RemoveReminderRangeInput) returns (database.models.CommonResponse); + rpc RemoveReminder(database.models.ReminderModel) returns (shared.CommonResponse); + rpc RemoveReminderRange(RemoveReminderRangeInput) returns (shared.CommonResponse); } message SortedUserRemindersInput { @@ -23,14 +24,6 @@ message SortedUserRemindersInput { int32 Take = 3; } -message GetReminderCountInput { - uint64 UserId = 1; -} - -message GetReminderCountResponse { - int32 Count = 1; -} - message GetReminderInput { uint64 UserId = 1; int32 ReminderId = 2; @@ -40,10 +33,6 @@ message ReminderBatchInput { uint64 EndDate = 1; } -message ReminderUserInput { - uint64 UserId = 1; -} - message ReminderModelCollection { repeated database.models.ReminderModel ReminderModels = 1; } diff --git a/src/HuppyService/HuppyService.Service/Protos/server.proto b/src/HuppyService/HuppyService.Service/Protos/server.proto index 2b58515..bef0c0c 100644 --- a/src/HuppyService/HuppyService.Service/Protos/server.proto +++ b/src/HuppyService/HuppyService.Service/Protos/server.proto @@ -2,20 +2,16 @@ syntax = "proto3"; option csharp_namespace = "HuppyService.Service.Protos"; -import "google/protobuf/empty.proto"; import "Protos/database.proto"; +import "Protos/shared.proto"; package ServerProto; service ServerProto { - rpc Get(ServerIdInput) returns (database.models.ServerModel); + rpc Get(shared.ServerId) returns (database.models.ServerModel); rpc GetOrCreate(GetOrCreateServerInput) returns (database.models.ServerModel); - rpc Update(database.models.ServerModel) returns(database.models.CommonResponse); - rpc GetAll(google.protobuf.Empty) returns (ServerModelCollection); -} - -message ServerIdInput { - uint64 Id = 1; + rpc Update(database.models.ServerModel) returns(shared.CommonResponse); + rpc GetAll(shared.Void) returns (ServerModelCollection); } message ServerModelCollection { diff --git a/src/HuppyService/HuppyService.Service/Protos/shared.proto b/src/HuppyService/HuppyService.Service/Protos/shared.proto new file mode 100644 index 0000000..f9ddc1d --- /dev/null +++ b/src/HuppyService/HuppyService.Service/Protos/shared.proto @@ -0,0 +1,23 @@ +syntax = "proto3"; + +option csharp_namespace = "HuppyService.Service.Protos"; + +package shared; + +message CommonResponse { + bool IsSuccess = 1; +} + +message UserId { + uint64 Id = 1; +} + +message ServerId { + uint64 Id = 1; +} + +message Int32 { + int32 Number = 1; +} + +message Void { } \ No newline at end of file diff --git a/src/HuppyService/HuppyService.Service/Protos/ticket.proto b/src/HuppyService/HuppyService.Service/Protos/ticket.proto new file mode 100644 index 0000000..c43251e --- /dev/null +++ b/src/HuppyService/HuppyService.Service/Protos/ticket.proto @@ -0,0 +1,61 @@ +syntax = "proto3"; + +option csharp_namespace = "HuppyService.Service.Protos"; + +import "Protos/database.proto"; +import "Protos/shared.proto"; + +package TicketProto; + +service TicketProto { + rpc GetCountAsync(shared.UserId) returns (shared.Int32); + rpc GetTickets(shared.Void) returns (TicketModelCollection); + rpc GetUserTickets(shared.UserId) returns (TicketModelCollection); + rpc GetPaginatedTickets(GetPaginatedTicketsInput) returns (TicketModelCollection); + rpc GetUserPaginatedTickets(GetUserPaginatedTicketsInput) returns (TicketModelCollection); + rpc GetTicket(GetTicketInput) returns (database.models.TicketModel); + rpc AddTicket(AddTicketInput) returns (database.models.TicketModel); + rpc RemoveTicketAsync(TicketRemoveInput) returns (shared.CommonResponse); + rpc UpdateTicketAsync(TicketUpdateInput) returns (shared.CommonResponse); + rpc CloseTicket(CloseTicketInput) returns (shared.CommonResponse); +} + +message TicketRemoveInput { + string TicketId = 1; +} + +message TicketUpdateInput { + string TicketId = 1; + string Description = 2; +} + +message CloseTicketInput { + string TicketId = 1; + string Answer = 2; +} + +message AddTicketInput { + uint64 UserId = 1; + string Topic = 2; + string Description = 3; +} + +message GetTicketInput { + string TicketId = 1; + uint64 UserId = 2; +} + +message GetUserPaginatedTicketsInput { + uint64 UserId = 1; + int32 Skip = 2; + int32 Take = 3; +} + +message GetPaginatedTicketsInput { + int32 Skip = 1; + int32 Take = 2; +} + +message TicketModelCollection { + repeated database.models.TicketModel TicketsModels = 1; +} \ No newline at end of file diff --git a/src/HuppyService/HuppyService.Service/Services/CommandLogService.cs b/src/HuppyService/HuppyService.Service/Services/CommandLogService.cs index e8eb6e0..fefb616 100644 --- a/src/HuppyService/HuppyService.Service/Services/CommandLogService.cs +++ b/src/HuppyService/HuppyService.Service/Services/CommandLogService.cs @@ -16,15 +16,15 @@ public CommandLogService(ICommandLogRepository commandLogRepository) _commandLogRepository = commandLogRepository; } - public override async Task GetCount(Empty request, ServerCallContext context) + public override async Task GetCount(Protos.Void request, ServerCallContext context) { var query = await _commandLogRepository.GetAllAsync(); var count = await query.CountAsync(); - return new CommandLogCount() { Count = count }; + return new Protos.Int32() { Number = count }; } - public override async Task GetAiUsage(Empty request, ServerCallContext context) + public override async Task GetAiUsage(Protos.Void request, ServerCallContext context) { Dictionary result = new(); @@ -46,7 +46,7 @@ public override async Task GetAiUsage(Empty request, ServerCall return response; } - public override async Task GetAverageExecutionTime(Empty request, ServerCallContext context) + public override async Task GetAverageExecutionTime(Protos.Void request, ServerCallContext context) { var query = await _commandLogRepository.GetAllAsync(); var avgTime = await query.AverageAsync(e => e.ExecutionTimeMs); diff --git a/src/HuppyService/HuppyService.Service/Services/ReminderService.cs b/src/HuppyService/HuppyService.Service/Services/ReminderService.cs index 8240779..b958e06 100644 --- a/src/HuppyService/HuppyService.Service/Services/ReminderService.cs +++ b/src/HuppyService/HuppyService.Service/Services/ReminderService.cs @@ -41,10 +41,10 @@ public override async Task GetSortedUserReminders(Sorte return result; } - public override async Task GetRemindersCount(GetReminderCountInput request, ServerCallContext context) + public override async Task GetRemindersCount(Protos.UserId request, ServerCallContext context) { var query = await _reminderRepository.GetAllAsync(); - return new GetReminderCountResponse() { Count = await query.Where(e => e.UserId == request.UserId).CountAsync() }; + return new Protos.Int32 () { Number = await query.Where(e => e.UserId == request.Id).CountAsync() }; } public override async Task GetReminder(GetReminderInput request, ServerCallContext context) @@ -109,11 +109,11 @@ public override async Task AddReminder(ReminderModel request, Ser return result; } - public override async Task GetUserReminders(ReminderUserInput request, ServerCallContext context) + public override async Task GetUserReminders(Protos.UserId request, ServerCallContext context) { var remindersQuery = await _reminderRepository.GetAllAsync(); - var reminders = await remindersQuery.Where(reminder => reminder.UserId == request.UserId) + var reminders = await remindersQuery.Where(reminder => reminder.UserId == request.Id) .ToListAsync(); ReminderModelCollection result = new(); diff --git a/src/HuppyService/HuppyService.Service/Services/ServerService.cs b/src/HuppyService/HuppyService.Service/Services/ServerService.cs index 6bb091c..201cc47 100644 --- a/src/HuppyService/HuppyService.Service/Services/ServerService.cs +++ b/src/HuppyService/HuppyService.Service/Services/ServerService.cs @@ -17,7 +17,7 @@ public ServerService(IServerRepository serverRepository) _serverRepository = serverRepository; } - public override async Task Get(ServerIdInput request, ServerCallContext context) + public override async Task Get(Protos.ServerId request, ServerCallContext context) { var server = await _serverRepository.GetAsync(request.Id); @@ -37,7 +37,7 @@ public override async Task Get(ServerIdInput request, ServerCallCon }; } - public override async Task GetAll(Empty request, ServerCallContext context) + public override async Task GetAll(Protos.Void request, ServerCallContext context) { var query = await _serverRepository.GetAllAsync(); var servers = await query.Include(e => e.Rooms).ToListAsync();