Skip to content

Commit

Permalink
Use already-existing Qualification constant.
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGHippo committed Jul 18, 2024
1 parent 72eca3f commit 8363a09
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions content/Dfe.EarlyYearsQualification.ContentUpload/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Contentful.Core.Models;
using Contentful.Core.Models.Management;
using Contentful.Core.Search;
using Dfe.EarlyYearsQualification.Content.Constants;
using Microsoft.VisualBasic.FileIO;

namespace Dfe.EarlyYearsQualification.ContentUpload;
Expand All @@ -15,7 +16,6 @@ public static class Program
private const string SpaceId = "";
private const string ManagementApiKey = "";
private const string CsvFile = "./csv/ey-quals-full-2024-with-new-reference-fields.csv";
private const string QualificationContentTypeId = "Qualification";
private const string FieldTypeSymbol = "Symbol";

// ReSharper disable once UnusedParameter.Global
Expand All @@ -38,10 +38,12 @@ public static async Task Main(string[] args)
private static async Task PopulateContentfulWithQualifications(ContentfulManagementClient client)
{
// Check existing entries and identify those to update, and those to create.
var queryBuilder = new QueryBuilder<Entry<dynamic>>()
.ContentTypeIs(ContentTypes.Qualification)
.Limit(1000);

var currentEntries =
await
client.GetEntriesForLocale(new QueryBuilder<Entry<dynamic>>().ContentTypeIs(QualificationContentTypeId).Limit(1000),
Locale);
await client.GetEntriesForLocale(queryBuilder, Locale);

var qualificationsToAddOrUpdate = GetQualificationsToAddOrUpdate();

Expand All @@ -59,7 +61,7 @@ private static async Task PopulateContentfulWithQualifications(ContentfulManagem

// Create new entry
var entryToPublish = await client.CreateOrUpdateEntry(entryToAddOrUpdate,
contentTypeId: QualificationContentTypeId,
contentTypeId: ContentTypes.Qualification,
version: entryToAddOrUpdate.SystemProperties.Version);

await client.PublishEntry(entryToPublish.SystemProperties.Id,
Expand All @@ -70,17 +72,17 @@ await client.PublishEntry(entryToPublish.SystemProperties.Id,
private static async Task SetUpContentModels(ContentfulManagementClient client)
{
// Check current version of model
var contentTypeModel = await client.GetContentType(QualificationContentTypeId);
var contentTypeModel = await client.GetContentType(ContentTypes.Qualification);

var version = contentTypeModel?.SystemProperties.Version ?? 1;

var contentType = new ContentType
{
SystemProperties = new SystemProperties
{
Id = QualificationContentTypeId
Id = ContentTypes.Qualification
},
Name = QualificationContentTypeId,
Name = ContentTypes.Qualification,
Description = "Model for storing all the early years qualifications",
DisplayField = "qualificationName",
Fields =
Expand Down Expand Up @@ -179,15 +181,15 @@ private static async Task SetUpContentModels(ContentfulManagementClient client)
};

var typeToActivate = await client.CreateOrUpdateContentType(contentType, version: version);
await client.ActivateContentType(QualificationContentTypeId, typeToActivate.SystemProperties.Version!.Value);
await client.ActivateContentType(ContentTypes.Qualification, typeToActivate.SystemProperties.Version!.Value);

Thread.Sleep(2000); // Allows the API time to activate the content type
await SetHelpText(client);
}

private static async Task SetHelpText(ContentfulManagementClient client)
{
var editorInterface = await client.GetEditorInterface(QualificationContentTypeId);
var editorInterface = await client.GetEditorInterface(ContentTypes.Qualification);
SetHelpTextForField(editorInterface, "qualificationId",
"The unique identifier used to reference the qualification");
SetHelpTextForField(editorInterface, "qualificationName", "The name of the qualification");
Expand All @@ -206,7 +208,7 @@ private static async Task SetHelpText(ContentfulManagementClient client)
SetHelpTextForField(editorInterface, "ratioRequirements", "The optional ratio requirements",
SystemWidgetIds.EntryMultipleLinksEditor);

await client.UpdateEditorInterface(editorInterface, QualificationContentTypeId,
await client.UpdateEditorInterface(editorInterface, ContentTypes.Qualification,
editorInterface.SystemProperties.Version!.Value);
}

Expand Down

0 comments on commit 8363a09

Please sign in to comment.