using System.Threading.Tasks; using Google.Protobuf.WellKnownTypes; using Grpc.Core; using Aurora.Cursor; using Microsoft.Extensions.Logging; namespace Aurora.Services.Signal { public partial class SignalService : Signal.SignalBase { private CursorList _partyList; public override Task CreateParty(CreatePartyRequest request, ServerCallContext context) { Party party = new Party(request.Party); _partyList.Add(party); this._logger.LogInformation(string.Format("Added party with name: ${0} to parties", party.Name)); return Task.FromResult(party); } public override Task DeleteParty(DeletePartyRequest request, ServerCallContext context) { if (this._partyList.ContainsKey(request.PartyId)) { this._partyList.Remove(request.PartyId); } this._logger.LogInformation(string.Format("Deleted party with id: ${0} to parties", request.PartyId)); return Task.FromResult(new Empty()); } public override Task ListParties(ListPartiesRequest request, ServerCallContext context) { Cursor cursor = new Cursor(ref this._partyList); Aurora.Cursor.SortDirection direction = Aurora.Cursor.SortDirection.Asc; if (request.OrderDirection == SortDirection.Desc) { direction = Aurora.Cursor.SortDirection.Desc; } CursorResult res = cursor .WithSort(request.OrderBy, direction) .WithNextPageToken(request.PageToken) .WithSize(request.PageSize) .GetNextPage(); ListPartiesResponse response = new ListPartiesResponse() { NextPageToken = res.NextPageToken }; response.Parties.AddRange(res.Result.ConvertAll(party => new PartyListItem() { Name = party.Name, Id = party.Id })); return Task.FromResult(response); } public override Task GetParty(GetPartyRequest request, ServerCallContext context) { Party party = new Party(); if (this._partyList.ContainsKey(request.PartyId)) { this._partyList.TryGetValue(request.PartyId, out party); } return Task.FromResult(party); } public override Task UpdateParty(UpdatePartyRequest request, ServerCallContext context) { throw new System.NotImplementedException(); } } }