-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSalaryRequestsGrpcService.cs
133 lines (106 loc) · 4.4 KB
/
SalaryRequestsGrpcService.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
namespace HrAspire.Salaries.Web.Services;
using System.Threading.Tasks;
using Google.Protobuf.WellKnownTypes;
using Grpc.Core;
using HrAspire.Salaries.Business.SalaryRequests;
using HrAspire.Salaries.Web.Mappers;
using HrAspire.Web.Common;
public class SalaryRequestsGrpcService : SalaryRequests.SalaryRequestsBase
{
private readonly ISalaryRequestsService salaryRequestsService;
public SalaryRequestsGrpcService(ISalaryRequestsService salaryRequestsService)
{
this.salaryRequestsService = salaryRequestsService;
}
public override async Task<ListSalaryRequestsResponse> List(ListSalaryRequestsRequest request, ServerCallContext context)
{
var salaryRequests = await this.salaryRequestsService.ListAsync(request.PageNumber, request.PageSize);
var total = await this.salaryRequestsService.GetCountAsync();
var response = new ListSalaryRequestsResponse { Total = total };
foreach (var salaryRequest in salaryRequests)
{
response.SalaryRequests.Add(salaryRequest.MapToSalaryRequestGrpcModel());
}
return response;
}
public override async Task<ListSalaryRequestsResponse> ListEmployeeSalaryRequests(
ListEmployeeSalaryRequestsRequest request,
ServerCallContext context)
{
var salaryRequests = await this.salaryRequestsService.ListEmployeeSalaryRequestsAsync(
request.EmployeeId,
request.PageNumber,
request.PageSize,
request.ManagerId);
var total = await this.salaryRequestsService.GetEmployeeSalaryRequestsCountAsync(request.EmployeeId, request.ManagerId);
var response = new ListSalaryRequestsResponse { Total = total };
foreach (var salaryRequest in salaryRequests)
{
response.SalaryRequests.Add(salaryRequest.MapToSalaryRequestGrpcModel());
}
return response;
}
public override async Task<GetSalaryRequestResponse> Get(GetSalaryRequestRequest request, ServerCallContext context)
{
var salaryRequest = await this.salaryRequestsService.GetAsync(request.Id, request.ManagerId);
if (salaryRequest is null)
{
throw new RpcException(new Status(StatusCode.NotFound, detail: string.Empty));
}
var response = new GetSalaryRequestResponse { SalaryRequest = salaryRequest.MapToSalaryRequestDetailsGrpcModel() };
return response;
}
public override async Task<CreateSalaryRequestResponse> Create(CreateSalaryRequestRequest request, ServerCallContext context)
{
var createResult = await this.salaryRequestsService.CreateAsync(
request.EmployeeId,
request.NewSalary,
request.Notes,
request.CreatedById);
if (createResult.IsError)
{
throw createResult.ToRpcException();
}
return new CreateSalaryRequestResponse { Id = createResult.Data };
}
public override async Task<Empty> Update(UpdateSalaryRequestRequest request, ServerCallContext context)
{
var updateResult = await this.salaryRequestsService.UpdateAsync(
request.Id,
request.NewSalary,
request.Notes,
request.CurrentEmployeeId);
if (updateResult.IsError)
{
throw updateResult.ToRpcException();
}
return new Empty();
}
public override async Task<Empty> Delete(DeleteSalaryRequestRequest request, ServerCallContext context)
{
var deleteResult = await this.salaryRequestsService.DeleteAsync(request.Id, request.CurrentEmployeeId);
if (deleteResult.IsError)
{
throw deleteResult.ToRpcException();
}
return new Empty();
}
public override async Task<Empty> Approve(ChangeStatusOfSalaryRequestRequest request, ServerCallContext context)
{
var result = await this.salaryRequestsService.ApproveAsync(request.Id, request.CurrentEmployeeId);
if (result.IsError)
{
throw result.ToRpcException();
}
return new Empty();
}
public override async Task<Empty> Reject(ChangeStatusOfSalaryRequestRequest request, ServerCallContext context)
{
var result = await this.salaryRequestsService.RejectAsync(request.Id, request.CurrentEmployeeId);
if (result.IsError)
{
throw result.ToRpcException();
}
return new Empty();
}
}