Spare Requests
A Spare Request takes place every time a crew member needs one or more
Spares to perform a Work Order or Service Order.
As part of this Services, we can find other related entities, such as:
- Approver Group: groups of Users / Positions in charge of approve a Spare
Request when it is required.
- Approver: relationship between a User / Position and an Approver
Group.
- Spare Request Line: each of pairs Spare - Quantity that compose a
Spare Request.
Integration
The Spare Requests Services offers some messages that can be published, as well
as some events that other services can consume to keep up to date with new and
updated Spare Requests. It also includes messages and events to manage
Approver Groups and Approvers, and to add Spare Request Lines to a
Spare Request.
First of all, we need a reference to the SpareRequests.Application.Contracts
project, as it's shown below:
XML |
---|
| <ProjectReference Include="$(ServicesPath)SpareRequests\ITsynch.Suite.SpareRequests.Application.Contracts\ITsynch.Suite.SpareRequests.Application.Contracts.csproj" />
|
In the following sections, we can find some examples of this messages events:
Messages
Create a new Approver Group:
C# |
---|
| var correlationId = NewId.NextGuid();
var displayName = "Master";
var limit = 10000;
await this.PublishEndpoint!.Publish<CreateOrUpdateApproverGroup>(new
{
CorrelationId = correlationId,
DisplayName = displayName,
Limit = limit,
});
|
Create a new Spare Request:
C# |
---|
| var approverCorrelationId = NewId.NextGuid();
var spareRequestCorrelationId = NewId.NextGuid();
var number = "NUM100.000.200";
var title = "A/C COMPRESSOR SAFETY VALVE CHECK";
var creatorUserId = NewId.NextGuid();
var creatorPositionId = NewId.NextGuid();
var creationDate = DateTime.Now;
var stockPickerId = NewId.NextGuid();
var preferredPickUpDate = DateTime.Now.AddDays(7);
await this.PublishEndpoint!.Publish<CreateSpareRequest>(new
{
CorrelationId = spareRequestCorrelationId,
Number = number,
Title = title,
CreatorUserId = creatorUserId,
CreatorPositionId = creatorPositionId,
CreationDate = creationDate,
ApproverId = approverCorrelationId,
StockPickerId = stockPickerId,
PreferredPickUpDate = preferredPickUpDate,
});
|
Note
approverCorrelationId
must belong to an Approver created before. For the example, we have just simplified it.
Add a Spare Request Line to a Spare Request:
C# |
---|
| var quantity = 2;
var spareId = NewId.NextGuid();
await this.PublishEndpoint!.Publish<AddSpareRequestLineToSpareRequest>(new
{
CorrelationId = spareRequestCorrelationId,
SpareCorrelationId = spareId,
Quantity = quantity,
});
|
Events
On the other hand, you can consume the different Spare Request's events and
perform the actions you need to do in your project.
For example, Spare Request Updated:
C# |
---|
| using ITsynch.Suite.SpareRequests.Application;
using MassTransit;
using System.Threading.Tasks;
namespace ITsynch.Suite.Example.Application
{
public class SpareRequestUpdatedConsumer : IConsumer<SpareRequestUpdated>
{
public SpareRequestUpdatedConsumer()
{
}
public async Task Consume(ConsumeContext<SpareRequestUpdated> context)
{
// do some stuff
}
}
}
|
This event includes all the Spare Request's information mentioned before in the
Spare Request creation.
Note
SpareRequestUpdated
event is published when a Spare Request is updated but
also when a Spare Request is created.