Skip to content

Commit

Permalink
Revert "chore: cleanup backend endpoints (#14418)"
Browse files Browse the repository at this point in the history
This reverts commit d39bfff.
  • Loading branch information
Konrad-Simso committed Jan 20, 2025
1 parent d39bfff commit 3cd9e23
Show file tree
Hide file tree
Showing 36 changed files with 1,920 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System.Collections.Generic;
using System.Threading.Tasks;

using Altinn.Studio.Designer.Services.Interfaces;
using Altinn.Studio.Designer.TypedHttpClients.KubernetesWrapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace Altinn.Studio.Designer.Controllers
{
/// <summary>
/// Controller for getting kubernetes deployments
/// </summary>
[ApiController]
[Authorize]
[AutoValidateAntiforgeryToken]
[Route("/designer/api/{org}/{app:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/kubernetesDeployments")]
public class KubernetesDeploymentsController : ControllerBase
{
private readonly IKubernetesDeploymentsService _kubernetesDeploymentsService;

/// <summary>
/// Constructor
/// </summary>
/// <param name="kubernetesDeploymentsService">IKubernetesDeploymentsService</param>
public KubernetesDeploymentsController(IKubernetesDeploymentsService kubernetesDeploymentsService)
{
_kubernetesDeploymentsService = kubernetesDeploymentsService;
}

/// <summary>
/// Gets kubernetes deployments
/// </summary>
/// <param name="org">Organisation</param>
/// <param name="app">Application name</param>
/// <returns>List of kubernetes deployments</returns>
[HttpGet]
[ApiConventionMethod(typeof(DefaultApiConventions), nameof(DefaultApiConventions.Get))]
public async Task<List<KubernetesDeployment>> Get(string org, string app)
{
return await _kubernetesDeploymentsService.GetAsync(org, app);
}
}
}
49 changes: 49 additions & 0 deletions backend/src/Designer/Controllers/LanguagesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections.Generic;

using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Services.Interfaces;

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Altinn.Studio.Designer.Controllers
{
/// <summary>
/// Controller containing actions related to languages
/// </summary>
[Authorize]
[AutoValidateAntiforgeryToken]
[Route("designer/api/{org}/{repo:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/languages")]
public class LanguagesController : ControllerBase
{
private readonly ILanguagesService _languagesService;

/// <summary>
/// Initializes a new instance of the <see cref="LanguagesController"/> class.
/// </summary>
/// <param name="languagesService">The languages service.</param>
public LanguagesController(ILanguagesService languagesService)
{
_languagesService = languagesService;
}

/// <summary>
/// Endpoint for getting the available languages in the application.
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repo">Application identifier which is unique within an organisation.</param>
/// <returns>List of languages as JSON</returns>
[HttpGet]
[Produces("application/json")]
[ProducesResponseType(StatusCodes.Status200OK)]
public ActionResult<List<string>> GetLanguages(string org, string repo)
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);

List<string> languages = new List<string>(_languagesService.GetLanguages(org, repo, developer));

return Ok(languages);
}
}
}
23 changes: 23 additions & 0 deletions backend/src/Designer/Controllers/ProcessModelingController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Mime;
using System.Text.Json;
Expand All @@ -13,6 +14,7 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NuGet.Versioning;

namespace Altinn.Studio.Designer.Controllers
{
Expand Down Expand Up @@ -100,6 +102,27 @@ await _mediator.Publish(new ProcessDataTypesChangedEvent
return Accepted();
}

[HttpGet("templates/{appVersion}")]
public IEnumerable<string> GetTemplates(string org, string repo, SemanticVersion appVersion)
{
Guard.AssertArgumentNotNull(appVersion, nameof(appVersion));
return _processModelingService.GetProcessDefinitionTemplates(appVersion);
}

[HttpPut("templates/{appVersion}/{templateName}")]
public async Task<FileStreamResult> SaveProcessDefinitionFromTemplate(string org, string repo,
SemanticVersion appVersion, string templateName, CancellationToken cancellationToken)
{
Guard.AssertArgumentNotNull(appVersion, nameof(appVersion));
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer);
await _processModelingService.SaveProcessDefinitionFromTemplateAsync(editingContext, templateName,
appVersion, cancellationToken);

Stream processDefinitionStream = _processModelingService.GetProcessDefinitionStream(editingContext);
return new FileStreamResult(processDefinitionStream, MediaTypeNames.Text.Plain);
}

[HttpPost("data-type/{dataTypeId}")]
public async Task<ActionResult> AddDataTypeToApplicationMetadata(string org, string repo, [FromRoute] string dataTypeId, [FromQuery] string taskId, CancellationToken cancellationToken)
{
Expand Down
142 changes: 142 additions & 0 deletions backend/src/Designer/Controllers/RepositoryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,32 @@ public async Task<ActionResult> Push(string org, string repository)
return pushSuccess ? Ok() : StatusCode(StatusCodes.Status500InternalServerError);
}

/// <summary>
/// Fetches the repository log
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repository">The repo name</param>
/// <returns>List of commits</returns>
[HttpGet]
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/log")]
public List<Commit> Log(string org, string repository)
{
return _sourceControl.Log(org, repository);
}

/// <summary>
/// Fetches the initial commit
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repository">The repo name</param>
/// <returns>The initial commit</returns>
[HttpGet]
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/initial-commit")]
public Commit GetInitialCommit(string org, string repository)
{
return _sourceControl.GetInitialCommit(org, repository);
}

/// <summary>
/// Gets the latest commit from current user
/// </summary>
Expand All @@ -356,6 +382,82 @@ public Commit GetLatestCommitFromCurrentUser(string org, string repository)
return _sourceControl.GetLatestCommitForCurrentUser(org, repository);
}

/// <summary>
/// List all branches for a repository
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repository">The repository</param>
/// <returns>List of repos</returns>
[HttpGet]
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/branches")]
public async Task<List<Branch>> Branches(string org, string repository)
=> await _giteaApi.GetBranches(org, repository);

/// <summary>
/// Returns information about a given branch
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repository">The name of repository</param>
/// <param name="branch">Name of branch</param>
/// <returns>The branch info</returns>
[HttpGet]
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/branches/branch")]
public async Task<Branch> Branch(string org, string repository, [FromQuery] string branch)
=> await _giteaApi.GetBranch(org, repository, branch);

/// <summary>
/// Discards all local changes for the logged in user and the local repository is updated with latest remote commit (origin/master)
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repository">The name of repository</param>
/// <returns>Http response message as ok if reset operation is successful</returns>
[HttpGet]
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/discard")]
public ActionResult DiscardLocalChanges(string org, string repository)
{
try
{
if (string.IsNullOrEmpty(org) || string.IsNullOrEmpty(repository))
{
return ValidationProblem("One or all of the input parameters are null");
}

_sourceControl.ResetCommit(org, repository);
return Ok();
}
catch (Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
}

/// <summary>
/// Discards local changes to a specific file and the files is updated with latest remote commit (origin/master)
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repository">The name of repository</param>
/// <param name="fileName">the name of the file</param>
/// <returns>Http response message as ok if checkout operation is successful</returns>
[HttpGet]
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/discard/{fileName}")]
public ActionResult DiscardLocalChangesForSpecificFile(string org, string repository, string fileName)
{
try
{
if (string.IsNullOrEmpty(org) || string.IsNullOrEmpty(repository) || string.IsNullOrEmpty(fileName))
{
return ValidationProblem("One or all of the input parameters are null");
}

_sourceControl.CheckoutLatestCommitForSpecificFile(org, repository, fileName);
return Ok();
}
catch (Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}
}

/// <summary>
/// Stages a specific file changed in working repository.
/// </summary>
Expand Down Expand Up @@ -383,6 +485,46 @@ public ActionResult StageChange(string org, string repository, string fileName)
}
}

/// <summary>
/// Clones the remote repository
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repository">The name of repository</param>
/// <returns>The result of the cloning</returns>
[HttpGet]
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/clone")]
public Task<string> CloneRemoteRepository(string org, string repository)
{
return _sourceControl.CloneRemoteRepository(org, repository);
}

/// <summary>
/// Halts the merge operation and keeps local changes
/// </summary>
/// <param name="org">Unique identifier of the organisation responsible for the app.</param>
/// <param name="repository">The name of the repository</param>
/// <returns>Http response message as ok if abort merge operation is successful</returns>
[HttpGet]
[Route("repo/{org}/{repository:regex(^(?!datamodels$)[[a-z]][[a-z0-9-]]{{1,28}}[[a-z0-9]]$)}/abort-merge")]
public ActionResult AbortMerge(string org, string repository)
{
try
{
if (string.IsNullOrEmpty(org) || string.IsNullOrEmpty(repository))
{
return ValidationProblem("One or all of the input parameters are null");
}

_sourceControl.AbortMerge(org, repository);

return Ok();
}
catch (Exception)
{
return StatusCode(StatusCodes.Status500InternalServerError);
}

Check notice

Code scanning / CodeQL

Generic catch clause Note

Generic catch clause.
}

/// <summary>
/// Gets the repository content
/// </summary>
Expand Down
Loading

0 comments on commit 3cd9e23

Please sign in to comment.