-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBulkUnpublishService.cs
More file actions
68 lines (61 loc) · 2.4 KB
/
BulkUnpublishService.cs
File metadata and controls
68 lines (61 loc) · 2.4 KB
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
using System;
using System.Text;
using Newtonsoft.Json;
using Contentstack.Management.Core.Models;
namespace Contentstack.Management.Core.Services.Stack.BulkOperation
{
/// <summary>
/// Service for bulk unpublish operations.
/// </summary>
internal class BulkUnpublishService : ContentstackService
{
private readonly BulkPublishDetails _details;
private readonly bool _skipWorkflowStage;
private readonly bool _approvals;
private readonly bool _isNested;
/// <summary>
/// Initializes a new instance of the <see cref="BulkUnpublishService"/> class.
/// </summary>
/// <param name="serializer">The JSON serializer.</param>
/// <param name="stack">The stack instance.</param>
/// <param name="details">The unpublish details.</param>
/// <param name="skipWorkflowStage">Whether to skip workflow stage checks.</param>
/// <param name="approvals">Whether to include approvals.</param>
/// <param name="isNested">Whether this is a nested operation.</param>
public BulkUnpublishService(JsonSerializer serializer, Contentstack.Management.Core.Models.Stack stack, BulkPublishDetails details, bool skipWorkflowStage = false, bool approvals = false, bool isNested = false)
: base(serializer, stack)
{
_details = details ?? throw new ArgumentNullException(nameof(details));
_skipWorkflowStage = skipWorkflowStage;
_approvals = approvals;
_isNested = isNested;
ResourcePath = "/bulk/unpublish";
HttpMethod = "POST";
// Set headers based on parameters
if (_skipWorkflowStage)
{
AddQueryResource("skip_workflow_stage_check", "true");
}
if (_approvals)
{
AddQueryResource("approvals", "true");
}
if (_isNested)
{
AddQueryResource("nested", "true");
AddQueryResource("event_type", "bulk");
}
}
/// <summary>
/// Creates the content body for the request.
/// </summary>
public override void ContentBody()
{
if (_details != null)
{
var json = JsonConvert.SerializeObject(_details);
ByteContent = Encoding.UTF8.GetBytes(json);
}
}
}
}