diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/ICatalogueService.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/ICatalogueService.cs index f763808e..af8ba856 100644 --- a/OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/ICatalogueService.cs +++ b/OpenAPI/LearningHub.Nhs.OpenApi.Services.Interface/Services/ICatalogueService.cs @@ -238,5 +238,13 @@ public interface ICatalogueService /// The allcatalogue result based on letters. Task GetAllCataloguesAsync(string filterChar, int userId); + /// + /// The UpdateCatalogueOwnerAsync. + /// + /// The userId. + /// The catalogue owner. + /// The catalogue view model. + Task UpdateCatalogueOwnerAsync(int userId, CatalogueOwnerViewModel catalogueOwner); + } } \ No newline at end of file diff --git a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/CatalogueService.cs b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/CatalogueService.cs index 53810f5d..9c78cdb0 100644 --- a/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/CatalogueService.cs +++ b/OpenAPI/LearningHub.Nhs.OpenApi.Services/Services/CatalogueService.cs @@ -1190,6 +1190,18 @@ private LearningHubValidationResult ValidateEditAsync(CatalogueViewModel model) IsValid = !details.Any(), }; } + /// + /// The UpdateCatalogueOwnerAsync. + /// + /// The userId. + /// The catalogue owner. + /// The catalogue view model. + public async Task UpdateCatalogueOwnerAsync(int userId, CatalogueOwnerViewModel catalogueOwner) + { + await this.catalogueNodeVersionRepository.UpdateCatalogueOwnerAsync(userId, catalogueOwner); + + return new LearningHubValidationResult(true); + } } } diff --git a/OpenAPI/LearningHub.Nhs.OpenApi/Controllers/CatalogueController.cs b/OpenAPI/LearningHub.Nhs.OpenApi/Controllers/CatalogueController.cs index 55b812fd..35686597 100644 --- a/OpenAPI/LearningHub.Nhs.OpenApi/Controllers/CatalogueController.cs +++ b/OpenAPI/LearningHub.Nhs.OpenApi/Controllers/CatalogueController.cs @@ -374,5 +374,25 @@ public async Task AcceptAccessRequest(int accessRequestId) return this.Ok(await this.catalogueService.AcceptAccessAsync(this.CurrentUserId.GetValueOrDefault(), accessRequestId)); } + /// + /// The UpdateCatalogueOwner. + /// + /// The catalogue owner. + /// The updated catalogue owner. + [HttpPut] + [Route("UpdateCatalogueOwner")] + public async Task UpdateCatalogueOwner(CatalogueOwnerViewModel viewModel) + { + try + { + var vr = await this.catalogueService.UpdateCatalogueOwnerAsync(this.CurrentUserId.GetValueOrDefault(), viewModel); + return this.Ok(new ApiResponse(true, vr)); + } + catch (Exception ex) + { + return this.Ok(new ApiResponse(false, new LearningHubValidationResult(false, ex.Message))); + } + } + } }