This repository has been archived on 2021-03-06. You can view files and clone it, but cannot push or open issues or pull requests.
aurora-cradle-sharp/AuroraCradle/Src/Services/Signal/Party.cs
2021-03-05 19:09:42 -05:00

79 lines
2.6 KiB
C#

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<Party> _partyList;
public override Task<Party> 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<Empty> 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<ListPartiesResponse> ListParties(ListPartiesRequest request, ServerCallContext context)
{
Cursor<Party> cursor = new Cursor<Party>(ref this._partyList);
Aurora.Cursor.SortDirection direction = Aurora.Cursor.SortDirection.Asc;
if (request.OrderDirection == SortDirection.Desc)
{
direction = Aurora.Cursor.SortDirection.Desc;
}
CursorResult<Party> 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<Party> 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<Party> UpdateParty(UpdatePartyRequest request, ServerCallContext context)
{
throw new System.NotImplementedException();
}
}
}