First pass at party service
This commit is contained in:
@ -1,34 +1,79 @@
|
||||
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)
|
||||
{
|
||||
return base.CreateParty(request, 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)
|
||||
{
|
||||
return base.DeleteParty(request, 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)
|
||||
{
|
||||
return base.ListParties(request, 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)
|
||||
{
|
||||
return base.GetParty(request, 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)
|
||||
{
|
||||
return base.UpdateParty(request, context);
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ namespace Aurora.Services.Signal
|
||||
{
|
||||
private readonly ILogger<SignalService> _logger;
|
||||
|
||||
private CursorList<Party> _partyList;
|
||||
public SignalService(ILogger<SignalService> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
|
Reference in New Issue
Block a user