Controllers¶
Generally we want to create an API controller to expose this service as an HTTP (REST) API endpoint. A typical API controller does nothing but redirects method calls to the application service and configures the REST API using attributes like [HttpGet], [HttpPost], [Route]... etc.
- Do create a controller for each aggregate root.
- Do use the
AppService
interface (ex:IProjectAppService
) and decorate with web verbs. - Do order methods according to C / R / U / D
- Do create version folder each controller
- Do not use
auto api
feature of the platform
Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.ConventionalControllers.Create(typeof(PSSXApplicationModule).Assembly);
});
- Do provide version number for each controller
- Do provide summary for each method, this will be displayed at swagger interface
[ApiVersion("1.0", Deprecated = false)]
[RemoteService(Name = ProjectPlanningRemoteServiceConsts.RemoteServiceName)]
[ControllerName("Projects")]
[Route("api/project-planning/projects")]
public class ProjectController : ProjectPlanningController, IProjectAppService
{
protected IProjectAppService ProjectAppService { get; }
public ProjectController(IProjectAppService projectAppService)
{
ProjectAppService = projectAppService;
}
/// <summary>
/// Creates new project with given basic properties
/// </summary>
/// <param name="input"></param>
/// <returns>Project information</returns>
[HttpPost]
public virtual async Task<ProjectDto> CreateAsync(CreateProjectInput input)
{
return await ProjectAppService.CreateAsync(input);
}
/// <summary>
/// Lists the properties of the project which id is given
/// </summary>
/// <param name="id">Database id of the project</param>
/// <returns>Project information</returns>
[HttpGet]
[Route("{id}")]
public virtual async Task<ProjectDto> GetAsync(Guid id)
{
return await ProjectAppService.GetAsync(id);
}
/// <summary>
/// Lists of the projects which filter is given
/// </summary>
/// <param name="input"></param>
/// <returns>Project information</returns>
[HttpGet]
public virtual async Task<PagedResultDto<ProjectDto>> GetListAsync(GetProjectInput input)
{
return await ProjectAppService.GetListAsync(input);
}
/// <summary>
/// Lists the properties of the project and its relations which id is given
/// </summary>
/// <param name="id">Database id of the project</param>
/// <returns>Project information</returns>
[HttpGet]
[Route("{id}/properties")]
public virtual async Task<ProjectWithNavigationPropertiesDto> GetWithNavigationPropertiesAsync(Guid id)
{
return await ProjectAppService.GetWithNavigationPropertiesAsync(id);
}
/// <summary>
/// Lists of the projects which filter is given
/// </summary>
/// <param name="input"></param>
/// <returns>Project information</returns>
[HttpGet]
[Route("properties")]
public virtual async Task<PagedResultDto<ProjectWithNavigationPropertiesDto>> GetListWithNavigationPropertiesAsync(GetProjectWithNavigationPropertiesInput input)
{
return await ProjectAppService.GetListWithNavigationPropertiesAsync(input);
}
[HttpGet]
[Route("lookup/definitions")]
public Task<List<DefinitionDto>> GetDefinitionLookupAsync(GetDefinitionInput input)
{
return ProjectAppService.GetDefinitionLookupAsync(input);
}
[HttpGet]
[Route("lookup/{id}/transitions")]
public Task<List<string>> GetPermittedTransitionsLookupAsync(Guid id, GetPermittedTransitionsInput input)
{
return ProjectAppService.GetPermittedTransitionsLookupAsync(id, input);
}
[HttpGet]
[Route("lookup/{id}/possible-states")]
public Task<List<string>> GetNextPossibleStatesLookupAsync(Guid id, GetPossibleStatesInput input)
{
return ProjectAppService.GetNextPossibleStatesLookupAsync(id, input);
}
[HttpGet]
[Route("lookup/{id}/all-states")]
public Task<List<string>> GetStatesLookupAsync(Guid id)
{
return ProjectAppService.GetStatesLookupAsync(id);
}
/// <summary>
/// Updates properties of the project
/// </summary>
/// <param name="input"></param>
/// <param name="id">Database id of the project</param>
/// <returns>Project information</returns>
[HttpPut]
[Route("{id}")]
public virtual async Task<ProjectDto> UpdateAsync(Guid id, UpdateProjectInput input)
{
return await ProjectAppService.UpdateAsync(id, input);
}
/// <summary>
/// Assigns organization unit to the project
/// </summary>
/// <param name="input"></param>
/// <param name="id">Project identification</param>
/// <returns>Project information</returns>
[HttpPut]
[Route("{id}/assign-organization-unit")]
public virtual async Task<ProjectDto> AssignOrganizationUnitAsync(Guid id, AssignOrganizationUnitInput input)
{
return await ProjectAppService.AssignOrganizationUnitAsync(id, input);
}
/// <summary>
/// Changes owner of the project
/// </summary>
/// <param name="input"></param>
/// <param name="id">Project identification</param>
/// <returns>Project information</returns>
[HttpPut]
[Route("{id}/change-owner")]
public virtual async Task<ProjectDto> ChangeOwnerAsync(Guid id, ChangeOwnerInput input)
{
return await ProjectAppService.ChangeOwnerAsync(id, input);
}
/// <summary>
/// Changes priority of the project
/// </summary>
/// <param name="input"></param>
/// <param name="id">Project identification</param>
/// <returns>Project information</returns>
[HttpPut]
[Route("{id}/change-priority")]
public virtual async Task<ProjectDto> ChangePriority(Guid id, ChangePriorityInput input)
{
return await ProjectAppService.ChangePriority(id, input);
}
/// <summary>
/// Changes state of the project
/// </summary>
/// <param name="input"></param>
/// <param name="id">Project identification</param>
/// <returns>Project information</returns>
[HttpPut]
[Route("{id}/change-state")]
public Task<ProjectDto> ChangeStateAsync(Guid id, ChangeStateInput input)
{
return ProjectAppService.ChangeStateAsync(id, input);
}
/// <summary>
/// Sync project states with existing workflow
/// </summary>
/// <param name="input"></param>
/// <param name="id">Project identification</param>
/// <returns>Project information</returns>
[HttpPut]
[Route("{id}/sync-with-workflow")]
public Task<ProjectDto> SyncWithWorkflowStateAsync(Guid id)
{
return ProjectAppService.SyncWithWorkflowStateAsync(id);
}
/// <summary>
/// Deletes project with id
/// </summary>
/// <param name="id">Database id of the project</param>
[HttpDelete]
[Route("{id}")]
public virtual async Task DeleteAsync(Guid id)
{
await ProjectAppService.DeleteAsync(id);
}
}