Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 6 additions & 0 deletions uSync.BackOffice/Services/ISyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public interface ISyncService
/// <returns></returns>
Task<uSyncAction> ImportSingleActionAsync(uSyncAction action);


/// <summary>
/// Import single item from disk given the key and handler alias
/// </summary>
Task<uSyncAction> ImportSingleItemAsync(Guid key, string handlerAlias);

/// <summary>
/// get the ordered nodes for a process and handler
/// </summary>
Expand Down
12 changes: 12 additions & 0 deletions uSync.BackOffice/Services/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,18 @@
return (await handlerConfig.Handler.ImportAsync(action.FileName, handlerConfig.Settings, true)).FirstOrDefault();
}

public async Task<uSyncAction> ImportSingleItemAsync(Guid key, string handlerAlias)

Check warning on line 242 in uSync.BackOffice/Services/SyncService.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncService.ImportSingleItemAsync(Guid, string)'

Check warning on line 242 in uSync.BackOffice/Services/SyncService.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncService.ImportSingleItemAsync(Guid, string)'

Check warning on line 242 in uSync.BackOffice/Services/SyncService.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncService.ImportSingleItemAsync(Guid, string)'
{
var handlerConfig = _handlerFactory.GetValidHandler(handlerAlias);
if (handlerConfig is null) return uSyncAction.Fail("Unknown", handlerAlias, "Unknown", ChangeType.Fail, $"Could not find handler with alias {handlerAlias}", new KeyNotFoundException(handlerAlias));

var node = await handlerConfig.Handler.TryFindItemNodeAsync(key);
if (node is null) return uSyncAction.Fail("Unknown", handlerAlias, handlerConfig.Handler.ItemType, ChangeType.Fail , $"Could not find item with key {key}", new FileNotFoundException(key.ToString()));

var result = await handlerConfig.Handler.ImportElementAsync(node, $"Single Item {key}", handlerConfig.Settings, new uSyncImportOptions { Flags = SerializerFlags.Force });
return result.FirstOrDefault();
}

#endregion

#region Exporting
Expand Down
7 changes: 7 additions & 0 deletions uSync.BackOffice/SyncHandlers/Interfaces/ISyncHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,11 @@ public interface ISyncHandler
/// <param name="folders"></param>
/// <returns></returns>
Task<IReadOnlyList<OrderedNodeInfo>> FetchAllNodesAsync(string[] folders);

/// <summary>
/// find an element by its key
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
Task<XElement?> TryFindItemNodeAsync(Guid key) => Task.FromResult<XElement?>(null);
}
15 changes: 15 additions & 0 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1996,4 +1996,19 @@ private async Task<bool> RootItemExistsAsync(TObject item)
}

#endregion

/// <inheritdoc/>
public async Task<XElement?> TryFindItemNodeAsync(Guid key)
{
var folders = GetDefaultHandlerFolders();
var items = await GetMergedItemsAsync(folders);

foreach (var item in items)
{
if (item.Node.GetKey() == key)
return item.Node;
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Asp.Versioning;

using Microsoft.AspNetCore.Mvc;

using uSync.Backoffice.Management.Api.Models;
using uSync.BackOffice;

namespace uSync.Backoffice.Management.Api.Controllers.Actions;

[ApiVersion("1.0")]
[ApiExplorerSettings(GroupName = "Actions")]
public class SyncItemController : uSyncControllerBase
{
private readonly ISyncService _syncService;

public SyncItemController(ISyncService syncService)
{
_syncService = syncService;
}

[HttpPost("Import")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(uSyncAction), 200)]
public async Task<IActionResult> ImportSingle([FromBody] uSyncActionView action)
{
var result = await _syncService.ImportSingleItemAsync(action.Key, action.Handler);
return Ok(result);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file is auto-generated by @hey-api/openapi-ts

import type { Options as ClientOptions, TDataShape, Client } from '@hey-api/client-fetch';
import type { GetActionsData, GetActionsResponse, GetActionsBySetData, GetActionsBySetResponse, DownloadData, DownloadResponse, PerformActionData, PerformActionResponse2, ProcessUploadData, ProcessUploadResponse, CheckLegacyData, CheckLegacyResponse, CopyLegacyData, CopyLegacyResponse, IgnoreLegacyData, IgnoreLegacyResponse, GetAddOnsData, GetAddOnsResponse, GetAddonSplashData, GetAddonSplashResponse, GetHandlerSetSettingsData, GetHandlerSetSettingsResponse, GetSetsData, GetSetsResponse, GetSettingsData, GetSettingsResponse } from './types.gen';
import type { GetActionsData, GetActionsResponse, GetActionsBySetData, GetActionsBySetResponse, DownloadData, DownloadResponse, ImportSingleData, ImportSingleResponse, PerformActionData, PerformActionResponse2, ProcessUploadData, ProcessUploadResponse, CheckLegacyData, CheckLegacyResponse, CopyLegacyData, CopyLegacyResponse, IgnoreLegacyData, IgnoreLegacyResponse, GetAddOnsData, GetAddOnsResponse, GetAddonSplashData, GetAddonSplashResponse, GetHandlerSetSettingsData, GetHandlerSetSettingsResponse, GetSetsData, GetSetsResponse, GetSettingsData, GetSettingsResponse } from './types.gen';
import { client as _heyApiClient } from './client.gen';

export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean> = ClientOptions<TData, ThrowOnError> & {
Expand Down Expand Up @@ -43,6 +43,17 @@ export class ActionsService {
});
}

public static importSingle<ThrowOnError extends boolean = true>(options?: Options<ImportSingleData, ThrowOnError>) {
return (options?.client ?? _heyApiClient).post<ImportSingleResponse, unknown, ThrowOnError>({
url: '/umbraco/usync/api/v1/Import',
...options,
headers: {
'Content-Type': 'application/json',
...options?.headers
}
});
}

public static performAction<ThrowOnError extends boolean = true>(options?: Options<PerformActionData, ThrowOnError>) {
return (options?.client ?? _heyApiClient).post<PerformActionResponse2, unknown, ThrowOnError>({
url: '/umbraco/usync/api/v1/Perform',
Expand Down
Loading
Loading