feat: 添加管理员实验板管理界面
This commit is contained in:
@@ -62,6 +62,7 @@ try
|
||||
options.Authority = "http://localhost:5000";
|
||||
options.RequireHttpsMetadata = false;
|
||||
});
|
||||
// Add JWT Token Authorization Policy
|
||||
builder.Services.AddAuthorization(options =>
|
||||
{
|
||||
options.AddPolicy("Admin", policy =>
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Net;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -17,7 +18,10 @@ public class DataController : ControllerBase
|
||||
{
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
|
||||
public class GetUserInfoResponse
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
public class UserInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户的唯一标识符
|
||||
@@ -118,7 +122,7 @@ public class DataController : ControllerBase
|
||||
[Authorize]
|
||||
[HttpGet("GetUserInfo")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(GetUserInfoResponse), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(UserInfo), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
@@ -139,7 +143,7 @@ public class DataController : ControllerBase
|
||||
return BadRequest("用户不存在");
|
||||
|
||||
var user = ret.Value.Value;
|
||||
return Ok(new GetUserInfoResponse
|
||||
return Ok(new UserInfo
|
||||
{
|
||||
ID = user.ID,
|
||||
Name = user.Name,
|
||||
@@ -187,5 +191,85 @@ public class DataController : ControllerBase
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "注册失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增板子(管理员权限)
|
||||
/// </summary>
|
||||
[Authorize("Admin")]
|
||||
[HttpPost("AddBoard")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public IActionResult AddBoard(string name, string ipAddr, int port)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return BadRequest("板子名称不能为空");
|
||||
if (string.IsNullOrWhiteSpace(ipAddr))
|
||||
return BadRequest("IP地址不能为空");
|
||||
if (port <= 0 || port > 65535)
|
||||
return BadRequest("端口号不合法");
|
||||
try
|
||||
{
|
||||
using var db = new Database.AppDataConnection();
|
||||
var ret = db.AddBoard(name, ipAddr, port);
|
||||
return Ok(ret);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "新增板子时发生异常");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "新增失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除板子(管理员权限)
|
||||
/// </summary>
|
||||
[Authorize("Admin")]
|
||||
[HttpDelete("DeleteBoard")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public IActionResult DeleteBoard(Guid id)
|
||||
{
|
||||
if (id == Guid.Empty)
|
||||
return BadRequest("板子Guid不能为空");
|
||||
|
||||
try
|
||||
{
|
||||
using var db = new Database.AppDataConnection();
|
||||
var ret = db.DeleteBoardByID(id);
|
||||
return Ok(ret);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "删除板子时发生异常");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "删除失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取全部板子(管理员权限)
|
||||
/// </summary>
|
||||
[Authorize("Admin")]
|
||||
[HttpGet("GetAllBoards")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(Database.Board[]), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public IActionResult GetAllBoards()
|
||||
{
|
||||
try
|
||||
{
|
||||
using var db = new Database.AppDataConnection();
|
||||
var boards = db.GetAllBoard();
|
||||
return Ok(boards);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "获取全部板子时发生异常");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "获取失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using DotNext;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
@@ -24,6 +25,7 @@ public class RemoteUpdateController : ControllerBase
|
||||
/// <param name="bitstream2">比特流文件2</param>
|
||||
/// <param name="bitstream3">比特流文件3</param>
|
||||
/// <returns>上传结果</returns>
|
||||
[Authorize("Admin")]
|
||||
[HttpPost("UploadBitstream")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
@@ -129,6 +131,7 @@ public class RemoteUpdateController : ControllerBase
|
||||
/// <param name="address"> 设备地址 </param>
|
||||
/// <param name="port"> 设备端口 </param>
|
||||
/// <param name="bitstreamNum"> 比特流位号 </param>
|
||||
[Authorize("Admin")]
|
||||
[HttpPost("DownloadBitstream")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
@@ -179,6 +182,7 @@ public class RemoteUpdateController : ControllerBase
|
||||
/// <param name="port">设备端口</param>
|
||||
/// <param name="bitstreamNum">比特流编号</param>
|
||||
/// <returns>总共上传比特流的数量</returns>
|
||||
[Authorize("Admin")]
|
||||
[HttpPost("DownloadMultiBitstreams")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
||||
@@ -239,6 +243,7 @@ public class RemoteUpdateController : ControllerBase
|
||||
/// <param name="port">设备端口</param>
|
||||
/// <param name="bitstreamNum">比特流编号</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[Authorize("Admin")]
|
||||
[HttpPost("HotResetBitstream")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
@@ -267,6 +272,7 @@ public class RemoteUpdateController : ControllerBase
|
||||
/// <param name="address">[TODO:parameter]</param>
|
||||
/// <param name="port">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
[Authorize("Admin")]
|
||||
[HttpPost("GetFirmwareVersion")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(UInt32), StatusCodes.Status200OK)]
|
||||
|
@@ -98,6 +98,12 @@ public class Board
|
||||
[NotNull]
|
||||
public required BoardStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
[NotNull]
|
||||
public string FirmVersion { get; set; } = "1.0.0";
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
@@ -273,6 +279,35 @@ public class AppDataConnection : DataConnection
|
||||
return this.Insert(board);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <param name="name">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public int DeleteBoardByName(string name)
|
||||
{
|
||||
return this.Board.Where(board => board.BoardName == name).Delete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <param name="id">[TODO:parameter]</param>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public int DeleteBoardByID(Guid id)
|
||||
{
|
||||
return this.Board.Where(board => board.ID == id).Delete();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
/// <returns>[TODO:return]</returns>
|
||||
public Board[] GetAllBoard()
|
||||
{
|
||||
return this.Board.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// [TODO:description]
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user