forked from ddrilling/AsbCloudServer
CS2-123: Added AdminPermissionController and Service
This commit is contained in:
parent
cf517eabd5
commit
22c5d33b7e
@ -1,8 +1,7 @@
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class PermissionDto : IId
|
||||
public class PermissionDto
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int IdUserRole { get; set; }
|
||||
public int IdPermission { get; set; }
|
||||
public int PermissionValue { get; set; }
|
||||
|
12
AsbCloudApp/Data/PermissionInfoDto.cs
Normal file
12
AsbCloudApp/Data/PermissionInfoDto.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AsbCloudApp.Data
|
||||
{
|
||||
public class PermissionInfoDto : IId
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public string Description { get; set; }
|
||||
public IDictionary<int, string> BitDescription { get; set; }
|
||||
}
|
||||
}
|
17
AsbCloudApp/Services/IPermissionService.cs
Normal file
17
AsbCloudApp/Services/IPermissionService.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using AsbCloudApp.Data;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.Services
|
||||
{
|
||||
public interface IPermissionService
|
||||
{
|
||||
Task<IEnumerable<PermissionDto>> GetPermissionsAsync(int idRole, CancellationToken token);
|
||||
Task<int> InsertPermissionAsync(PermissionDto dto, CancellationToken token);
|
||||
Task<int> InsertPermissionsRangeAsync(IEnumerable<PermissionDto> dtos, CancellationToken token);
|
||||
Task<int> UpdatePermissionAsync(int id, PermissionDto dto, CancellationToken token);
|
||||
Task<int> DeletePermissionAsync(int idRole, int idPermission, CancellationToken token);
|
||||
|
||||
}
|
||||
}
|
@ -39,8 +39,8 @@ namespace AsbCloudDb.Model
|
||||
public virtual DbSet<DrillParams> DrillParams { get; set; }
|
||||
public virtual DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
||||
public virtual DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||
public virtual DbSet<Permission> RelationUserRolesPermissions { get; set; }
|
||||
public virtual DbSet<PermissionInfo> Permissions { get; set; }
|
||||
public virtual DbSet<Permission> Permissions { get; set; }
|
||||
public virtual DbSet<PermissionInfo> PermissionInfos { get; set; }
|
||||
|
||||
//var options = new DbContextOptionsBuilder<AsbCloudDbContext>()
|
||||
// .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
|
||||
|
@ -37,8 +37,8 @@ namespace AsbCloudDb.Model
|
||||
DbSet<DrillParams> DrillParams { get; set; }
|
||||
DbSet<DrillFlowChart> DrillFlowChart { get; set; }
|
||||
DbSet<RelationUserUserRole> RelationUserUserRoles { get; set; }
|
||||
DbSet<Permission> RelationUserRolesPermissions { get; set; }
|
||||
DbSet<PermissionInfo> Permissions { get; set; }
|
||||
DbSet<Permission> Permissions { get; set; }
|
||||
DbSet<PermissionInfo> PermissionInfos { get; set; }
|
||||
|
||||
DatabaseFacade Database { get; }
|
||||
|
||||
|
@ -6,7 +6,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
namespace AsbCloudDb.Model
|
||||
{
|
||||
[Table("t_permission_info"), Comment("Разрешения на доступ к данным")]
|
||||
public class PermissionInfo
|
||||
public class PermissionInfo : IId
|
||||
{
|
||||
[Key]
|
||||
[Column("id")]
|
||||
|
@ -169,7 +169,7 @@ namespace AsbCloudDevOperations
|
||||
new WellOperation { Id = 76341, IdWell = 1, IdWellSectionType = 1, IdCategory = 1047, IdType = 0, DepthEnd = 1250, DateStart = DateTime.Parse("2021-08-26 11:30"), DurationHours = 3.5 }
|
||||
);
|
||||
|
||||
demoContext.Permissions.AddRange(
|
||||
demoContext.PermissionInfos.AddRange(
|
||||
new PermissionInfo()
|
||||
{
|
||||
Id = 1,
|
||||
@ -186,7 +186,7 @@ namespace AsbCloudDevOperations
|
||||
}
|
||||
);
|
||||
|
||||
demoContext.RelationUserRolesPermissions.AddRange(
|
||||
demoContext.Permissions.AddRange(
|
||||
new Permission()
|
||||
{
|
||||
IdUserRole = 2,
|
||||
|
@ -58,6 +58,8 @@ namespace AsbCloudInfrastructure
|
||||
services.AddTransient<ICrudService<UserRoleDto>, UserRoleService>();
|
||||
services.AddTransient<ICrudService<TelemetryDto>, CrudServiceBase<TelemetryDto, Telemetry>>();
|
||||
services.AddTransient<ICrudService<DrillParamsDto>, DrillParamsService>();
|
||||
services.AddTransient<IPermissionService, PermissionService>();
|
||||
services.AddTransient<ICrudService<PermissionInfoDto>, CrudServiceBase<PermissionInfoDto, PermissionInfo>>();
|
||||
|
||||
// TelemetryData services
|
||||
services.AddTransient<ITelemetryDataService<TelemetryDataSaubDto>, TelemetryDataSaubService>();
|
||||
|
66
AsbCloudInfrastructure/Services/PermissionService.cs
Normal file
66
AsbCloudInfrastructure/Services/PermissionService.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb.Model;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
public class PermissionService : IPermissionService
|
||||
{
|
||||
private readonly IAsbCloudDbContext db;
|
||||
|
||||
public PermissionService(IAsbCloudDbContext db)
|
||||
{
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
|
||||
public async Task<IEnumerable<PermissionDto>> GetPermissionsAsync(int idRole, CancellationToken token)
|
||||
{
|
||||
var entities = await (from p in db.Permissions
|
||||
where p.IdUserRole == idRole
|
||||
select p)
|
||||
.ToListAsync(token).ConfigureAwait(false);
|
||||
var dto = entities.Adapt<PermissionDto>();
|
||||
return dto;
|
||||
}
|
||||
|
||||
public Task<int> InsertPermissionAsync(PermissionDto dto, CancellationToken token)
|
||||
{
|
||||
var entity = dto.Adapt<Permission>();
|
||||
db.Permissions.Add(entity);
|
||||
return db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public Task<int> InsertPermissionsRangeAsync(IEnumerable<PermissionDto> dtos, CancellationToken token)
|
||||
{
|
||||
var entities = dtos.Adapt<Permission>();
|
||||
|
||||
db.Permissions.AddRange(entities);
|
||||
return db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public Task<int> UpdatePermissionAsync(int id, PermissionDto dto, CancellationToken token)
|
||||
{
|
||||
var entity = dto.Adapt<Permission>();
|
||||
db.Permissions.Update(entity);
|
||||
return db.SaveChangesAsync(token);
|
||||
}
|
||||
|
||||
public Task<int> DeletePermissionAsync(int idRole, int idPermission, CancellationToken token)
|
||||
{
|
||||
var entities = db.Permissions.AsNoTracking()
|
||||
.Where(e => e.IdUserRole == idRole && e.IdPermission == idPermission)
|
||||
.ToList();
|
||||
if (!entities.Any())
|
||||
return Task.FromResult(0);
|
||||
db.Permissions.RemoveRange(entities);
|
||||
return db.SaveChangesAsync(token);
|
||||
}
|
||||
}
|
||||
}
|
23
AsbCloudWebApi/Controllers/AdminPermissionController.cs
Normal file
23
AsbCloudWebApi/Controllers/AdminPermissionController.cs
Normal file
@ -0,0 +1,23 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers
|
||||
{
|
||||
[Route("api/admin/user/permission")]
|
||||
[ApiController]
|
||||
[Authorize]
|
||||
public class AdminPermissionController : ControllerBase
|
||||
{
|
||||
private readonly IPermissionService permissionService;
|
||||
private readonly ICrudService<PermissionInfoDto> permissionInfoService;
|
||||
|
||||
public AdminPermissionController(IPermissionService permissionService,
|
||||
ICrudService<PermissionInfoDto> permissionInfoService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
this.permissionInfoService = permissionInfoService;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user