This repository has been archived by the owner on May 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
/
PortfolioService.cs
51 lines (42 loc) · 1.67 KB
/
PortfolioService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using System;
using System.Linq;
using System.Threading.Tasks;
using Grpc.Core;
using Microsoft.AspNetCore.Authorization;
using TraderSys.PortfolioData;
using TraderSys.Portfolios.Protos;
namespace TraderSys.Portfolios.Services
{
public class PortfolioService : Protos.Portfolios.PortfoliosBase
{
private readonly IPortfolioRepository _repository;
public PortfolioService(IPortfolioRepository repository)
{
_repository = repository;
}
[Authorize]
public override async Task<GetResponse> Get(GetRequest request, ServerCallContext context)
{
if (!Guid.TryParse(request.TraderId, out var traderId))
{
throw new RpcException(new Status(StatusCode.InvalidArgument, "traderId must be a UUID"));
}
var portfolio = await _repository.GetAsync(traderId, request.PortfolioId);
return new GetResponse
{
Portfolio = Portfolio.FromRepositoryModel(portfolio)
};
}
public override async Task<GetAllResponse> GetAll(GetAllRequest request, ServerCallContext context)
{
if (!Guid.TryParse(request.TraderId, out var traderId))
{
throw new RpcException(new Status(StatusCode.InvalidArgument, "traderId must be a UUID"));
}
var portfolios = await _repository.GetAllAsync(traderId);
var response = new GetAllResponse();
response.Portfolios.AddRange(portfolios.Select(Portfolio.FromRepositoryModel));
return response;
}
}
}