增加数据库角色、角色组和应用表

This commit is contained in:
falcon 2020-04-14 11:43:48 +08:00
parent 6854cfbaec
commit f2a8d4566f
9 changed files with 188 additions and 1 deletions

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace FAuth.Controllers.api
{
/// <summary>
/// 角色控制器
/// </summary>
public class RoleController:ApiControllerBase<RoleController>
{
public RoleController(ILogger<RoleController> logger,IServiceProvider service) : base(logger,service) {
}
}
}

View File

@ -11,9 +11,42 @@ namespace FAuth.DataBase
public FAuthDb(DbContextOptions options) : base(options) {
Database.EnsureCreatedAsync().Wait();
}
protected override void OnModelCreating(ModelBuilder modelBuilder) {
var mb = modelBuilder;
mb.Entity<App_RoleGroup>().HasKey(m => new { m.AppId,m.RoleGroupId });
mb.Entity<RoleGroup_Role>().HasKey(m => new { m.RoleGroupId,m.RoleId });
mb.Entity<Role_User>().HasKey(m => new { m.RoleId,m.UserId });
base.OnModelCreating(modelBuilder);
}
/// <summary>
/// 用户表
/// 用户
/// </summary>
public DbSet<FUser> Users { get; set; }
/// <summary>
/// 应用信息
/// </summary>
public DbSet<Apps> Apps { get; set; }
/// <summary>
/// 角色组信息
/// </summary>
public DbSet<RoleGroup> RoleGroups { get; set; }
/// <summary>
/// 角色信息
/// </summary>
public DbSet<Roles> Roles { get; set; }
/// <summary>
/// 应用角色组对应关系
/// </summary>
public DbSet<App_RoleGroup> App_RoleGroups { get; set; }
/// <summary>
/// 角色组角色对应关系
/// </summary>
public DbSet<RoleGroup_Role> RoleGroup_Roles { get; set; }
/// <summary>
/// 角色用户对应关系
/// </summary>
public DbSet<Role_User> Role_Users { get; set; }
}
}

View File

@ -0,0 +1,17 @@
namespace FAuth.DataBase.Tables
{
/// <summary>
/// 应用和角色组对应关系
/// </summary>
public class App_RoleGroup
{
/// <summary>
/// 应用编号
/// </summary>
public int AppId { get; set; }
/// <summary>
/// 角色组编号
/// </summary>
public int RoleGroupId { get; set; }
}
}

View File

@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FAuth.DataBase.Tables
{
/// <summary>
/// 应用信息
/// </summary>
[Table("Apps")]
public class Apps
{
/// <summary>
/// 应用编号
/// </summary>
[Key]
public int Id { get; set; }
/// <summary>
/// 应用名称
/// </summary>
[MaxLength(50), Required]
public string Name { get; set; }
/// <summary>
/// 应用说明
/// </summary>
[MaxLength(200)]
public string Description { get; set; }
}
}

View File

@ -1,11 +1,13 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FAuth.DataBase.Tables
{
/// <summary>
/// 用户信息
/// </summary>
[Table("FUser")]
public class FUser
{
/// <summary>

View File

@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FAuth.DataBase.Tables
{
/// <summary>
/// 角色组
/// </summary>
[Table("RoleGroup")]
public class RoleGroup
{
/// <summary>
/// 角色组编号
/// </summary>
[Key]
public int Id { get; set; }
/// <summary>
/// 角色组名称
/// </summary>
[MaxLength(50),Required]
public string Name { get; set; }
/// <summary>
/// 角色组说明
/// </summary>
[MaxLength(200)]
public string Description { get; set; }
}
}

View File

@ -0,0 +1,17 @@
namespace FAuth.DataBase.Tables
{
/// <summary>
/// 角色组合角色对应关系
/// </summary>
public class RoleGroup_Role
{
/// <summary>
/// 角色组编号
/// </summary>
public int RoleGroupId { get; set; }
/// <summary>
/// 角色编号
/// </summary>
public int RoleId { get; set; }
}
}

View File

@ -0,0 +1,17 @@
namespace FAuth.DataBase.Tables
{
/// <summary>
/// 角色用户对应关系
/// </summary>
public class Role_User
{
/// <summary>
/// 角色编号
/// </summary>
public int RoleId { get; set; }
/// <summary>
/// 用户编号
/// </summary>
public int UserId { get; set; }
}
}

View File

@ -0,0 +1,28 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace FAuth.DataBase.Tables
{
/// <summary>
/// 角色定义
/// </summary>
[Table("Roles")]
public class Roles
{
/// <summary>
/// 角色编号
/// </summary>
[Key]
public int Id { get; set; }
/// <summary>
/// 角色名称
/// </summary>
[MaxLength(50), Required]
public string Name { get; set; }
/// <summary>
/// 角色说明
/// </summary>
[MaxLength(50)]
public string Description { get; set; }
}
}