Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Performance #139

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/api/Areas/Admin/Controllers/GroupController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using HSB.Core.Exceptions;
using Microsoft.AspNetCore.Http.Extensions;

namespace HSB.API.Areas.SystemAdmin.Controllers;
namespace HSB.API.Areas.Admin.Controllers;

/// <summary>
/// GroupController class, provides endpoints for groups.
Expand Down Expand Up @@ -49,7 +49,7 @@ public GroupController(IGroupService service, ILogger<GroupController> logger)
[HttpGet(Name = "GetGroups-SystemAdmin")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(IEnumerable<GroupModel>), (int)HttpStatusCode.OK)]
[SwaggerOperation(Tags = new[] { "Group" })]
[SwaggerOperation(Tags = ["Group"])]
public IActionResult Find()
{
var uri = new Uri(this.Request.GetDisplayUrl());
Expand All @@ -60,15 +60,15 @@ public IActionResult Find()
}

/// <summary>
///
/// Get the group for the specified 'id'.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}", Name = "GetGroup-SystemAdmin")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(GroupModel), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[SwaggerOperation(Tags = new[] { "Group" })]
[SwaggerOperation(Tags = ["Group"])]
public IActionResult GetForId(int id)
{
var group = _service.FindForId(id);
Expand All @@ -79,15 +79,15 @@ public IActionResult GetForId(int id)
}

/// <summary>
///
/// Add a new group to the database.
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPost(Name = "AddGroup-SystemAdmin")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(GroupModel), (int)HttpStatusCode.Created)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Group" })]
[SwaggerOperation(Tags = ["Group"])]
public IActionResult Add(GroupModel model)
{
var entity = model.ToEntity();
Expand All @@ -97,15 +97,15 @@ public IActionResult Add(GroupModel model)
}

/// <summary>
///
/// Update the group for the specified 'id'.
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpPut("{id}", Name = "UpdateGroup-SystemAdmin")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(GroupModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Group" })]
[SwaggerOperation(Tags = ["Group"])]
public IActionResult Update(GroupModel model)
{
var entity = model.ToEntity();
Expand All @@ -115,15 +115,15 @@ public IActionResult Update(GroupModel model)
}

/// <summary>
///
/// Delete the group from the database.
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
[HttpDelete("{id}", Name = "RemoveGroup-SystemAdmin")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(GroupModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Group" })]
[SwaggerOperation(Tags = ["Group"])]
public IActionResult Remove(GroupModel model)
{
var entity = model.ToEntity() ?? throw new NoContentException();
Expand Down
17 changes: 9 additions & 8 deletions src/api/Areas/Admin/Controllers/OrganizationController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net.Mime;
using HSB.Models;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using HSB.Core.Models;
Expand All @@ -8,9 +7,9 @@
using HSB.Keycloak;
using HSB.Core.Exceptions;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Caching.Memory;
using HSB.Models.Admin;

namespace HSB.API.Areas.SystemAdmin.Controllers;
namespace HSB.API.Areas.Admin.Controllers;

/// <summary>
/// OrganizationController class, provides endpoints for organizations.
Expand Down Expand Up @@ -52,7 +51,7 @@ public OrganizationController(
[HttpGet(Name = "GetOrganizations-SystemAdmin")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(IEnumerable<OrganizationModel>), (int)HttpStatusCode.OK)]
[SwaggerOperation(Tags = new[] { "Organization" })]
[SwaggerOperation(Tags = ["Organization"])]
public IActionResult Find()
{
var uri = new Uri(this.Request.GetDisplayUrl());
Expand All @@ -71,7 +70,7 @@ public IActionResult Find()
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[SwaggerOperation(Tags = new[] { "Organization" })]
[SwaggerOperation(Tags = ["Organization"])]
public IActionResult GetForId(int id)
{
var organization = _service.FindForId(id);
Expand All @@ -90,7 +89,7 @@ public IActionResult GetForId(int id)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.Created)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Organization" })]
[SwaggerOperation(Tags = ["Organization"])]
public IActionResult Add(OrganizationModel model)
{
var entity = model.ToEntity();
Expand All @@ -112,10 +111,12 @@ public IActionResult Add(OrganizationModel model)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Organization" })]
[SwaggerOperation(Tags = ["Organization"])]
public IActionResult Update(OrganizationModel model)
{
var original = _service.FindForIdAsNoTracking(model.Id) ?? throw new NoContentException();
var entity = model.ToEntity();
entity.RawData = original.RawData;
_service.Update(entity);
_service.CommitTransaction();

Expand All @@ -133,7 +134,7 @@ public IActionResult Update(OrganizationModel model)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(OrganizationModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Organization" })]
[SwaggerOperation(Tags = ["Organization"])]
public IActionResult Remove(OrganizationModel model)
{
var entity = model.ToEntity() ?? throw new NoContentException();
Expand Down
12 changes: 6 additions & 6 deletions src/api/Areas/Admin/Controllers/RoleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using HSB.Models;
using HSB.Keycloak;

namespace HSB.API.Areas.SystemAdmin.Controllers;
namespace HSB.API.Areas.Admin.Controllers;

/// <summary>
/// RoleController class, provides endpoints for roles.
Expand Down Expand Up @@ -49,7 +49,7 @@ public RoleController(IRoleService service, ILogger<RoleController> logger)
[HttpGet(Name = "GetRoles-SystemAdmin")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(IEnumerable<RoleModel>), (int)HttpStatusCode.OK)]
[SwaggerOperation(Tags = new[] { "Role" })]
[SwaggerOperation(Tags = ["Role"])]
public IActionResult Find()
{
var uri = new Uri(this.Request.GetDisplayUrl());
Expand All @@ -68,7 +68,7 @@ public IActionResult Find()
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(RoleModel), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[SwaggerOperation(Tags = new[] { "Role" })]
[SwaggerOperation(Tags = ["Role"])]
public IActionResult GetForId(int id)
{
var role = _service.FindForId(id);
Expand All @@ -87,7 +87,7 @@ public IActionResult GetForId(int id)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(RoleModel), (int)HttpStatusCode.Created)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Role" })]
[SwaggerOperation(Tags = ["Role"])]
public IActionResult Add(RoleModel model)
{
var entity = model.ToEntity();
Expand All @@ -105,7 +105,7 @@ public IActionResult Add(RoleModel model)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(RoleModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Role" })]
[SwaggerOperation(Tags = ["Role"])]
public IActionResult Update(RoleModel model)
{
var entity = model.ToEntity();
Expand All @@ -123,7 +123,7 @@ public IActionResult Update(RoleModel model)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(RoleModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Role" })]
[SwaggerOperation(Tags = ["Role"])]
public IActionResult Remove(RoleModel model)
{
var entity = model.ToEntity() ?? throw new NoContentException();
Expand Down
16 changes: 9 additions & 7 deletions src/api/Areas/Admin/Controllers/TenantController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Net.Mime;
using HSB.Models;
using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using HSB.Core.Models;
Expand All @@ -8,8 +7,9 @@
using HSB.Keycloak;
using HSB.Core.Exceptions;
using Microsoft.AspNetCore.Http.Extensions;
using HSB.Models.Admin;

namespace HSB.API.Areas.SystemAdmin.Controllers;
namespace HSB.API.Areas.Admin.Controllers;

/// <summary>
/// TenantController class, provides endpoints for tenants.
Expand Down Expand Up @@ -49,7 +49,7 @@ public TenantController(ITenantService service, ILogger<TenantController> logger
[HttpGet(Name = "GetTenants-SystemAdmin")]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(IEnumerable<TenantModel>), (int)HttpStatusCode.OK)]
[SwaggerOperation(Tags = new[] { "Tenant" })]
[SwaggerOperation(Tags = ["Tenant"])]
public IActionResult Find()
{
var uri = new Uri(this.Request.GetDisplayUrl());
Expand All @@ -68,7 +68,7 @@ public IActionResult Find()
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(TenantModel), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
[SwaggerOperation(Tags = new[] { "Tenant" })]
[SwaggerOperation(Tags = ["Tenant"])]
public IActionResult GetForId(int id)
{
var tenant = _service.FindForId(id);
Expand All @@ -87,7 +87,7 @@ public IActionResult GetForId(int id)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(TenantModel), (int)HttpStatusCode.Created)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Tenant" })]
[SwaggerOperation(Tags = ["Tenant"])]
public IActionResult Add(TenantModel model)
{
var entity = model.ToEntity();
Expand All @@ -108,10 +108,12 @@ public IActionResult Add(TenantModel model)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(TenantModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Tenant" })]
[SwaggerOperation(Tags = ["Tenant"])]
public IActionResult Update(TenantModel model)
{
var original = _service.FindForIdAsNoTracking(model.Id) ?? throw new NoContentException();
var entity = model.ToEntity();
entity.RawData = original.RawData;
_service.Update(entity);
_service.CommitTransaction();

Expand All @@ -129,7 +131,7 @@ public IActionResult Update(TenantModel model)
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(typeof(TenantModel), (int)HttpStatusCode.OK)]
[ProducesResponseType(typeof(ErrorResponseModel), (int)HttpStatusCode.BadRequest)]
[SwaggerOperation(Tags = new[] { "Tenant" })]
[SwaggerOperation(Tags = ["Tenant"])]
public IActionResult Remove(TenantModel model)
{
var entity = model.ToEntity() ?? throw new NoContentException();
Expand Down
2 changes: 1 addition & 1 deletion src/api/Areas/Admin/Controllers/UserController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.Annotations;

namespace HSB.API.Areas.SystemAdmin.Controllers;
namespace HSB.API.Areas.Admin.Controllers;

/// <summary>
/// UserController class, provides User endpoints for the admin api.
Expand Down
7 changes: 7 additions & 0 deletions src/libs/dal/Services/IOrganizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ namespace HSB.DAL.Services;

public interface IOrganizationService : IBaseService<Organization>
{
/// <summary>
/// Find the entity for the specified `keyValues`.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Organization? FindForIdAsNoTracking(int id);

IEnumerable<Organization> Find(
Models.Filters.OrganizationFilter filter);

Expand Down
7 changes: 7 additions & 0 deletions src/libs/dal/Services/ITenantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ namespace HSB.DAL.Services;

public interface ITenantService : IBaseService<Tenant>
{
/// <summary>
/// Find the entity for the specified `keyValues`.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Tenant? FindForIdAsNoTracking(int id);

IEnumerable<Tenant> Find(
Models.Filters.TenantFilter filter);

Expand Down
11 changes: 11 additions & 0 deletions src/libs/dal/Services/OrganizationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ public OrganizationService(HSBContext dbContext, ClaimsPrincipal principal, ISer
#endregion

#region Methods
/// <summary>
/// Find the entity for the specified `keyValues`.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Organization? FindForIdAsNoTracking(int id)
{
return this.Context.Organizations.AsNoTracking()
.FirstOrDefault(t => t.Id == id);
}

public IEnumerable<Organization> Find(Models.Filters.OrganizationFilter filter)
{
var query = from org in this.Context.Organizations
Expand Down
21 changes: 21 additions & 0 deletions src/libs/dal/Services/TenantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,37 @@

namespace HSB.DAL.Services;

/// <summary>
///
/// </summary>
public class TenantService : BaseService<Tenant>, ITenantService
{
#region Constructors
/// <summary>
///
/// </summary>
/// <param name="dbContext"></param>
/// <param name="principal"></param>
/// <param name="serviceProvider"></param>
/// <param name="logger"></param>
public TenantService(HSBContext dbContext, ClaimsPrincipal principal, IServiceProvider serviceProvider, ILogger<TenantService> logger)
: base(dbContext, principal, serviceProvider, logger)
{
}
#endregion

#region Methods
/// <summary>
/// Find the entity for the specified `keyValues`.
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public Tenant? FindForIdAsNoTracking(int id)
{
return this.Context.Tenants.AsNoTracking()
.FirstOrDefault(t => t.Id == id);
}

public IEnumerable<Tenant> Find(
Models.Filters.TenantFilter filter)
{
Expand Down
Loading
Loading