2021-03-04 17:08:53 +00:00
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Google.Protobuf.WellKnownTypes;
|
|
|
|
using Grpc.Core;
|
2021-03-06 00:09:42 +00:00
|
|
|
using Aurora.Cursor;
|
|
|
|
using Microsoft.Extensions.Logging;
|
2021-03-04 17:08:53 +00:00
|
|
|
|
|
|
|
namespace Aurora.Services.Signal
|
|
|
|
{
|
|
|
|
public partial class SignalService : Signal.SignalBase
|
|
|
|
{
|
2021-03-06 00:09:42 +00:00
|
|
|
private CursorList<Party> _partyList;
|
|
|
|
|
2021-03-04 17:08:53 +00:00
|
|
|
public override Task<Party> CreateParty(CreatePartyRequest request, ServerCallContext context)
|
|
|
|
{
|
2021-03-06 00:09:42 +00:00
|
|
|
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);
|
2021-03-04 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<Empty> DeleteParty(DeletePartyRequest request, ServerCallContext context)
|
|
|
|
{
|
2021-03-06 00:09:42 +00:00
|
|
|
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());
|
2021-03-04 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<ListPartiesResponse> ListParties(ListPartiesRequest request, ServerCallContext context)
|
|
|
|
{
|
2021-03-06 00:09:42 +00:00
|
|
|
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);
|
2021-03-04 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<Party> GetParty(GetPartyRequest request, ServerCallContext context)
|
|
|
|
{
|
2021-03-06 00:09:42 +00:00
|
|
|
Party party = new Party();
|
|
|
|
|
|
|
|
if (this._partyList.ContainsKey(request.PartyId))
|
|
|
|
{
|
|
|
|
this._partyList.TryGetValue(request.PartyId, out party);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Task.FromResult(party);
|
2021-03-04 17:08:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<Party> UpdateParty(UpdatePartyRequest request, ServerCallContext context)
|
|
|
|
{
|
2021-03-06 00:09:42 +00:00
|
|
|
throw new System.NotImplementedException();
|
2021-03-04 17:08:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|