增加角色、应用、角色组控制器
This commit is contained in:
parent
3ce676dd9a
commit
7289a12c8a
|
@ -1,7 +1,8 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
|
||||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
using System;
|
||||
using Falcon.Extend;
|
||||
using FAuth.DataBase;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FAuth.Controllers
|
||||
|
@ -17,6 +20,14 @@ namespace FAuth.Controllers
|
|||
/// 服务集合
|
||||
/// </summary>
|
||||
public IServiceProvider Services { get; set; }
|
||||
/// <summary>
|
||||
/// 数据库
|
||||
/// </summary>
|
||||
public FAuthDb Db { get; set; }
|
||||
/// <summary>
|
||||
/// 数据缓冲
|
||||
/// </summary>
|
||||
public ICacheProvider Cache { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 通过日志组件和服务集合生成控制器
|
||||
|
@ -26,6 +37,8 @@ namespace FAuth.Controllers
|
|||
public ControllerBase(ILogger<LoggerType> logger,IServiceProvider service) {
|
||||
this.Logger = logger;
|
||||
this.Services = service;
|
||||
this.Db = service.GetService<FAuthDb>();
|
||||
this.Cache = service.GetService<ICacheProvider>();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
67
FAuth/Controllers/api/AppController.cs
Normal file
67
FAuth/Controllers/api/AppController.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Falcon.Extend;
|
||||
using FAuth.DataBase;
|
||||
using System.Linq;
|
||||
using FAuth.DataBase.Tables;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace FAuth.Controllers.api
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用程序控制器
|
||||
/// </summary>
|
||||
public class AppController:ApiControllerBase<AppController>
|
||||
{
|
||||
public AppController(ILogger<AppController> logger,IServiceProvider service) : base(logger,service) {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加新应用
|
||||
/// </summary>
|
||||
/// <param name="appName">应用名称</param>
|
||||
/// <param name="description">应用说明</param>
|
||||
/// <returns>应用信息</returns>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(Apps),200)]
|
||||
public Apps AddNewApp(string appName,string description) {
|
||||
if(appName.IsNullOrEmpty()) {
|
||||
throw new ArgumentNullException(nameof(appName));
|
||||
}
|
||||
var qu = this.Db.Apps.Where(m => m.Name == appName);
|
||||
if(qu.Any()) {
|
||||
throw new Exception($"应用{appName}已经存在,不可以重复创建!");
|
||||
}
|
||||
var newApp = new Apps {
|
||||
Name = appName,
|
||||
Description = description,
|
||||
};
|
||||
this.Db.Entry(newApp).State = EntityState.Added;
|
||||
this.Db.SaveChangesAsync().Wait();
|
||||
return newApp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询app是否注册
|
||||
/// </summary>
|
||||
/// <param name="appName">app名称</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[ProducesResponseType(typeof(Apps),200)]
|
||||
public Apps GetApps(string appName) {
|
||||
if(string.IsNullOrEmpty(appName))
|
||||
throw new ArgumentException("message",nameof(appName));
|
||||
var qu = this.Db.Apps.Where(m => m.Name == appName);
|
||||
if(qu.Any()) {
|
||||
return qu.First();
|
||||
} else {
|
||||
throw new Exception("没有找到该应用");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -14,4 +14,5 @@ namespace FAuth.Controllers.api
|
|||
public RoleController(ILogger<RoleController> logger,IServiceProvider service) : base(logger,service) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
15
FAuth/Controllers/api/RoleGroupController.cs
Normal file
15
FAuth/Controllers/api/RoleGroupController.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FAuth.Controllers.api
|
||||
{
|
||||
/// <summary>
|
||||
/// 角色组控制器
|
||||
/// </summary>
|
||||
public class RoleGroupController:ApiControllerBase<RoleGroupController>
|
||||
{
|
||||
public RoleGroupController(ILogger<RoleGroupController> logger,IServiceProvider service) : base(logger,service) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Falcon.Extend;
|
||||
using FAuth.DataBase.Tables;
|
||||
using FAuth.Extensions.Decryptor;
|
||||
using FAuth.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using FAuth.DataBase.Tables;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using FAuth.Extensions.Decryptor;
|
||||
using FAuth.DataBase;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Falcon.Extend;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FAuth.Controllers.api
|
||||
{
|
||||
|
@ -20,21 +17,11 @@ namespace FAuth.Controllers.api
|
|||
public class UserController:ApiControllerBase<UserController>
|
||||
{
|
||||
public IUserTicketDryptor UserTicketDryptor { get; set; }
|
||||
public FAuthDb Db { get; set; }
|
||||
|
||||
public UserController(
|
||||
ILogger<UserController> logger,
|
||||
IServiceProvider service,
|
||||
IUserTicketDryptor userTicketDryptor,
|
||||
FAuthDb db)
|
||||
public UserController(ILogger<UserController> logger,IServiceProvider service,IUserTicketDryptor userTicketDryptor)
|
||||
: base(logger,service) {
|
||||
|
||||
if(logger is null)
|
||||
throw new ArgumentNullException(nameof(logger));
|
||||
if(service is null)
|
||||
throw new ArgumentNullException(nameof(service));
|
||||
this.UserTicketDryptor = userTicketDryptor ?? throw new ArgumentNullException(nameof(userTicketDryptor));
|
||||
this.Db = db ?? throw new ArgumentNullException(nameof(db));
|
||||
this.UserTicketDryptor = userTicketDryptor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue
Block a user