From 3bbb103269576475ddfc3be36bcfecec3c83a41a Mon Sep 17 00:00:00 2001 From: Konrad-Simso Date: Fri, 14 Feb 2025 15:03:56 +0100 Subject: [PATCH] Update repo-name, and move logic to service. --- .../Controllers/Organisation/OrgTextController.cs | 11 +++++------ .../Organisation/OrgTextsService.cs | 15 ++++++++++++--- .../Interfaces/Organisation/IOrgTextsService.cs | 9 +++------ 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/backend/src/Designer/Controllers/Organisation/OrgTextController.cs b/backend/src/Designer/Controllers/Organisation/OrgTextController.cs index 36ac666da50..c6534861096 100644 --- a/backend/src/Designer/Controllers/Organisation/OrgTextController.cs +++ b/backend/src/Designer/Controllers/Organisation/OrgTextController.cs @@ -20,7 +20,6 @@ namespace Altinn.Studio.Designer.Controllers.Organisation; public class OrgTextController : ControllerBase { private readonly IOrgTextsService _orgTextsService; - private const string Repo = "content"; /// /// Initializes a new instance of the class. @@ -46,7 +45,7 @@ public async Task> GetResource(string org, string lan string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext); try { - TextResource textResource = await _orgTextsService.GetText(org, Repo, developer, languageCode, cancellationToken); + TextResource textResource = await _orgTextsService.GetText(org, developer, languageCode, cancellationToken); return Ok(textResource); } catch (NotFoundException) @@ -73,8 +72,8 @@ public async Task> CreateResource([FromBody] TextReso try { - await _orgTextsService.SaveText(org, Repo, developer, jsonData, languageCode, cancellationToken); - TextResource textResource = await _orgTextsService.GetText(org, Repo, developer, languageCode, cancellationToken); + await _orgTextsService.SaveText(org, developer, jsonData, languageCode, cancellationToken); + TextResource textResource = await _orgTextsService.GetText(org, developer, languageCode, cancellationToken); return Ok(textResource); } catch (ArgumentException e) @@ -102,8 +101,8 @@ public async Task> UpdateResource(string org, [FromBo try { - await _orgTextsService.UpdateTextsForKeys(org, Repo, developer, keysTexts, languageCode, cancellationToken); - TextResource textResource = await _orgTextsService.GetText(org, Repo, developer, languageCode, cancellationToken); + await _orgTextsService.UpdateTextsForKeys(org, developer, keysTexts, languageCode, cancellationToken); + TextResource textResource = await _orgTextsService.GetText(org, developer, languageCode, cancellationToken); return Ok(textResource); } catch (ArgumentException exception) diff --git a/backend/src/Designer/Services/Implementation/Organisation/OrgTextsService.cs b/backend/src/Designer/Services/Implementation/Organisation/OrgTextsService.cs index b7d7581cc30..6cf1e5de520 100644 --- a/backend/src/Designer/Services/Implementation/Organisation/OrgTextsService.cs +++ b/backend/src/Designer/Services/Implementation/Organisation/OrgTextsService.cs @@ -13,6 +13,7 @@ namespace Altinn.Studio.Designer.Services.Implementation.Organisation; public class OrgTextsService : IOrgTextsService { private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory; + private const string Repo = "content"; /// /// Constructor @@ -24,9 +25,10 @@ public OrgTextsService(IAltinnGitRepositoryFactory altinnGitRepositoryFactory) } /// - public async Task GetText(string org, string repo, string developer, string languageCode, CancellationToken cancellationToken = default) + public async Task GetText(string org, string developer, string languageCode, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); + string repo = GetStaticContentRepo(org); AltinnOrgGitRepository altinnOrgGitRepository = _altinnGitRepositoryFactory.GetAltinnOrgGitRepository(org, repo, developer); TextResource texts = await altinnOrgGitRepository.GetText(languageCode, cancellationToken); @@ -35,9 +37,10 @@ public async Task GetText(string org, string repo, string develope } /// - public async Task SaveText(string org, string repo, string developer, TextResource textResource, string languageCode, CancellationToken cancellationToken = default) + public async Task SaveText(string org, string developer, TextResource textResource, string languageCode, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); + string repo = GetStaticContentRepo(org); AltinnOrgGitRepository altinnOrgGitRepository = _altinnGitRepositoryFactory.GetAltinnOrgGitRepository(org, repo, developer); string[] duplicateKeys = textResource.Resources.GroupBy(tre => tre.Id).Where(grp => grp.Count() > 1).Select(grp => grp.Key).ToArray(); @@ -52,9 +55,10 @@ public async Task SaveText(string org, string repo, string developer, TextResour /// - public async Task UpdateTextsForKeys(string org, string repo, string developer, Dictionary keysTexts, string languageCode, CancellationToken cancellationToken = default) + public async Task UpdateTextsForKeys(string org, string developer, Dictionary keysTexts, string languageCode, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); + string repo = GetStaticContentRepo(org); AltinnOrgGitRepository altinnOrgGitRepository = _altinnGitRepositoryFactory.GetAltinnOrgGitRepository(org, repo, developer); TextResource textResourceObject = await altinnOrgGitRepository.GetText(languageCode, cancellationToken); @@ -84,4 +88,9 @@ public async Task UpdateTextsForKeys(string org, string repo, string developer, await altinnOrgGitRepository.SaveText(languageCode, textResourceObject, cancellationToken); } + + private static string GetStaticContentRepo(string org) + { + return $"{org}-{Repo}"; + } } diff --git a/backend/src/Designer/Services/Interfaces/Organisation/IOrgTextsService.cs b/backend/src/Designer/Services/Interfaces/Organisation/IOrgTextsService.cs index 4c52873be83..984462528cb 100644 --- a/backend/src/Designer/Services/Interfaces/Organisation/IOrgTextsService.cs +++ b/backend/src/Designer/Services/Interfaces/Organisation/IOrgTextsService.cs @@ -11,34 +11,31 @@ public interface IOrgTextsService /// Gets texts file in organisation repository according to specified language Code. /// /// Organisation - /// Repository /// Username of developer /// LanguageCode /// A that observes if operation is cancelled. /// The text file - public Task GetText(string org, string repo, string developer, string languageCode, CancellationToken cancellationToken = default); + public Task GetText(string org, string developer, string languageCode, CancellationToken cancellationToken = default); /// /// Saves text resource. /// /// Organisation - /// Repository /// Username of developer /// The text resource to be saved /// LanguageCode /// A that observes if operation is cancelled. /// - public Task SaveText(string org, string repo, string developer, TextResource textResource, string languageCode, CancellationToken cancellationToken = default); + public Task SaveText(string org, string developer, TextResource textResource, string languageCode, CancellationToken cancellationToken = default); /// /// Updates values for specified keys in the text resouce. /// /// Organisation - /// Repository /// Username of developer /// KeysTexts /// LanguageCode /// A that observes if operation is cancelled. /// - public Task UpdateTextsForKeys(string org, string repo, string developer, Dictionary keysTexts, string languageCode, CancellationToken cancellationToken = default); + public Task UpdateTextsForKeys(string org, string developer, Dictionary keysTexts, string languageCode, CancellationToken cancellationToken = default); }