Skip to content
This repository was archived by the owner on Jun 8, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion SnipeSharp/EndPoint/ComponentEndPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public sealed class ComponentEndPoint : EndPoint<Component>
{
/// <param name="api">The Api to grab the RequestManager from.</param>
/// <exception cref="SnipeSharp.Exceptions.MissingRequiredAttributeException">When the type parameter does not have the <see cref="PathSegmentAttribute">PathSegmentAttribute</see> attribute.</exception>
internal ComponentEndPoint(SnipeItApi api) : base(api) {}
internal ComponentEndPoint(SnipeItApi api) : base(api) { }

/// <summary>
/// Get the list of component assignees for a component.
Expand All @@ -18,5 +18,25 @@ internal ComponentEndPoint(SnipeItApi api) : base(api) {}
/// <returns>A ResponseCollection list of ComponentAssignees.</returns>
public ResponseCollection<ComponentAsset> GetAssignedAssets(Component component)
=> Api.RequestManager.GetAll<ComponentAsset>($"{EndPointInfo.BaseUri}/{component.Id}/assets").RethrowExceptionIfAny().Value;

/// <summary>
/// Check out an accessory.
/// </summary>
/// <param name="request">An accessory check-out request.</param>
/// <returns></returns>
public RequestResponse<ApiObject> CheckOut(ComponentCheckOutRequest request)
=> Api.RequestManager.Post<ComponentCheckOutRequest, ApiObject>($"{EndPointInfo.BaseUri}/{request.Component.Id}/checkout", request).RethrowExceptionIfAny().Value;


/// <summary>
/// Check out a component.
/// </summary>
/// <param name="component">The accessory to check out.</param>
/// <param name="assignedAsset">The user to check out to.</param>
/// /// <param name="quantity">How many components should be assigned to the asset.</param>
/// <param name="note">An optional note for the checkout log.</param>
/// <returns></returns>
public RequestResponse<ApiObject> CheckOut(Component component, Asset assignedAsset, int quantity, string note = null)
=> CheckOut(new ComponentCheckOutRequest(component, assignedAsset, quantity) { Note = note });
}
}
36 changes: 36 additions & 0 deletions SnipeSharp/Models/ComponentCheckOut.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using SnipeSharp.Serialization;
using SnipeSharp.Models.Enumerations;

namespace SnipeSharp.Models
{
/// <summary>
/// A Componenet/Asset relation.
/// </summary>
public sealed class ComponentCheckOut : ApiObject, IAvailableActions
{
/// <summary>
/// The Id of the Component in Snipe-IT.
/// </summary>
[DeserializeAs("assigned_pivot_id")]
public int ComponentId { get; private set; }

/// <summary>
/// The Id of the User in Snipe-IT.
/// </summary>
[DeserializeAs("id")]
public int AssetId { get; private set; }


/// <summary>
/// The assignee type of this particular check out.
/// </summary>
/// <remarks>Currently, this field will always be Asset.</remarks>
[DeserializeAs("type")]
public AssignedToType Type { get; private set; }

/// <inheritdoc />
/// <remarks>Currently, this will always be <c>{CheckIn}</c>.</remarks>
[DeserializeAs("available_actions", DeserializeAs.AvailableActions)]
public AvailableAction AvailableActions { get; private set; }
}
}
39 changes: 39 additions & 0 deletions SnipeSharp/Models/OnlySubmittable/ComponentCheckOutRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using SnipeSharp.Serialization;

namespace SnipeSharp.Models
{
/// <summary>
/// A request to associate an Accessory with a User.
/// </summary>
public sealed class ComponentCheckOutRequest : ApiObject
{
/// <value>The Accessory that will be checked out.</value>
/// <remarks>This property is not serialized, but instead used for its Id value.</remarks>
public Component Component { get; private set; }

/// <value>The assigned user.</value>
[SerializeAs("assigned_to", SerializeAs.IdValue)]
public Asset AssignedAsset { get; private set; }

/// <value>The note to put in the log for this check-out event.</value>
[SerializeAs("note")]
public string Note { get; set; }

///<value>How many to assign</value>
[SerializeAs("assigned_qty")]
public int Quantity { get; set; }

/// <summary>
/// Begins a new ComponentCheckOutRequest assigning the supplied component to the supplied asset.
/// </summary>
/// <param name="component">The accessory to assign.</param>
/// <param name="asset">The User to assign the accessory to.</param>
/// <param name="quantity">How many components to assign to the asset</param>
public ComponentCheckOutRequest(Component component, Asset asset, int quantity)
{
Component = component;
AssignedAsset = asset;
Quantity = quantity;
}
}
}