Skip to content

Commit

Permalink
Update repo-name, and move logic to service.
Browse files Browse the repository at this point in the history
  • Loading branch information
Konrad-Simso committed Feb 14, 2025
1 parent 2dfb619 commit 3bbb103
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace Altinn.Studio.Designer.Controllers.Organisation;
public class OrgTextController : ControllerBase
{
private readonly IOrgTextsService _orgTextsService;
private const string Repo = "content";

/// <summary>
/// Initializes a new instance of the <see cref="OrgTextController"/> class.
Expand All @@ -46,7 +45,7 @@ public async Task<ActionResult<TextResource>> 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)
Expand All @@ -73,8 +72,8 @@ public async Task<ActionResult<TextResource>> 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)
Expand Down Expand Up @@ -102,8 +101,8 @@ public async Task<ActionResult<TextResource>> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Altinn.Studio.Designer.Services.Implementation.Organisation;
public class OrgTextsService : IOrgTextsService
{
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
private const string Repo = "content";

/// <summary>
/// Constructor
Expand All @@ -24,9 +25,10 @@ public OrgTextsService(IAltinnGitRepositoryFactory altinnGitRepositoryFactory)
}

/// <inheritdoc />
public async Task<TextResource> GetText(string org, string repo, string developer, string languageCode, CancellationToken cancellationToken = default)
public async Task<TextResource> 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);
Expand All @@ -35,9 +37,10 @@ public async Task<TextResource> GetText(string org, string repo, string develope
}

/// <inheritdoc />
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();
Expand All @@ -52,9 +55,10 @@ public async Task SaveText(string org, string repo, string developer, TextResour


/// <inheritdoc />
public async Task UpdateTextsForKeys(string org, string repo, string developer, Dictionary<string, string> keysTexts, string languageCode, CancellationToken cancellationToken = default)
public async Task UpdateTextsForKeys(string org, string developer, Dictionary<string, string> 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);
Expand Down Expand Up @@ -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}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,31 @@ public interface IOrgTextsService
/// Gets texts file in organisation repository according to specified language Code.
/// </summary>
/// <param name="org">Organisation</param>
/// <param name="repo">Repository</param>
/// <param name="developer">Username of developer</param>
/// <param name="languageCode">LanguageCode</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns>The text file</returns>
public Task<TextResource> GetText(string org, string repo, string developer, string languageCode, CancellationToken cancellationToken = default);
public Task<TextResource> GetText(string org, string developer, string languageCode, CancellationToken cancellationToken = default);

/// <summary>
/// Saves text resource.
/// </summary>
/// <param name="org">Organisation</param>
/// <param name="repo">Repository</param>
/// <param name="developer">Username of developer</param>
/// <param name="textResource">The text resource to be saved</param>
/// <param name="languageCode">LanguageCode</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns></returns>
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);

/// <summary>
/// Updates values for specified keys in the text resouce.
/// </summary>
/// <param name="org">Organisation</param>
/// <param name="repo">Repository</param>
/// <param name="developer">Username of developer</param>
/// <param name="keysTexts">KeysTexts</param>
/// <param name="languageCode">LanguageCode</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns></returns>
public Task UpdateTextsForKeys(string org, string repo, string developer, Dictionary<string, string> keysTexts, string languageCode, CancellationToken cancellationToken = default);
public Task UpdateTextsForKeys(string org, string developer, Dictionary<string, string> keysTexts, string languageCode, CancellationToken cancellationToken = default);
}

0 comments on commit 3bbb103

Please sign in to comment.